Skip to content

Commit 4738b4a

Browse files
Convert datadog-metadata subsegment's start and end times from milliseconds to seconds (#236)
convert dd subsegment start and end times to seconds
1 parent 261c190 commit 4738b4a

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/trace/context.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ describe("extractTraceContext", () => {
839839
const sentMessage = sentSegment.toString();
840840
expect(sentMessage).toMatchInlineSnapshot(`
841841
"{\\"format\\": \\"json\\", \\"version\\": 1}
842-
{\\"id\\":\\"11111\\",\\"trace_id\\":\\"1-5e272390-8c398be037738dc042009320\\",\\"parent_id\\":\\"94ae789b969f1cc5\\",\\"name\\":\\"datadog-metadata\\",\\"start_time\\":1487076708000,\\"end_time\\":1487076708000,\\"type\\":\\"subsegment\\",\\"metadata\\":{\\"datadog\\":{\\"trace\\":{\\"parent-id\\":\\"797643193680388251\\",\\"sampling-priority\\":\\"2\\",\\"trace-id\\":\\"4110911582297405551\\"}}}}"
842+
{\\"id\\":\\"11111\\",\\"trace_id\\":\\"1-5e272390-8c398be037738dc042009320\\",\\"parent_id\\":\\"94ae789b969f1cc5\\",\\"name\\":\\"datadog-metadata\\",\\"start_time\\":1487076708,\\"end_time\\":1487076708,\\"type\\":\\"subsegment\\",\\"metadata\\":{\\"datadog\\":{\\"trace\\":{\\"parent-id\\":\\"797643193680388251\\",\\"sampling-priority\\":\\"2\\",\\"trace-id\\":\\"4110911582297405551\\"}}}}"
843843
`);
844844
});
845845
it("skips adding datadog metadata to x-ray when daemon isn't present", () => {
@@ -889,7 +889,7 @@ describe("extractTraceContext", () => {
889889
const sentMessage = sentSegment.toString();
890890
expect(sentMessage).toMatchInlineSnapshot(`
891891
"{\\"format\\": \\"json\\", \\"version\\": 1}
892-
{\\"id\\":\\"11111\\",\\"trace_id\\":\\"1-5e272390-8c398be037738dc042009320\\",\\"parent_id\\":\\"94ae789b969f1cc5\\",\\"name\\":\\"datadog-metadata\\",\\"start_time\\":1487076708000,\\"end_time\\":1487076708000,\\"type\\":\\"subsegment\\",\\"metadata\\":{\\"datadog\\":{\\"root_span_metadata\\":{\\"step_function.execution_id\\":\\"fb7b1e15-e4a2-4cb2-963f-8f1fa4aec492\\",\\"step_function.retry_count\\":2,\\"step_function.state_machine_arn\\":\\"arn:aws:states:us-east-1:601427279990:stateMachine:HelloStepOneStepFunctionsStateMachine-z4T0mJveJ7pJ\\",\\"step_function.state_machine_name\\":\\"my-state-machine\\",\\"step_function.step_name\\":\\"step-one\\"}}}}"
892+
{\\"id\\":\\"11111\\",\\"trace_id\\":\\"1-5e272390-8c398be037738dc042009320\\",\\"parent_id\\":\\"94ae789b969f1cc5\\",\\"name\\":\\"datadog-metadata\\",\\"start_time\\":1487076708,\\"end_time\\":1487076708,\\"type\\":\\"subsegment\\",\\"metadata\\":{\\"datadog\\":{\\"root_span_metadata\\":{\\"step_function.execution_id\\":\\"fb7b1e15-e4a2-4cb2-963f-8f1fa4aec492\\",\\"step_function.retry_count\\":2,\\"step_function.state_machine_arn\\":\\"arn:aws:states:us-east-1:601427279990:stateMachine:HelloStepOneStepFunctionsStateMachine-z4T0mJveJ7pJ\\",\\"step_function.state_machine_name\\":\\"my-state-machine\\",\\"step_function.step_name\\":\\"step-one\\"}}}}"
893893
`);
894894
});
895895
});

src/trace/context.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ export function generateXraySubsegment(key: string, metadata: Record<string, any
134134
logDebug("couldn't parse xray trace header from env");
135135
return;
136136
}
137-
const time = Date.now();
137+
138+
// Convert from milliseconds to seconds
139+
const time = Date.now() * 0.001;
138140

139141
return JSON.stringify({
140142
id: randomBytes(8).toString("hex"),

0 commit comments

Comments
 (0)