Skip to content

Commit 85fa3fe

Browse files
feat: support fetch instrumentation in node distro (#27)
1 parent 60dd0fe commit 85fa3fe

26 files changed

Lines changed: 1101 additions & 110 deletions
Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1-
2-
31
export async function handler(event) {
42
console.log("Handler invoked with event:", event);
5-
await new Promise((resolve) => setTimeout(resolve, 2000));
3+
4+
const response = await fetch('https://jsonplaceholder.typicode.com/posts', {
5+
method: 'POST',
6+
headers: { 'Content-Type': 'application/json' },
7+
body: JSON.stringify({
8+
title: 'foo',
9+
body: 'bar',
10+
userId: 1,
11+
}),
12+
});
13+
14+
console.log(`response.statusCode: ${response.status}`);
15+
console.warn("let's parse this as a warning");
16+
617
return {
718
statusCode: 200,
819
body: JSON.stringify({ message: "Success" }),
920
};
10-
}
21+
}

integration-tests/iac/lib/node-tracing-scenarios-stack.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ export class NodeTracingScenariosStack extends cdk.NestedStack {
170170
const kinesisStream = new kinesis.Stream(this, `TracingTestKinesisStream-${runtimeName}`, {
171171
streamName: `${prefix}tracing-test-kinesis-stream-${runtimeName}`,
172172
shardCount: 1,
173+
removalPolicy: cdk.RemovalPolicy.DESTROY,
173174
});
174175

175176
const kinesisProducer = new lambda.Function(this, `KinesisProducerLambda-${runtimeName}`, {

integration-tests/tests/src/test-commonjs-bundle.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
checkLogs,
77
compareJsonStrings,
88
getAttributesMap,
9-
getRequestPayload,
9+
getRequestPayload, LogToCheck,
1010
invokeFunction,
1111
RESOURCE_PREFIX,
1212
} from "./utils";
@@ -65,9 +65,9 @@ const verifyCjsSuccess = async (functionName: string) => {
6565
parentSpanId: parentSpanId!,
6666
success: true,
6767
logsToBeChecked: [
68-
'START RequestId: ',
69-
'Handler invoked with event:',
70-
'END RequestId: ',
68+
{ message: 'START RequestId: ' },
69+
{ message: 'Handler invoked with event:' },
70+
{ message: 'END RequestId: ' },
7171
],
7272
});
7373
};

integration-tests/tests/src/test-dockerized-lambda.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
checkSpanAttributesFromReport,
88
compareJsonStrings,
99
getAttributesMap,
10-
getRequestPayload,
10+
getRequestPayload, LogToCheck,
1111
invokeFunction,
1212
RESOURCE_PREFIX,
1313
} from "./utils";
@@ -66,9 +66,9 @@ const verifyDockerizedInvocation = async (functionName: string, runtime: string)
6666
}
6767
}
6868

