Skip to content

Commit 7a98263

Browse files
committed
fix callback support
1 parent 30bffa6 commit 7a98263

File tree

6 files changed

+17
-16
lines changed

6 files changed

+17
-16
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
55

66
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
77

8+
## [0.1.18] 2023-07-24
9+
10+
- Improved robustness of callback support
811

912
## [0.1.17] 2023-07-24
1013

examples/serverless/serverless.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ provider:
2727
Resource: '*'
2828
tags:
2929
'baselime:tracing': true
30+
'baselime:version': 5
3031
functions:
3132
hello:
3233
handler: src/main.handler
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

2-
exports.handler = async (event, context) => {
2+
exports.handler = (event, context, callback) => {
33
context.callbackWaitForEmptyEventLoop = false;
4-
console.log(event.Records[0].Sns)
5-
return {
4+
console.log(event.Records[0].Sns);
5+
return callback(null, {
66
message: 'req processed'
7-
}
7+
})
88
};

multiRegion.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"regions": [
3-
"eu-west-1",
43
"eu-west-2",
4+
"eu-west-1",
55
"us-east-1",
66
"us-east-2",
77
"us-west-2",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@baselime/lambda-node-opentelemetry",
3-
"version": "0.1.17",
3+
"version": "0.1.18",
44
"description": "OpenTelemetry auto tracer for Node.JS based AWS Lambda functions",
55
"keywords": [
66
"nodejs",

src/index.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export function wrap(handler: Handler) {
3737
attributes: flatten({
3838
event,
3939
context: {
40-
callbackWaitsForEmptyEventLoop: lambda_context.callbackWaitsForEmptyEventLoop,
4140
functionName: lambda_context.functionName,
4241
functionVersion: lambda_context.functionVersion,
4342
invokedFunctionArn: lambda_context.invokedFunctionArn,
@@ -67,10 +66,7 @@ export function wrap(handler: Handler) {
6766
const ctx = trace.setSpan(context.active(), span);
6867

6968
try {
70-
// if (callback && handler.constructor.name !== "AsyncFunction" && handler.length === 3) {
71-
// console.log("promisify handler");
72-
// handler = promisify(handler);
73-
// }
69+
7470
const result = await context.with(ctx, async (e, lc, cb) => {
7571
const unkownResult = handler(e, lc, (err, res) => {
7672
if (err) {
@@ -80,20 +76,21 @@ export function wrap(handler: Handler) {
8076
}
8177

8278
if (res) {
83-
span.setAttributes(({ result: res }) as Attributes);
79+
span.setAttributes(flatten({ result: res }));
8480
}
8581
if (cb) {
86-
cb(err, res)
82+
span.end();
83+
cb(err, res);
8784
}
88-
span.end();
8985
});
90-
9186
if (unkownResult) {
9287
return await unkownResult
9388
}
9489
}, null, event, lambda_context, callback);
90+
if (result) {
91+
span.setAttributes(flatten({ result }));
92+
}
9593

96-
span.setAttributes(({ result }) as Attributes);
9794
span.end();
9895
return result;
9996
} catch (e) {

0 commit comments

Comments
 (0)