Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SLES-1463] [SLES-1454] Fix id.toArray() issue #455

Merged
merged 2 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/trace/span-context-wrapper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,17 @@ describe("SpanContextWrapper", () => {
it("fromTraceContext", () => {
const traceContext = {
traceId: "8768810343773813232",
parentId: "6004d9aeb61ddcac",
parentId: "6918894271950871724",
sampleMode: 1,
source: TraceSource.Event,
};
const spanContext = SpanContextWrapper.fromTraceContext(traceContext);

expect(spanContext?.toTraceId()).toBe("8768810343773813232");
expect(spanContext?.toSpanId()).toBe("6004d9aeb61ddcac");
expect(spanContext?.toSpanId()).toBe("6918894271950871724");
expect(spanContext?.sampleMode()).toBe("1");
expect(spanContext?.source).toBe("event");
// The inner type dd-trace/packages/dd-trace/src/opentracing/span_context
// must have traceId and spanId as objects instead of strings because of the toArray() call
// https://github.com/DataDog/dd-trace-js/blob/9c71b3060081a77639bab4c6b2a26c952f4a114f/packages/dd-trace/src/encode/0.4.js#L168
expect(spanContext?.spanContext._traceId).toBeInstanceOf(Object);
expect(spanContext?.spanContext._spanId).toBeInstanceOf(Object);
expect(spanContext?.spanContext._traceId.toArray()).toEqual([121, 177, 18, 140, 107, 104, 185, 240]);
expect(spanContext?.spanContext._spanId.toArray()).toEqual([96, 4, 217, 174, 182, 29, 220, 172]);
});
});
9 changes: 3 additions & 6 deletions src/trace/span-context-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,12 @@ export class SpanContextWrapper implements SpanContext {
try {
// Try requiring class from the tracer.
const _DatadogSpanContext = require("dd-trace/packages/dd-trace/src/opentracing/span_context");
const id = require("dd-trace/packages/dd-trace/src/id");

return new SpanContextWrapper(
// The inner type _DatadogSpanContext must have traceId and spanId as objects instead of strings because of the toArray() call
// https://github.com/DataDog/dd-trace-js/blob/9c71b3060081a77639bab4c6b2a26c952f4a114f/packages/dd-trace/src/encode/0.4.js#L168
new _DatadogSpanContext({
// tslint:disable-next-line:no-construct
traceId: new String(traceId),
// tslint:disable-next-line:no-construct
spanId: new String(spanId),
traceId: id(traceId, 10),
spanId: id(spanId, 10),
sampling: { priority: samplingPriority },
}),
source,
Expand Down