Skip to content

Commit 666b06d

Browse files
Ashish AggarwalAshish Aggarwal
authored andcommitted
improving example code and adding getter on isFinished
1 parent a0d7204 commit 666b06d

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

examples/index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
/// first do `npm install haystack-client` and replace '../dist/index' with 'haystack-client'
2121
const initTracer = require('../dist/index').initTracer;
22+
const SpanContext = require('../dist/index').SpanContext;
23+
2224
const opentracing = require('opentracing');
2325
const MyLogger = require('./logger');
2426

@@ -59,11 +61,10 @@ const tracer = initTracer(config);
5961

6062
const serverSpan = tracer
6163
.startSpan('dummy-operation', {
62-
callerSpanContext: {
63-
_traceId: '1848fadd-fa16-4b3e-8ad1-6d73339bbee7',
64-
_spanId: '7a7cc5bf-796e-4527-9b42-13ae5766c6fd',
65-
_parentSpanId: 'e96de653-ad6e-4ad5-b437-e81fd9d2d61d'
66-
}
64+
callerSpanContext: new SpanContext(
65+
'1848fadd-fa16-4b3e-8ad1-6d73339bbee7',
66+
'7a7cc5bf-796e-4527-9b42-13ae5766c6fd',
67+
'e96de653-ad6e-4ad5-b437-e81fd9d2d61d')
6768
})
6869
.setTag(opentracing.Tags.SPAN_KIND, 'server')
6970
.setTag(opentracing.Tags.HTTP_METHOD, 'GET');

src/span.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ export default class Span {
8383
return this;
8484
}
8585

86+
isFinished(): boolean {
87+
return this._isFinished;
88+
}
8689
addTags(keyValues: any): Span {
8790
for (const k in keyValues) {
8891
if (keyValues.hasOwnProperty(k)) {

src/tracer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export default class Tracer {
9494
private _createSpanContext(parent: SpanContext, callerContext: SpanContext): SpanContext {
9595
if (!parent || !parent.isValid) {
9696
if (callerContext) {
97-
return new SpanContext(callerContext._traceId, callerContext._spanId, callerContext._parentSpanId, callerContext._baggage);
97+
return new SpanContext(callerContext.traceId(), callerContext.spanId(), callerContext.parentSpanId(), callerContext.baggage());
9898
} else {
9999
const parentBaggage = parent && parent.baggage();
100100
return new SpanContext(Utils.randomUUID(), Utils.randomUUID(), parentBaggage);

0 commit comments

Comments
 (0)