opentracing
Advanced tools
Comparing version 0.14.6 to 0.14.7
@@ -5,2 +5,3 @@ "use strict"; | ||
var reference_1 = require("./reference"); | ||
var span_1 = require("./span"); | ||
/** | ||
@@ -14,2 +15,6 @@ * Return a new REFERENCE_CHILD_OF reference. | ||
function childOf(spanContext) { | ||
// Allow the user to pass a Span instead of a SpanContext | ||
if (spanContext instanceof span_1.default) { | ||
spanContext = spanContext.context(); | ||
} | ||
return new reference_1.default(Constants.REFERENCE_CHILD_OF, spanContext); | ||
@@ -26,2 +31,6 @@ } | ||
function followsFrom(spanContext) { | ||
// Allow the user to pass a Span instead of a SpanContext | ||
if (spanContext instanceof span_1.default) { | ||
spanContext = spanContext.context(); | ||
} | ||
return new reference_1.default(Constants.REFERENCE_FOLLOWS_FROM, spanContext); | ||
@@ -28,0 +37,0 @@ } |
@@ -1,3 +0,2 @@ | ||
import Span from '../span'; | ||
import Tracer from '../tracer'; | ||
import * as opentracing from '../index'; | ||
import Reference from '../reference'; | ||
@@ -17,3 +16,3 @@ import MockContext from './mock_context'; | ||
*/ | ||
export declare class MockSpan extends Span { | ||
export declare class MockSpan extends opentracing.Span { | ||
private _operationName; | ||
@@ -43,3 +42,3 @@ private _tags; | ||
}; | ||
tracer(): Tracer; | ||
tracer(): opentracing.Tracer; | ||
private _generateUUID; | ||
@@ -46,0 +45,0 @@ addReference(ref: Reference): void; |
@@ -17,3 +17,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var span_1 = require("../span"); | ||
var opentracing = require("../index"); | ||
var mock_context_1 = require("./mock_context"); | ||
@@ -101,5 +101,5 @@ /** | ||
return MockSpan; | ||
}(span_1.default)); | ||
}(opentracing.Span)); | ||
exports.MockSpan = MockSpan; | ||
exports.default = MockSpan; | ||
//# sourceMappingURL=mock_span.js.map |
@@ -1,2 +0,2 @@ | ||
import { SpanOptions, Tracer } from '../tracer'; | ||
import * as opentracing from '../index'; | ||
import MockContext from './mock_context'; | ||
@@ -8,5 +8,5 @@ import MockReport from './mock_report'; | ||
*/ | ||
export declare class MockTracer extends Tracer { | ||
export declare class MockTracer extends opentracing.Tracer { | ||
private _spans; | ||
protected _startSpan(name: string, fields: SpanOptions): MockSpan; | ||
protected _startSpan(name: string, fields: opentracing.SpanOptions): MockSpan; | ||
protected _inject(span: MockContext, format: any, carrier: any): never; | ||
@@ -13,0 +13,0 @@ protected _extract(format: any, carrier: any): never; |
@@ -17,3 +17,3 @@ "use strict"; | ||
// TODO: Move mock-tracer to its own NPM package once it is complete and tested. | ||
var tracer_1 = require("../tracer"); | ||
var opentracing = require("../index"); | ||
var mock_report_1 = require("./mock_report"); | ||
@@ -77,5 +77,5 @@ var mock_span_1 = require("./mock_span"); | ||
return MockTracer; | ||
}(tracer_1.Tracer)); | ||
}(opentracing.Tracer)); | ||
exports.MockTracer = MockTracer; | ||
exports.default = MockTracer; | ||
//# sourceMappingURL=mock_tracer.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var span_1 = require("./span"); | ||
var span_context_1 = require("./span_context"); | ||
var toContext = function (contextOrSpan) { | ||
if (contextOrSpan instanceof span_context_1.default) { | ||
return contextOrSpan; | ||
} | ||
// Second check is for cases when a Span implementation does not extend | ||
// opentracing.Span class directly (like Jaeger), just implements the same interface. | ||
// The only false-positive case here is a non-extending SpanContext class, | ||
// which has a method called "context". | ||
// But that's too much of a specification violation to take care of. | ||
if (contextOrSpan instanceof span_1.default || 'context' in contextOrSpan) { | ||
return contextOrSpan.context(); | ||
} | ||
return contextOrSpan; | ||
}; | ||
/** | ||
@@ -37,3 +22,5 @@ * Reference pairs a reference type constant (e.g., REFERENCE_CHILD_OF or | ||
this._type = type; | ||
this._referencedContext = toContext(referencedContext); | ||
this._referencedContext = (referencedContext instanceof span_1.default ? | ||
referencedContext.context() : | ||
referencedContext); | ||
} | ||
@@ -40,0 +27,0 @@ /** |
@@ -18,6 +18,2 @@ "use strict"; | ||
var opentracing = require("../index"); | ||
var mock_context_1 = require("../mock_tracer/mock_context"); | ||
var mock_span_1 = require("../mock_tracer/mock_span"); | ||
var mock_tracer_1 = require("../mock_tracer/mock_tracer"); | ||
var span_context_1 = require("../span_context"); | ||
function opentracingAPITests() { | ||
@@ -109,28 +105,2 @@ describe('Opentracing API', function () { | ||
}); | ||
it('should get context from custom extending span classes', function () { | ||
var span = new mock_span_1.default(new mock_tracer_1.default()); | ||
var ref = new opentracing.Reference(opentracing.REFERENCE_CHILD_OF, span); | ||
chai_1.expect(ref.referencedContext() instanceof span_context_1.default).to.equal(true); | ||
}); | ||
it('should get context from custom non-extending span classes', function () { | ||
var ctx = new span_context_1.default(); | ||
var pseudoSpan = { | ||
context: function () { return ctx; } | ||
}; | ||
var ref = new opentracing.Reference(opentracing.REFERENCE_CHILD_OF, pseudoSpan); | ||
chai_1.expect(ref.referencedContext()).to.equal(ctx); | ||
}); | ||
it('should use extending contexts', function () { | ||
var ctx = new mock_context_1.default({}); | ||
var ref = new opentracing.Reference(opentracing.REFERENCE_CHILD_OF, ctx); | ||
chai_1.expect(ref.referencedContext()).to.equal(ctx); | ||
}); | ||
it('should use non-extending contexts', function () { | ||
var ctx = { | ||
toTraceId: function () { return ''; }, | ||
toSpanId: function () { return ''; } | ||
}; | ||
var ref = new opentracing.Reference(opentracing.REFERENCE_CHILD_OF, ctx); | ||
chai_1.expect(ref.referencedContext()).to.equal(ctx); | ||
}); | ||
}); | ||
@@ -137,0 +107,0 @@ describe('BinaryCarrier', function () { |
{ | ||
"name": "opentracing", | ||
"version": "0.14.6", | ||
"version": "0.14.7", | ||
"engines": { | ||
@@ -5,0 +5,0 @@ "node": ">=0.10" |
@@ -14,2 +14,6 @@ import * as Constants from './constants'; | ||
export function childOf(spanContext: SpanContext | Span): Reference { | ||
// Allow the user to pass a Span instead of a SpanContext | ||
if (spanContext instanceof Span) { | ||
spanContext = spanContext.context(); | ||
} | ||
return new Reference(Constants.REFERENCE_CHILD_OF, spanContext); | ||
@@ -26,3 +30,7 @@ } | ||
export function followsFrom(spanContext: SpanContext | Span): Reference { | ||
// Allow the user to pass a Span instead of a SpanContext | ||
if (spanContext instanceof Span) { | ||
spanContext = spanContext.context(); | ||
} | ||
return new Reference(Constants.REFERENCE_FOLLOWS_FROM, spanContext); | ||
} |
/* eslint-disable import/no-extraneous-dependencies */ | ||
import Span from '../span'; | ||
import Tracer from '../tracer' | ||
import * as opentracing from '../index'; | ||
import Reference from '../reference'; | ||
@@ -24,3 +23,3 @@ import MockContext from './mock_context'; | ||
*/ | ||
export class MockSpan extends Span { | ||
export class MockSpan extends opentracing.Span { | ||
@@ -97,3 +96,3 @@ private _operationName: string; | ||
tracer(): Tracer { | ||
tracer(): opentracing.Tracer { | ||
return this._mockTracer; | ||
@@ -100,0 +99,0 @@ } |
// TODO: Move mock-tracer to its own NPM package once it is complete and tested. | ||
import {SpanOptions, Tracer} from '../tracer'; | ||
import * as opentracing from '../index'; | ||
import MockContext from './mock_context'; | ||
@@ -11,3 +11,3 @@ import MockReport from './mock_report'; | ||
*/ | ||
export class MockTracer extends Tracer { | ||
export class MockTracer extends opentracing.Tracer { | ||
@@ -20,3 +20,3 @@ private _spans: MockSpan[]; | ||
protected _startSpan(name: string, fields: SpanOptions): MockSpan { | ||
protected _startSpan(name: string, fields: opentracing.SpanOptions): MockSpan { | ||
// _allocSpan is given it's own method so that derived classes can | ||
@@ -23,0 +23,0 @@ // allocate any type of object they want, but not have to duplicate |
import Span from './span'; | ||
import SpanContext from './span_context'; | ||
const toContext = (contextOrSpan: SpanContext | Span): SpanContext => { | ||
if (contextOrSpan instanceof SpanContext) { | ||
return contextOrSpan; | ||
} | ||
// Second check is for cases when a Span implementation does not extend | ||
// opentracing.Span class directly (like Jaeger), just implements the same interface. | ||
// The only false-positive case here is a non-extending SpanContext class, | ||
// which has a method called "context". | ||
// But that's too much of a specification violation to take care of. | ||
if (contextOrSpan instanceof Span || 'context' in contextOrSpan) { | ||
return contextOrSpan.context(); | ||
} | ||
return contextOrSpan; | ||
}; | ||
/** | ||
@@ -59,4 +42,7 @@ * Reference pairs a reference type constant (e.g., REFERENCE_CHILD_OF or | ||
this._type = type; | ||
this._referencedContext = toContext(referencedContext); | ||
this._referencedContext = ( | ||
referencedContext instanceof Span ? | ||
referencedContext.context() : | ||
referencedContext); | ||
} | ||
} |
import { expect } from 'chai'; | ||
import * as opentracing from '../index'; | ||
import MockContext from '../mock_tracer/mock_context'; | ||
import MockSpan from '../mock_tracer/mock_span'; | ||
import MockTracer from '../mock_tracer/mock_tracer'; | ||
import Span from '../span'; | ||
import SpanContext from '../span_context'; | ||
@@ -93,32 +88,2 @@ export function opentracingAPITests(): void { | ||
}); | ||
it('should get context from custom extending span classes', () => { | ||
const span = new MockSpan(new MockTracer()); | ||
const ref = new opentracing.Reference(opentracing.REFERENCE_CHILD_OF, span); | ||
expect(ref.referencedContext() instanceof SpanContext).to.equal(true); | ||
}); | ||
it('should get context from custom non-extending span classes', () => { | ||
const ctx = new SpanContext(); | ||
const pseudoSpan = { | ||
context: () => ctx | ||
} as Span; | ||
const ref = new opentracing.Reference(opentracing.REFERENCE_CHILD_OF, pseudoSpan); | ||
expect(ref.referencedContext()).to.equal(ctx); | ||
}); | ||
it('should use extending contexts', () => { | ||
const ctx = new MockContext({} as MockSpan); | ||
const ref = new opentracing.Reference(opentracing.REFERENCE_CHILD_OF, ctx); | ||
expect(ref.referencedContext()).to.equal(ctx); | ||
}); | ||
it('should use non-extending contexts', () => { | ||
const ctx = { | ||
toTraceId: () => '', | ||
toSpanId: () => '' | ||
}; | ||
const ref = new opentracing.Reference(opentracing.REFERENCE_CHILD_OF, ctx); | ||
expect(ref.referencedContext()).to.equal(ctx); | ||
}); | ||
}); | ||
@@ -125,0 +90,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
194807
3269