Skip to content

Commit

Permalink
Merge bf0b1ae into a481762
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanista authored Feb 7, 2024
2 parents a481762 + bf0b1ae commit 226cee8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
34 changes: 33 additions & 1 deletion src/trace/span-context-wrapper.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SpanContextWrapper } from "./span-context-wrapper";
import { TraceSource } from "./trace-context-service";
import { SampleMode, TraceSource } from "./trace-context-service";

describe("SpanContextWrapper", () => {
beforeEach(() => {});
Expand All @@ -20,4 +20,36 @@ describe("SpanContextWrapper", () => {
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]);
});

describe("sampleMode", () => {
it("should return AUTO_KEEP when sampling priority is not available in spanContext", () => {
const spanContext = new SpanContextWrapper(
{
toSpanId: () => "1234",
toTraceId: () => "5678",
_sampling: {},
},
TraceSource.Event,
);

const sampleMode = spanContext.sampleMode();
expect(sampleMode).toBe(SampleMode.AUTO_KEEP);
expect(sampleMode.toString()).toBe("1");
});

it("should return sampling priority when available in spanContext", () => {
const spanContext = new SpanContextWrapper(
{
toSpanId: () => "1234",
toTraceId: () => "5678",
_sampling: { priority: 2 },
},
TraceSource.Event,
);

const sampleMode = spanContext.sampleMode();
expect(sampleMode).toBe(2);
expect(sampleMode.toString()).toBe("2");
});
});
});
4 changes: 2 additions & 2 deletions src/trace/span-context-wrapper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { logDebug } from "../utils";
import { TraceContext, TraceSource } from "./trace-context-service";
import { SampleMode, TraceContext, TraceSource } from "./trace-context-service";
import { SpanContext } from "./tracer-wrapper";

/**
Expand All @@ -18,7 +18,7 @@ export class SpanContextWrapper implements SpanContext {
}

public sampleMode(): number {
return this.spanContext._sampling?.priority;
return this.spanContext._sampling?.priority ?? SampleMode.AUTO_KEEP;
}

public toString = (): string => {
Expand Down

0 comments on commit 226cee8

Please sign in to comment.