From cfdfbf595cc67f118cad190823a13c9176705bac Mon Sep 17 00:00:00 2001 From: Thomas Schoffelen Date: Mon, 23 Dec 2024 20:30:55 +0000 Subject: [PATCH] fix: record error response attributes --- README.md | 14 +++++++++++++- src/lib/ApiAdapter.js | 7 ++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9dc9c40..6ed449e 100644 --- a/README.md +++ b/README.md @@ -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). --- @@ -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. +

--- diff --git a/src/lib/ApiAdapter.js b/src/lib/ApiAdapter.js index 1a738f7..e862871 100644 --- a/src/lib/ApiAdapter.js +++ b/src/lib/ApiAdapter.js @@ -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; } }