Skip to content

Commit c52c4b9

Browse files
committed
feat(otel): implement propagation
1 parent ff8ada2 commit c52c4b9

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/api/request.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { RequestContext } from "../models/models";
2+
import { injectPropagation } from "../otel/propagation";
23
import { isMatch } from "../utils/match";
34

45
export type RequestOptions = {
@@ -40,11 +41,17 @@ export function buildRequestUrl(url: string, queryParams: string): string {
4041
}
4142

4243
export function requestHeaderFrom(rq: RequestContext): Object {
43-
return {
44+
const baseHeaders = {
4445
"Content-Type": "application/json",
4546
"x-forwarded-for": rq.ipAddress,
4647
"user-agent": rq.ua,
4748
referer: rq.referer,
4849
"x-request-id": rq.requestId
4950
};
51+
const otelHeaders = injectPropagation();
52+
53+
return {
54+
...baseHeaders,
55+
...otelHeaders
56+
};
5057
}

src/otel/propagation.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { context, propagation } from "@opentelemetry/api";
2+
3+
export function injectPropagation(): Record<string, string> {
4+
const otelHeaders: Record<string, string> = {};
5+
propagation.inject(context.active(), otelHeaders);
6+
return otelHeaders;
7+
}

0 commit comments

Comments
 (0)