Skip to content

Commit cbda58c

Browse files
committed
test(tracer): improve xray trace retrieval
1 parent 57601a6 commit cbda58c

13 files changed

+842
-982
lines changed

package-lock.json

Lines changed: 7 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/testing/package.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
"./types": {
5454
"import": "./lib/esm/types.js",
5555
"require": "./lib/cjs/types.js"
56+
},
57+
"./utils/xray-traces": {
58+
"import": "./lib/esm/xray-traces-utils.js",
59+
"require": "./lib/cjs/xray-traces-utils.js"
5660
}
5761
},
5862
"typesVersions": {
@@ -72,6 +76,10 @@
7276
"context": [
7377
"lib/cjs/context.d.ts",
7478
"lib/esm/context.d.ts"
79+
],
80+
"utils/xray-traces": [
81+
"lib/cjs/xray-traces-utils.d.ts",
82+
"lib/esm/xray-traces-utils.d.ts"
7583
]
7684
}
7785
},
@@ -94,6 +102,10 @@
94102
"@aws-sdk/client-lambda": "^3.637.0",
95103
"@smithy/util-utf8": "^3.0.0",
96104
"aws-cdk-lib": "^2.155.0",
97-
"esbuild": "^0.23.1"
105+
"esbuild": "^0.23.1",
106+
"promise-retry": "^2.0.1"
107+
},
108+
"devDependencies": {
109+
"@types/promise-retry": "^1.1.6"
98110
}
99-
}
111+
}

packages/testing/src/types.ts

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,94 @@ interface TestStackProps {
8787
stack?: Stack;
8888
}
8989

90+
// #region X-Ray Trace Utils
91+
92+
type GetXRayTraceIdsOptions = {
93+
startTime: Date;
94+
resourceName: string;
95+
expectedTracesCount: number;
96+
};
97+
98+
type XRayTraceDocumentParsed = {
99+
name: string;
100+
id: string;
101+
start_time: number;
102+
end_time?: number;
103+
// This flag may be set if the segment hasn't been fully processed
104+
// The trace may have already appeared in the `getTraceSummaries` response
105+
// but a segment may still be in_progress
106+
in_progress?: boolean;
107+
aws?: {
108+
request_id: string;
109+
};
110+
http?: {
111+
response: {
112+
status: number;
113+
};
114+
};
115+
origin?: string;
116+
resource_arn?: string;
117+
trace_id?: string;
118+
subsegments?: XRayTraceDocumentParsed[];
119+
annotations?: {
120+
[key: string]: string | boolean | number;
121+
};
122+
metadata?: {
123+
[key: string]: {
124+
[key: string]: unknown;
125+
};
126+
};
127+
fault?: boolean;
128+
cause?: {
129+
working_directory: string;
130+
exceptions: {
131+
message: string;
132+
type: string;
133+
remote: boolean;
134+
stack: {
135+
path: string;
136+
line: number;
137+
label: string;
138+
}[];
139+
}[];
140+
};
141+
exception: {
142+
message: string;
143+
};
144+
error?: boolean;
145+
};
146+
147+
type XRaySegmentParsed = {
148+
Id: string;
149+
Document: XRayTraceDocumentParsed;
150+
};
151+
152+
type XRayTraceParsed = {
153+
Id: string;
154+
Segments: XRaySegmentParsed[];
155+
};
156+
157+
type GetXRayTraceDetailsOptions = {
158+
/**
159+
* The trace IDs to get details for
160+
*/
161+
traceIds: string[];
162+
/**
163+
* The expected number of segments in each trace
164+
*/
165+
expectedSegmentsCount: number;
166+
};
167+
168+
/**
169+
* Enriched X-Ray trace document parsed with subsegments as a map
170+
*/
171+
type EnrichedXRayTraceDocumentParsed = Omit<
172+
XRayTraceDocumentParsed,
173+
'subsegments'
174+
> & {
175+
subsegments: Map<string, XRayTraceDocumentParsed>;
176+
};
177+
90178
export type {
91179
ExtraTestProps,
92180
TestDynamodbTableProps,
@@ -96,4 +184,10 @@ export type {
96184
FunctionLog,
97185
StackNameProps,
98186
TestStackProps,
187+
GetXRayTraceIdsOptions,
188+
GetXRayTraceDetailsOptions,
189+
XRayTraceDocumentParsed,
190+
XRaySegmentParsed,
191+
XRayTraceParsed,
192+
EnrichedXRayTraceDocumentParsed,
99193
};

0 commit comments

Comments
 (0)