Skip to content

Commit 58f3667

Browse files
committed
feat: Add createTraceSpan support
1 parent 5560d84 commit 58f3667

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

node/packages/aws-lambda-sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"version": "0.15.10",
55
"author": "Serverless, Inc.",
66
"dependencies": {
7-
"@serverless/sdk": "^0.5.21",
7+
"@serverless/sdk": "^0.5.23",
88
"@serverless/sdk-schema": "^0.15.6",
99
"d": "^1.0.1",
1010
"ext": "^1.7.0",
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
const sdk = require('@serverless/sdk');
4+
5+
module.exports.handler = async (event) => {
6+
if (!sdk) throw new Error('SDK not exported');
7+
8+
if (!event.isTriggeredByUnitTest) {
9+
// eslint-disable-next-line import/no-unresolved
10+
const sdkMirror = require('@serverless/aws-lambda-sdk');
11+
if (sdk !== sdkMirror) throw new Error('SDK exports mismatch');
12+
}
13+
14+
const span = sdk.createTraceSpan('user.parent');
15+
16+
sdk.createTraceSpan('user.child.one', () => {});
17+
18+
await sdk.createTraceSpan('user.child.two', async () => {});
19+
20+
span.close();
21+
22+
return {
23+
name: sdk.name,
24+
version: sdk.version,
25+
rootSpanName: sdk.traceSpans.root.name,
26+
};
27+
};

node/packages/aws-lambda-sdk/test/integration/index.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,23 @@ describe('integration', function () {
482482
},
483483
};
484484

485+
const sdkCreateTraceSpanTestConfig = {
486+
isCustomResponse: true,
487+
test: ({ invocationsData }) => {
488+
for (const [, { trace }] of invocationsData.entries()) {
489+
const { spans } = trace;
490+
const parentSpan = spans.find(({ name }) => name === 'user.parent');
491+
const childOneSpan = spans.find(({ name }) => name === 'user.child.one');
492+
const childTwoSpan = spans.find(({ name }) => name === 'user.child.two');
493+
expect(parentSpan).to.exist;
494+
expect(childOneSpan).to.exist;
495+
expect(childTwoSpan).to.exist;
496+
expect(childOneSpan.parentSpanId.toString()).to.equal(parentSpan.id.toString());
497+
expect(childTwoSpan.parentSpanId.toString()).to.equal(parentSpan.id.toString());
498+
}
499+
},
500+
};
501+
485502
const sdkTestConfig = {
486503
isCustomResponse: true,
487504
capturedEvents: [
@@ -2638,6 +2655,17 @@ describe('integration', function () {
26382655
config: sdkTestConfig,
26392656
},
26402657
],
2658+
[
2659+
'sdk-create-trace-span',
2660+
{
2661+
variants: new Map([
2662+
['v14', { configuration: { Runtime: 'nodejs14.x' } }],
2663+
['v16', { configuration: { Runtime: 'nodejs16.x' } }],
2664+
['v18', { configuration: { Runtime: 'nodejs18.x' } }],
2665+
]),
2666+
config: sdkCreateTraceSpanTestConfig,
2667+
},
2668+
],
26412669
[
26422670
'structured-logging-events',
26432671
{

0 commit comments

Comments
 (0)