Skip to content

Commit 135ad3b

Browse files
committed
fix/troubleshooting
1 parent ae6d781 commit 135ad3b

File tree

5 files changed

+46
-24
lines changed

5 files changed

+46
-24
lines changed

Diff for: packages/tracing/tests/e2e/tracer.test.Decorator.ts

+3-1
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
});

Diff for: packages/tracing/tests/e2e/tracer.test.DecoratorWithAsyncHandler.ts

+3-1
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);

Diff for: packages/tracing/tests/e2e/tracer.test.Manual.ts

+1-2
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) {

Diff for: packages/tracing/tests/e2e/tracer.test.Middleware.ts

+3-1
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);

Diff for: packages/tracing/tests/e2e/tracer.test.ts

+36-19
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ describe('Tracer integration tests', () => {
149149
expect(handlerSubsegment.name).toBe('## index.handler');
150150
if (handlerSubsegment?.subsegments !== undefined) {
151151
// Assert that there are three subsegments
152-
expect(handlerSubsegment?.subsegments?.length).toBe(2);
152+
expect(handlerSubsegment?.subsegments?.length).toBe(3);
153153

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

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

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

214214
const invocationSubsegment = getInvocationSubsegment(sortedTraces[i]);
215215

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

225-
const [ AWSSDKSubsegment1, AWSSDKSubsegment2 ] = handlerSubsegment?.subsegments;
225+
const [ AWSSDKSubsegment1, AWSSDKSubsegment2, HTTPSegment ] = handlerSubsegment?.subsegments;
226226
// Assert that the subsegment names is the expected ones
227227
expect(AWSSDKSubsegment1.name).toBe('DynamoDB');
228228
expect(AWSSDKSubsegment2.name).toBe('DynamoDB');
229+
expect(HTTPSegment.name).toBe('httpbin.org');
229230

230231
const { annotations, metadata } = handlerSubsegment;
231232

@@ -275,11 +276,11 @@ describe('Tracer integration tests', () => {
275276

276277
// Assess
277278
// Retrieve traces from X-Ray using Resource ARN as filter
278-
const sortedTraces = await getTraces(xray, startTime, resourceArn, invocations, 4);
279+
const sortedTraces = await getTraces(xray, startTime, resourceArn, invocations, 5);
279280

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

284285
const invocationSubsegment = getInvocationSubsegment(sortedTraces[i]);
285286

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

295-
const [ AWSSDKSubsegment1, AWSSDKSubsegment2 ] = handlerSubsegment?.subsegments;
296-
// Assert that the subsegment names is the expected ones
296+
const [ AWSSDKSubsegment1, AWSSDKSubsegment2, HTTPSegment ] = handlerSubsegment?.subsegments;
297+
// Assert that the subsegment names are the expected ones
297298
expect(AWSSDKSubsegment1.name).toBe('DynamoDB');
298299
expect(AWSSDKSubsegment2.name).toBe('DynamoDB');
300+
expect(HTTPSegment.name).toBe('httpbin.org');
299301

300302
const { annotations, metadata } = handlerSubsegment;
301303

@@ -368,11 +370,11 @@ describe('Tracer integration tests', () => {
368370

369371
// Assess
370372
// Retrieve traces from X-Ray using Resource ARN as filter
371-
const sortedTraces = await getTraces(xray, startTime, resourceArn, invocations, 4);
373+
const sortedTraces = await getTraces(xray, startTime, resourceArn, invocations, 5);
372374

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

377379
const invocationSubsegment = getInvocationSubsegment(sortedTraces[i]);
378380

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

388390
// Sort the subsegments by name
389391
const dynamoDBSubsegments: ParsedDocument[] = [];
390392
const methodSubsegment: ParsedDocument[] = [];
393+
const httpSubsegment: ParsedDocument[] = [];
391394
const otherSegments: ParsedDocument[] = [];
392395
handlerSubsegment?.subsegments.forEach(subsegment => {
393396
if (subsegment.name === 'DynamoDB') {
394397
dynamoDBSubsegments.push(subsegment);
395398
} else if (subsegment.name === '### myMethod') {
396399
methodSubsegment.push(subsegment);
400+
} else if (subsegment.name === 'httpbin.org') {
401+
httpSubsegment.push(subsegment);
397402
} else {
398403
otherSegments.push(subsegment);
399404
}
@@ -402,6 +407,8 @@ describe('Tracer integration tests', () => {
402407
expect(dynamoDBSubsegments.length).toBe(2);
403408
// Assert that there is exactly one subsegment with the name '### myMethod'
404409
expect(methodSubsegment.length).toBe(1);
410+
// Assert that there is exactly one subsegment with the name 'httpbin.org'
411+
expect(httpSubsegment.length).toBe(1);
405412
// Assert that there are exactly zero other subsegments
406413
expect(otherSegments.length).toBe(0);
407414

@@ -465,11 +472,11 @@ describe('Tracer integration tests', () => {
465472

466473
// Assess
467474
// Retrieve traces from X-Ray using Resource ARN as filter
468-
const sortedTraces = await getTraces(xray, startTime, resourceArn, invocations, 4);
475+
const sortedTraces = await getTraces(xray, startTime, resourceArn, invocations, 5);
469476

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

474481
const invocationSubsegment = getInvocationSubsegment(sortedTraces[i]);
475482

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

485492
// Sort the subsegments by name
486493
const dynamoDBSubsegments: ParsedDocument[] = [];
487494
const methodSubsegment: ParsedDocument[] = [];
495+
const httpSubsegment: ParsedDocument[] = [];
488496
const otherSegments: ParsedDocument[] = [];
489497
handlerSubsegment?.subsegments.forEach(subsegment => {
490498
if (subsegment.name === 'DynamoDB') {
491499
dynamoDBSubsegments.push(subsegment);
492500
} else if (subsegment.name === '### myMethod') {
493501
methodSubsegment.push(subsegment);
502+
} else if (subsegment.name === 'httpbin.org') {
503+
httpSubsegment.push(subsegment);
494504
} else {
495505
otherSegments.push(subsegment);
496506
}
@@ -499,6 +509,8 @@ describe('Tracer integration tests', () => {
499509
expect(dynamoDBSubsegments.length).toBe(2);
500510
// Assert that there is exactly one subsegment with the name '### myMethod'
501511
expect(methodSubsegment.length).toBe(1);
512+
// Assert that there is exactly one subsegment with the name 'httpbin.org'
513+
expect(httpSubsegment.length).toBe(1);
502514
// Assert that there are exactly zero other subsegments
503515
expect(otherSegments.length).toBe(0);
504516

@@ -562,11 +574,11 @@ describe('Tracer integration tests', () => {
562574

563575
// Assess
564576
// Retrieve traces from X-Ray using Resource ARN as filter
565-
const sortedTraces = await getTraces(xray, startTime, resourceArn, invocations, 4);
577+
const sortedTraces = await getTraces(xray, startTime, resourceArn, invocations, 5);
566578

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

571583
const invocationSubsegment = getInvocationSubsegment(sortedTraces[i]);
572584

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

582594
// Sort the subsegments by name
583595
const dynamoDBSubsegments: ParsedDocument[] = [];
584596
const methodSubsegment: ParsedDocument[] = [];
597+
const httpSubsegment: ParsedDocument[] = [];
585598
const otherSegments: ParsedDocument[] = [];
586599
handlerSubsegment?.subsegments.forEach(subsegment => {
587600
if (subsegment.name === 'DynamoDB') {
588601
dynamoDBSubsegments.push(subsegment);
589602
} else if (subsegment.name === '### myMethod') {
590603
methodSubsegment.push(subsegment);
604+
} else if (subsegment.name === 'httpbin.org') {
605+
httpSubsegment.push(subsegment);
591606
} else {
592607
otherSegments.push(subsegment);
593608
}
@@ -596,6 +611,8 @@ describe('Tracer integration tests', () => {
596611
expect(dynamoDBSubsegments.length).toBe(2);
597612
// Assert that there is exactly one subsegment with the name '### myMethod'
598613
expect(methodSubsegment.length).toBe(1);
614+
// Assert that there is exactly one subsegment with the name 'httpbin.org'
615+
expect(httpSubsegment.length).toBe(1);
599616
// Assert that there are exactly zero other subsegments
600617
expect(otherSegments.length).toBe(0);
601618
// Assert that no response was captured on the subsegment

0 commit comments

Comments
 (0)