Skip to content

Commit

Permalink
fix: record error response attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
tschoffelen committed Dec 23, 2024
1 parent 312bff9 commit cfdfbf5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Serverless Middleware

Some helpers for writing API endpoints using AWS Lambda.
A helper for writing APIs using AWS Lambda functions.

### Features

- Dependency injection for easy unit testing.
- Pretty JSON error output, with status codes automatically determined based on error message.
- Easy access to query strings and JSON body properties.
- Serverless warmup plugin support.
- OpenTelemetry support and additional span attributes, for use with [opentelemetry-lambda](https://github.com/open-telemetry/opentelemetry-lambda).

---

Expand Down Expand Up @@ -47,6 +55,10 @@ serverless plugin.
Simply install the serverless plugin, no other changes to your code necessary.
The middleware will automatically prevent code execution on warmup requests.

### OpenTelemetry span enrichment

If an active OpenTelemetry span is detected, event and response properties will automatically be added.

<br /><br />

---
Expand Down
7 changes: 6 additions & 1 deletion src/lib/ApiAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ class ApiAdapter {
return res;
} catch (error) {
console.error(error);

OpenTelemetry.addSpanErrorAttributes(event, error);
return this.errorConverter.convert(error);

const res = this.errorConverter.convert(error);
OpenTelemetry.addSpanResponseAttributes(event, res);

return res;
}
}

Expand Down

0 comments on commit cfdfbf5

Please sign in to comment.