Skip to content

Commit 46b769b

Browse files
committed
fix/troubleshooting
1 parent de23975 commit 46b769b

File tree

5 files changed

+46
-24
lines changed

5 files changed

+46
-24
lines changed

packages/tracing/tests/e2e/tracer.test.Decorator.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Tracer } from '../../src';
22
import { Callback, Context } from 'aws-lambda';
33
import { DynamoDBClient, PutItemCommand } from '@aws-sdk/client-dynamodb';
4+
import axios from 'axios';
45
// eslint-disable-next-line @typescript-eslint/no-var-requires
56
let AWS = require('aws-sdk');
67

@@ -54,6 +55,7 @@ export class MyFunctionWithDecorator {
5455
return Promise.all([
5556
dynamoDBv2.put({ TableName: testTableName, Item: { id: `${serviceName}-${event.invocation}-sdkv2` } }).promise(),
5657
dynamoDBv3.send(new PutItemCommand({ TableName: testTableName, Item: { id: { 'S': `${serviceName}-${event.invocation}-sdkv3` } } })),
58+
axios.get('https://httpbin.org/status/200'),
5759
new Promise((resolve, reject) => {
5860
setTimeout(() => {
5961
const res = this.myMethod();
@@ -65,7 +67,7 @@ export class MyFunctionWithDecorator {
6567
}, 2000); // We need to wait for to make sure previous calls are finished
6668
})
6769
])
68-
.then(([ _dynamoDBv2Res, _dynamoDBv3Res, promiseRes ]) => promiseRes)
70+
.then(([ _dynamoDBv2Res, _dynamoDBv3Res, _axiosRes, promiseRes ]) => promiseRes)
6971
.catch((err) => {
7072
throw err;
7173
});

packages/tracing/tests/e2e/tracer.test.DecoratorWithAsyncHandler.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Tracer } from '../../src';
22
import { Context } from 'aws-lambda';
33
import { DynamoDBClient, PutItemCommand } from '@aws-sdk/client-dynamodb';
4+
import axios from 'axios';
45
// eslint-disable-next-line @typescript-eslint/no-var-requires
56
let AWS = require('aws-sdk');
67

@@ -54,7 +55,8 @@ export class MyFunctionWithDecorator {
5455
try {
5556
await dynamoDBv2.put({ TableName: testTableName, Item: { id: `${serviceName}-${event.invocation}-sdkv2` } }).promise();
5657
await dynamoDBv3.send(new PutItemCommand({ TableName: testTableName, Item: { id: { 'S': `${serviceName}-${event.invocation}-sdkv3` } } }));
57-
58+
await axios.get('https://httpbin.org/status/200');
59+
5860
const res = this.myMethod();
5961
if (event.throw) {
6062
throw new Error(customErrorMessage);

packages/tracing/tests/e2e/tracer.test.Manual.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ export const handler = async (event: CustomEvent, _context: Context): Promise<vo
5858
try {
5959
await dynamoDBv2.put({ TableName: testTableName, Item: { id: `${serviceName}-${event.invocation}-sdkv2` } }).promise();
6060
await dynamoDBv3.send(new PutItemCommand({ TableName: testTableName, Item: { id: { 'S': `${serviceName}-${event.invocation}-sdkv3` } } }));
61-
const t = await axios.get('https://httpbin.org/status/200');
62-
tracer.putAnnotation('httpbin', t.status);
61+
await axios.get('https://httpbin.org/status/200');
6362

6463
const res = customResponseValue;
6564
if (event.throw) {

packages/tracing/tests/e2e/tracer.test.Middleware.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import middy from '@middy/core';
22
import { captureLambdaHandler, Tracer } from '../../src';
33
import { Context } from 'aws-lambda';
44
import { DynamoDBClient, PutItemCommand } from '@aws-sdk/client-dynamodb';
5+
import axios from 'axios';
56
// eslint-disable-next-line @typescript-eslint/no-var-requires
67
let AWS = require('aws-sdk');
78

@@ -51,7 +52,8 @@ export const handler = middy(async (event: CustomEvent, _context: Context): Prom
5152
try {
5253
await dynamoDBv2.put({ TableName: testTableName, Item: { id: `${serviceName}-${event.invocation}-sdkv2` } }).promise();
5354
await dynamoDBv3.send(new PutItemCommand({ TableName: testTableName, Item: { id: { 'S': `${serviceName}-${event.invocation}-sdkv3` } } }));
54-
55+
await axios.get('https://httpbin.org/status/200');
56+
5557
const res = customResponseValue;
5658
if (event.throw) {
5759
throw new Error(customErrorMessage);

packages/tracing/tests/e2e/tracer.test.ts

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ describe('Tracer integration tests', () => {
152152
expect(handlerSubsegment.name).toBe('## index.handler');
153153
if (handlerSubsegment?.subsegments !== undefined) {
154154
// Assert that there are three subsegments
155-
expect(handlerSubsegment?.subsegments?.length).toBe(2);
155+
expect(handlerSubsegment?.subsegments?.length).toBe(3);
156156

157157
const [ AWSSDKSubsegment1, AWSSDKSubsegment2, HTTPSegment ] = handlerSubsegment?.subsegments;
158158
// Assert that the subsegment names are the expected ones
@@ -208,11 +208,11 @@ describe('Tracer integration tests', () => {
208208

209209
// Assess
210210
// Retrieve traces from X-Ray using Resource ARN as filter
211-
const sortedTraces = await getTraces(xray, startTime, resourceArn, invocations, 4);
211+
const sortedTraces = await getTraces(xray, startTime, resourceArn, invocations, 5);
212212

213213
for (let i = 0; i < invocations; i++) {
214214
// Assert that the trace has the expected amount of segments
215-
expect(sortedTraces[i].Segments.length).toBe(4);
215+
expect(sortedTraces[i].Segments.length).toBe(5);
216216

217217
const invocationSubsegment = getInvocationSubsegment(sortedTraces[i]);
218218

@@ -223,12 +223,13 @@ describe('Tracer integration tests', () => {
223223
expect(handlerSubsegment.name).toBe('## index.handler');
224224
if (handlerSubsegment?.subsegments !== undefined) {
225225
// Assert that there're two subsegments
226-
expect(handlerSubsegment?.subsegments?.length).toBe(2);
226+
expect(handlerSubsegment?.subsegments?.length).toBe(3);
227227

228-
const [ AWSSDKSubsegment1, AWSSDKSubsegment2 ] = handlerSubsegment?.subsegments;
228+
const [ AWSSDKSubsegment1, AWSSDKSubsegment2, HTTPSegment ] = handlerSubsegment?.subsegments;
229229
// Assert that the subsegment names is the expected ones
230230
expect(AWSSDKSubsegment1.name).toBe('DynamoDB');
231231
expect(AWSSDKSubsegment2.name).toBe('DynamoDB');
232+
expect(HTTPSegment.name).toBe('httpbin.org');
232233

233234
const { annotations, metadata } = handlerSubsegment;
234235

@@ -278,11 +279,11 @@ describe('Tracer integration tests', () => {
278279

279280
// Assess
280281
// Retrieve traces from X-Ray using Resource ARN as filter
281-
const sortedTraces = await getTraces(xray, startTime, resourceArn, invocations, 4);
282+
const sortedTraces = await getTraces(xray, startTime, resourceArn, invocations, 5);
282283

283284
for (let i = 0; i < invocations; i++) {
284285
// Assert that the trace has the expected amount of segments
285-
expect(sortedTraces[i].Segments.length).toBe(4);
286+
expect(sortedTraces[i].Segments.length).toBe(5);
286287

287288
const invocationSubsegment = getInvocationSubsegment(sortedTraces[i]);
288289

@@ -293,12 +294,13 @@ describe('Tracer integration tests', () => {
293294
expect(handlerSubsegment.name).toBe('## index.handler');
294295
if (handlerSubsegment?.subsegments !== undefined) {
295296
// Assert that there're two subsegments
296-
expect(handlerSubsegment?.subsegments?.length).toBe(2);
297+
expect(handlerSubsegment?.subsegments?.length).toBe(3);
297298

298-
const [ AWSSDKSubsegment1, AWSSDKSubsegment2 ] = handlerSubsegment?.subsegments;
299-
// Assert that the subsegment names is the expected ones
299+
const [ AWSSDKSubsegment1, AWSSDKSubsegment2, HTTPSegment ] = handlerSubsegment?.subsegments;
300+
// Assert that the subsegment names are the expected ones
300301
expect(AWSSDKSubsegment1.name).toBe('DynamoDB');
301302
expect(AWSSDKSubsegment2.name).toBe('DynamoDB');
303+
expect(HTTPSegment.name).toBe('httpbin.org');
302304

303305
const { annotations, metadata } = handlerSubsegment;
304306

@@ -371,11 +373,11 @@ describe('Tracer integration tests', () => {
371373

372374
// Assess
373375
// Retrieve traces from X-Ray using Resource ARN as filter
374-
const sortedTraces = await getTraces(xray, startTime, resourceArn, invocations, 4);
376+
const sortedTraces = await getTraces(xray, startTime, resourceArn, invocations, 5);
375377

376378
for (let i = 0; i < invocations; i++) {
377379
// Assert that the trace has the expected amount of segments
378-
expect(sortedTraces[i].Segments.length).toBe(4);
380+
expect(sortedTraces[i].Segments.length).toBe(5);
379381

380382
const invocationSubsegment = getInvocationSubsegment(sortedTraces[i]);
381383

@@ -386,17 +388,20 @@ describe('Tracer integration tests', () => {
386388
expect(handlerSubsegment.name).toBe('## index.handler');
387389
if (handlerSubsegment?.subsegments !== undefined) {
388390
// Assert that there're three subsegments
389-
expect(handlerSubsegment?.subsegments?.length).toBe(3);
391+
expect(handlerSubsegment?.subsegments?.length).toBe(4);
390392

391393
// Sort the subsegments by name
392394
const dynamoDBSubsegments: ParsedDocument[] = [];
393395
const methodSubsegment: ParsedDocument[] = [];
396+
const httpSubsegment: ParsedDocument[] = [];
394397
const otherSegments: ParsedDocument[] = [];
395398
handlerSubsegment?.subsegments.forEach(subsegment => {
396399
if (subsegment.name === 'DynamoDB') {
397400
dynamoDBSubsegments.push(subsegment);
398401
} else if (subsegment.name === '### myMethod') {
399402
methodSubsegment.push(subsegment);
403+
} else if (subsegment.name === 'httpbin.org') {
404+
httpSubsegment.push(subsegment);
400405
} else {
401406
otherSegments.push(subsegment);
402407
}
@@ -405,6 +410,8 @@ describe('Tracer integration tests', () => {
405410
expect(dynamoDBSubsegments.length).toBe(2);
406411
// Assert that there is exactly one subsegment with the name '### myMethod'
407412
expect(methodSubsegment.length).toBe(1);
413+
// Assert that there is exactly one subsegment with the name 'httpbin.org'
414+
expect(httpSubsegment.length).toBe(1);
408415
// Assert that there are exactly zero other subsegments
409416
expect(otherSegments.length).toBe(0);
410417

@@ -468,11 +475,11 @@ describe('Tracer integration tests', () => {
468475

469476
// Assess
470477
// Retrieve traces from X-Ray using Resource ARN as filter
471-
const sortedTraces = await getTraces(xray, startTime, resourceArn, invocations, 4);
478+
const sortedTraces = await getTraces(xray, startTime, resourceArn, invocations, 5);
472479

473480
for (let i = 0; i < invocations; i++) {
474481
// Assert that the trace has the expected amount of segments
475-
expect(sortedTraces[i].Segments.length).toBe(4);
482+
expect(sortedTraces[i].Segments.length).toBe(5);
476483

477484
const invocationSubsegment = getInvocationSubsegment(sortedTraces[i]);
478485

@@ -483,17 +490,20 @@ describe('Tracer integration tests', () => {
483490
expect(handlerSubsegment.name).toBe('## index.handler');
484491
if (handlerSubsegment?.subsegments !== undefined) {
485492
// Assert that there're three subsegments
486-
expect(handlerSubsegment?.subsegments?.length).toBe(3);
493+
expect(handlerSubsegment?.subsegments?.length).toBe(4);
487494

488495
// Sort the subsegments by name
489496
const dynamoDBSubsegments: ParsedDocument[] = [];
490497
const methodSubsegment: ParsedDocument[] = [];
498+
const httpSubsegment: ParsedDocument[] = [];
491499
const otherSegments: ParsedDocument[] = [];
492500
handlerSubsegment?.subsegments.forEach(subsegment => {
493501
if (subsegment.name === 'DynamoDB') {
494502
dynamoDBSubsegments.push(subsegment);
495503
} else if (subsegment.name === '### myMethod') {
496504
methodSubsegment.push(subsegment);
505+
} else if (subsegment.name === 'httpbin.org') {
506+
httpSubsegment.push(subsegment);
497507
} else {
498508
otherSegments.push(subsegment);
499509
}
@@ -502,6 +512,8 @@ describe('Tracer integration tests', () => {
502512
expect(dynamoDBSubsegments.length).toBe(2);
503513
// Assert that there is exactly one subsegment with the name '### myMethod'
504514
expect(methodSubsegment.length).toBe(1);
515+
// Assert that there is exactly one subsegment with the name 'httpbin.org'
516+
expect(httpSubsegment.length).toBe(1);
505517
// Assert that there are exactly zero other subsegments
506518
expect(otherSegments.length).toBe(0);
507519

@@ -565,11 +577,11 @@ describe('Tracer integration tests', () => {
565577

566578
// Assess
567579
// Retrieve traces from X-Ray using Resource ARN as filter
568-
const sortedTraces = await getTraces(xray, startTime, resourceArn, invocations, 4);
580+
const sortedTraces = await getTraces(xray, startTime, resourceArn, invocations, 5);
569581

570582
for (let i = 0; i < invocations; i++) {
571583
// Assert that the trace has the expected amount of segments
572-
expect(sortedTraces[i].Segments.length).toBe(4);
584+
expect(sortedTraces[i].Segments.length).toBe(5);
573585

574586
const invocationSubsegment = getInvocationSubsegment(sortedTraces[i]);
575587

@@ -580,17 +592,20 @@ describe('Tracer integration tests', () => {
580592
expect(handlerSubsegment.name).toBe('## index.handler');
581593
if (handlerSubsegment?.subsegments !== undefined) {
582594
// Assert that there're three subsegments
583-
expect(handlerSubsegment?.subsegments?.length).toBe(3);
595+
expect(handlerSubsegment?.subsegments?.length).toBe(5);
584596

585597
// Sort the subsegments by name
586598
const dynamoDBSubsegments: ParsedDocument[] = [];
587599
const methodSubsegment: ParsedDocument[] = [];
600+
const httpSubsegment: ParsedDocument[] = [];
588601
const otherSegments: ParsedDocument[] = [];
589602
handlerSubsegment?.subsegments.forEach(subsegment => {
590603
if (subsegment.name === 'DynamoDB') {
591604
dynamoDBSubsegments.push(subsegment);
592605
} else if (subsegment.name === '### myMethod') {
593606
methodSubsegment.push(subsegment);
607+
} else if (subsegment.name === 'httpbin.org') {
608+
httpSubsegment.push(subsegment);
594609
} else {
595610
otherSegments.push(subsegment);
596611
}
@@ -599,6 +614,8 @@ describe('Tracer integration tests', () => {
599614
expect(dynamoDBSubsegments.length).toBe(2);
600615
// Assert that there is exactly one subsegment with the name '### myMethod'
601616
expect(methodSubsegment.length).toBe(1);
617+
// Assert that there is exactly one subsegment with the name 'httpbin.org'
618+
expect(httpSubsegment.length).toBe(1);
602619
// Assert that there are exactly zero other subsegments
603620
expect(otherSegments.length).toBe(0);
604621
// Assert that no response was captured on the subsegment

0 commit comments

Comments
 (0)