Skip to content

Commit f37e776

Browse files
Fix HTTP headers in fetch instrumentation (#489)
1 parent 09a02bb commit f37e776

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

features/support/tracer.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ function wrap(method: any) {
1212
return tracer.trace(
1313
"fetch",
1414
{ type: "http", resource: request.getUrl() },
15-
(span: any) => {
15+
(span: any, callback?: (error?: Error) => string) => {
1616
const spanId = span.context().toSpanId();
1717
const traceId = span.context().toTraceId();
1818
request.setHeaderParam("x-datadog-parent-id", spanId);
1919
request.setHeaderParam("x-datadog-trace-id", traceId);
20+
// These headers are required to prevent the continuation of the trace from being dropped
21+
request.setHeaderParam("x-datadog-origin", "ciapp-test");
22+
request.setHeaderParam("x-datadog-sampling-priority", "1");
23+
request.setHeaderParam("x-datadog-sampled", "1");
2024
const response = method(request);
2125

2226
response.promise = response.promise.then((responseContext: any) => {
@@ -29,6 +33,13 @@ function wrap(method: any) {
2933
}
3034
return responseContext;
3135
});
36+
37+
response.promise.finally(() => {
38+
if (callback) {
39+
callback()
40+
}
41+
});
42+
3243
return response;
3344
}
3445
);

0 commit comments

Comments
 (0)