Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should convert span with 128 bit traceId', () => {
let reporter = new InMemoryReporter();
let tracer = new Tracer('test-service-name', reporter, new ConstSampler(true), { traceId128bit: true });
let span = tracer.startSpan('some operation');
let childOfRef = new opentracing.Reference(opentracing.REFERENCE_CHILD_OF, span.context());
let childSpan = tracer.startSpan('some child operation', { references: [childOfRef] });
childSpan.finish();
span.finish();
tracer.close();
let tSpan = ThriftUtils.spanToThrift(childSpan);
assert.deepEqual(tSpan.traceIdLow, childSpan.context().traceId.slice(-8));
assert.deepEqual(tSpan.traceIdHigh, childSpan.context().traceId.slice(-16, -8));
assert.deepEqual(tSpan.spanId, childSpan.context().spanId);
assert.deepEqual(tSpan.references[0].traceIdLow, span.context().traceId.slice(-8));
assert.deepEqual(tSpan.references[0].traceIdHigh, span.context().traceId.slice(-16, -8));
assert.deepEqual(tSpan.references[0].spanId, span.context().spanId);
});
describe('span reference tests', () => {
let tracer = new Tracer('test-service-name', new InMemoryReporter(), new ConstSampler(true));
let parentContext = tracer.startSpan('just-used-for-context').context();
let childOfContext = tracer.startSpan('just-used-for-context').context();
let childOfRef = new opentracing.Reference(opentracing.REFERENCE_CHILD_OF, childOfContext);
let followsFromContext = tracer.startSpan('just-used-for-context').context();
let followsFromRef = new opentracing.Reference(opentracing.REFERENCE_FOLLOWS_FROM, followsFromContext);
let options = [
{ childOf: null, references: [], expectedTraceId: null, expectedParentId: null },
{
childOf: parentContext,
references: [childOfRef, followsFromRef],
expectedTraceId: parentContext.traceId,
expectedParentId: parentContext.parentId,
},
];
_.each(options, o => {
it('should serialize span references', done => {
const span = tracer.startSpan('bender', {
describe('start a child span represented as a separate span from parent, using childOf and references', () => {
let nextId = 0;
const getId = () => Utils.encodeInt64(nextId++);
const traceId = getId();
const flags = 1;
const parentContext = SpanContext.withBinaryIds(traceId, getId(), null, flags);
const childOfContext = SpanContext.withBinaryIds(traceId, getId(), null, flags);
const childOfRef = new opentracing.Reference(opentracing.REFERENCE_CHILD_OF, childOfContext);
const followsFromContext = SpanContext.withBinaryIds(traceId, getId(), null, flags);
const followsFromRef = new opentracing.Reference(opentracing.REFERENCE_FOLLOWS_FROM, followsFromContext);
const testCases = [
{
message: 'starts a span based on childOf',
spanOptions: {
childOf: parentContext,
references: [],
},
verify: parentContext,
},
{
message: 'starts a span based on childOf, ignoring FOLLOWS_FROM',
spanOptions: {
childOf: parentContext,
expect(function () {
return new ot.Reference(ot.REFERENCE_CHILD_OF, span)
}).not.toThrow(Error)
expect(function () {
type: 'new-type'
})
expect(childSpan.span.type).toBe('new-type')
expect(childSpan.span.context).toEqual({
tags: {
another_tag: 'test-tag',
user_id: 'test-id',
user_username: 'test-username',
user_email: 'test-email'
}
})
var SecondChildSpan = tracer.startSpan('span-name', {
tags: { type: 'span-type' },
references: [new Reference(REFERENCE_CHILD_OF, childSpan)]
})
expect(SecondChildSpan.span.parentId).toBe(childSpan.span.id)
})
})
expect(function () {
return new ot.Reference(ot.REFERENCE_CHILD_OF, span.context())
}).not.toThrow(Error)
})
public createRootSpanOnMessage(message: IMessageBase): Span {
const spanContext = this._tracer.extract(FORMAT_TEXT_MAP, message) as any;
const properties = message.properties;
let spanOptions: { references: Reference[] } | undefined;
if (spanContext && spanContext.isValid) {
const ref = new Reference('follows_from', spanContext as SpanContext);
spanOptions = { references: [ref] };
}
const rootSpan = this._tracer.startSpan('handle_message', spanOptions);
rootSpan.addTags({ activityId: properties.activityId });
rootSpan.addTags({ businessKey: properties.businessKey });
rootSpan.addTags({ workerId: properties.workerId });
rootSpan.addTags({ topicName: properties.topicName });
return rootSpan;
}
public onMessageFailed(e: Error, { spans }: IMessage): void {