Skip to content

Commit e5525c6

Browse files
antoinetissierDaniel Schmidt
authored andcommitted
Support OpenTracing span.context() (#100)
1 parent 04b5f3a commit e5525c6

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

src/__tests__/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,12 @@ describe("Opentracing interface", () => {
249249
expect(span.id.sampled).toBeDefined();
250250
});
251251

252+
it("should expose its context", () => {
253+
const spanContext = span.context();
254+
expect(spanContext.toSpanId()).toBe(span.id.spanId);
255+
expect(spanContext.toTraceId()).toBe(span.id.traceId);
256+
});
257+
252258
it("should log data", () => {
253259
span.log({ event: "data_received", data: "42" });
254260

src/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,18 @@ function SpanCreator({ tracer, serviceName, kind }) {
172172
});
173173
}
174174

175+
context() {
176+
const { spanId, traceId } = this.id;
177+
return {
178+
toSpanId() {
179+
return spanId;
180+
},
181+
toTraceId() {
182+
return traceId;
183+
}
184+
};
185+
}
186+
175187
finish() {
176188
tracer.scoped(() => {
177189
// make sure correct id is set

0 commit comments

Comments
 (0)