69-
const logsToBeChecked = [
70-
'START RequestId: ',
71-
'END RequestId: ',
69+
const logsToBeChecked: LogToCheck[] = [
70+
{ message: 'START RequestId: ' },
71+
{ message: 'END RequestId: ' },
7272
]
7373
await checkLogs({
7474
invocationId: invocationId!,

integration-tests/tests/src/test-java-exception.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { describe, expect, it } from 'vitest';
44
import {DASH0_ENDPOINT, DASH0_TOKEN, MAX_ATTEMPTS, RETRY_DELAY_MS} from "./config";
55
import {
66
checkException, checkHttpSpan, checkLogs,
7-
checkSpanAttributesFromReport, getAttributesMap, getRequestPayload, invokeFunction, runAllTests
7+
checkSpanAttributesFromReport, getAttributesMap, getRequestPayload, invokeFunction, LogToCheck, runAllTests
88
} from "./utils";
99

1010

@@ -71,14 +71,14 @@ const verifySuccessInvocation = async (functionName: string, invocationEnd: bool
7171
}
7272
}
7373
}
74-
const logsToBeChecked = [
75-
'START RequestId: ',
76-
"Input received:",
77-
"java.lang.RuntimeException",
78-
'END RequestId: ',
74+
const logsToBeChecked: LogToCheck[] = [
75+
{ message: 'START RequestId: ' },
76+
{ message: "Input received:" },
77+
{ message: "java.lang.RuntimeException" },
78+
{ message: 'END RequestId: ' },
7979
]
8080
if (!invocationEnd) {
81-
logsToBeChecked.push('REPORT RequestId: ');
81+
logsToBeChecked.push({ message: 'REPORT RequestId: ' });
8282
}
8383
const reportLog = await checkLogs({
8484
invocationId: invocationId!,

integration-tests/tests/src/test-java-success.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
checkLogs,
88
checkResourceAttributes,
99
checkSpanAttributesFromReport,
10-
getAttributesMap,
10+
getAttributesMap, LogToCheck,
1111
getRequestPayload,
1212
invokeFunction, runAllTests
1313
} from "./utils";
@@ -59,12 +59,12 @@ const verifySuccessInvocation = async (functionName: string, invocationEnd: bool
5959
}
6060
}
6161
}
62-
const logsToBeChecked = [
63-
'START RequestId: ',
64-
'END RequestId: ',
62+
const logsToBeChecked: LogToCheck[] = [
63+
{ message: 'START RequestId: ' },
64+
{ message: 'END RequestId: ' },
6565
]
6666
if (!invocationEnd) {
67-
logsToBeChecked.push('REPORT RequestId: ');
67+
logsToBeChecked.push({ message: 'REPORT RequestId: ' });
6868
}
6969
const reportLog = await checkLogs({
7070
invocationId: invocationId!,

integration-tests/tests/src/test-java-timeout.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
checkHttpSpan,
88
checkLogs,
99
checkResourceAttributes,
10-
checkSpanAttributesFromReport,
10+
checkSpanAttributesFromReport, LogToCheck,
1111
getAttributesMap,
1212
getRequestPayload,
1313
invokeFunction, runAllTests
@@ -59,12 +59,12 @@ const verifySuccessInvocation = async (functionName: string, invocationEnd: bool
5959
}
6060
}
6161
}
62-
const logsToBeChecked = [
63-
'START RequestId: ',
64-
'END RequestId: ',
62+
const logsToBeChecked: LogToCheck[] = [
63+
{ message: 'START RequestId: ' },
64+
{ message: 'END RequestId: ' },
6565
]
6666
if (!invocationEnd) {
67-
logsToBeChecked.push('REPORT RequestId: ', "Status: timeout");
67+
logsToBeChecked.push({ message: 'REPORT RequestId: ' }, { message: "Status: timeout" });
6868
}
6969
const reportLog = await checkLogs({
7070
invocationId: invocationId!,

integration-tests/tests/src/test-manual-node.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fetch from 'node-fetch';
22
import { setTimeout as delay } from 'node:timers/promises';
33
import { describe, expect, it } from 'vitest';
44
import { DASH0_ENDPOINT, DASH0_TOKEN, MAX_ATTEMPTS, RETRY_DELAY_MS } from "./config";
5-
import {checkLogs, compareJsonStrings, getAttributesMap, getRequestPayload, invokeFunction, RESOURCE_PREFIX} from "./utils";
5+
import {checkLogs, compareJsonStrings, getAttributesMap, getRequestPayload, invokeFunction, LogToCheck, RESOURCE_PREFIX} from "./utils";
66

77
const verifyManualInstrumentation = async (functionName: string) => {
88
const invocationId = await invokeFunction(functionName, true, false);
@@ -48,10 +48,10 @@ const verifyManualInstrumentation = async (functionName: string) => {
4848
}
4949
}
5050
}
51-
const logsToBeChecked = [
52-
'START RequestId: ',
53-
'[tracing] forceFlush complete',
54-
'END RequestId: ',
51+
const logsToBeChecked: LogToCheck[] = [
52+
{ message: 'START RequestId: ' },
53+
{ message: '[tracing] forceFlush complete' },
54+
{ message: 'END RequestId: ' },
5555
]
5656
await checkLogs({
5757
invocationId: invocationId!,

integration-tests/tests/src/test-node-exception.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { describe, expect, it } from 'vitest';
44
import {DASH0_ENDPOINT, DASH0_TOKEN, MAX_ATTEMPTS, RETRY_DELAY_MS} from "./config";
55
import {
66
checkException, checkHttpSpan, checkLogs,
7-
checkSpanAttributesFromReport, getAttributesMap, getRequestPayload, invokeFunction, runAllTests
7+
checkSpanAttributesFromReport, getAttributesMap, getRequestPayload, invokeFunction, LogToCheck, runAllTests
88
} from "./utils";
99

1010

@@ -65,14 +65,14 @@ const verifySuccessInvocation = async (functionName: string, invocationEnd: bool
6565
}
6666
}
6767
}
68-
const logsToBeChecked = [
69-
'START RequestId: ',
70-
"Handler invoked with event:",
71-
"ReferenceError",
72-
'END RequestId: ',
68+
const logsToBeChecked: LogToCheck[] = [
69+
{ message: 'START RequestId: ' },
70+
{ message: "Handler invoked with event:" },
71+
{ message: "ReferenceError", severity: "error" },
72+
{ message: 'END RequestId: ' },
7373
]
7474
if (!invocationEnd) {
75-
logsToBeChecked.push('REPORT RequestId: ');
75+
logsToBeChecked.push({ message: 'REPORT RequestId: ' });
7676
}
7777
const reportLog = await checkLogs({
7878
invocationId: invocationId!,

integration-tests/tests/src/test-node-importerror.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fetch from 'node-fetch';
22
import { setTimeout as delay } from 'node:timers/promises';
33
import { describe, expect, it } from 'vitest';
44
import {DASH0_ENDPOINT, DASH0_TOKEN, MAX_ATTEMPTS, RETRY_DELAY_MS} from "./config";
5-
import {checkException, checkLogs, getAttributesMap, getRequestPayload, invokeFunction, runAllTests} from "./utils";
5+
import {checkException, checkLogs, getAttributesMap, getRequestPayload, invokeFunction, LogToCheck, runAllTests} from "./utils";
66

77

88
const verifySuccessInvocation = async (functionName: string, invocationEnd: boolean, traced: boolean) => {
@@ -45,12 +45,12 @@ const verifySuccessInvocation = async (functionName: string, invocationEnd: bool
4545
}
4646
}
4747
}
48-
const logsToBeChecked = [
49-
'START RequestId: ',
50-
'END RequestId: ',
48+
const logsToBeChecked: LogToCheck[] = [
49+
{ message: 'START RequestId: ' },
50+
{ message: 'END RequestId: ' },
5151
];
5252
if (!invocationEnd) {
53-
logsToBeChecked.push("Error Type: Runtime.Unknown", "REPORT RequestId: ");
53+
logsToBeChecked.push({ message: "Error Type: Runtime.Unknown" }, { message: "REPORT RequestId: " });
5454
}
5555
await checkLogs({
5656
invocationId: invocationId!,

0 commit comments

Comments
 (0)