8000 test flattening multiValueHeaders with real ALB event · DataDog/datadog-lambda-js@032f3ca · GitHub
[go: up one dir, main page]

Skip to content

Commit 032f3ca

Browse files
committed
test flattening multiValueHeaders with real ALB event
1 parent 96300cd commit 032f3ca

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"requestContext": {
3+
"elb": {
4+
"targetGroupArn": "arn:aws:elasticloadbalancing:us-east-1:1234567890:targetgroup/nhulston-alb-test/dcabb42f66a496e0"
5+
}
6+
},
7+
"httpMethod": "GET",
8+
"path": "/",
9+
"multiValueQueryStringParameters": {},
10+
"multiValueHeaders": {
11+
"accept": [
12+
"*/*"
13+
],
14+
"accept-encoding": [
15+
"gzip, deflate"
16+
],
17+
"accept-language": [
18+
"*"
19+
],
20+
"connection": [
21+
"keep-alive"
22+
],
23+
"host": [
24+
"nhulston-test-0987654321.us-east-1.elb.amazonaws.com"
25+
],
26+
"sec-fetch-mode": [
27+
"cors"
28+
],
29+
"traceparent": [
30+
"00-68126c4300000000125a7f065cf9a530-1c6dcc8ab8a6e99d-01"
31+
],
32+
"tracestate": [
33+
"dd=t.dm:-0;t.tid:68126c4300000000;s:1;p:1c6dcc8ab8a6e99d"
34+
],
35+
"user-agent": [
36+
"node"
37+
],
38+
"x-amzn-trace-id": [
39+
"Root=1-68126c45-01b175997ab51c4c47a2d643"
40+
],
41+
"x-datadog-parent-id": [
42+
"1234567890"
43+
],
44+
"x-datadog-sampling-priority": [
45+
"1"
46+
],
47+
"x-datadog-tags": [
48+
"_dd.p.tid=68126c4300000000,_dd.p.dm=-0"
49+
],
50+
"x-datadog-trace-id": [
51+
"0987654321"
52+
],
53+
"x-forwarded-for": [
54+
"18.204.55.6"
55+
],
56+
"x-forwarded-port": [
57+
"80"
58+
],
59+
"x-forwarded-proto": [
60+
"http"
61+
]
62+
},
63+
"body": "",
64+
"isBase64Encoded": false
65+
}

src/trace/context/extractors/http.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { TracerWrapper } from "../../tracer-wrapper";
22
import { HTTPEventSubType, HTTPEventTraceExtractor } from "./http";
3+
const albMultivalueHeadersEvent = require("../../../../event_samples/application-load-balancer-multivalue-headers.json");
34

45
let mockSpanContext: any = null;
56

@@ -126,6 +127,37 @@ describe("HTTPEventTraceExtractor", () => {
126127
expect(traceContext?.sampleMode()).toBe("1");
127128
});
128129

130+
it("flattens a real ALB multiValueHeaders payload into a lowercase, single-value map", () => {
131+
const tracerWrapper = new TracerWrapper();
132+
const extractor = new HTTPEventTraceExtractor(tracerWrapper);
133+
134+
spyTracerWrapper.mockClear();
135+
extractor.extract(albMultivalueHeadersEvent);
136+
expect(spyTracerWrapper).toHaveBeenCalled();
137+
138+
const captured = spyTracerWrapper.mock.calls[0][0] as Record<string, string>;
139+
140+
expect(captured).toEqual({
141+
accept: "*/*",
142+
"accept-encoding": "gzip, deflate",
143+
"accept-language": "*",
144+
connection: "keep-alive",
145+
host: "nhulston-test-0987654321.us-east-1.elb.amazonaws.com",
146+
"sec-fetch-mode": "cors",
147+
"user-agent": "node",
148+
traceparent: "00-68126c4300000000125a7f065cf9a530-1c6dcc8ab8a6e99d-01",
149+
tracestate: "dd=t.dm:-0;t.tid:68126c4300000000;s:1;p:1c6dcc8ab8a6e99d",
150+
"x-amzn-trace-id": "Root=1-68126c45-01b175997ab51c4c47a2d643",
151+
"x-datadog-tags": "_dd.p.tid=68126c4300000000,_dd.p.dm=-0",
152+
"x-datadog-sampling-priority": "1",
153+
"x-datadog-trace-id": "0987654321",
154+
"x-datadog-parent-id": "1234567890",
155+
"x-forwarded-for": "18.204.55.6",
156+
"x-forwarded-port": "80",
157+
"x-forwarded-proto": "http",
158+
});
159+
});
160+
129161
it("extracts trace context from payload with authorizer", () => {
130162
mockSpanContext = {
131163
toTraceId: () => "2389589954026090296",

0 commit comments

Comments
 (0)
0