test('#inject(span, http, {})', setup(function (t) { const tracer = new Tracer(getAgent()) const span = tracer.startSpan('foo') const carrier = {} tracer.inject(span, opentracing.FORMAT_HTTP_HEADERS, carrier) t.equal(carrier['elastic-apm-traceparent'], span.context().toString()) t.end() }))
Object.keys(carrier).forEach(carrierKey => { if (carrierKey.indexOf(baggageKeyPrefix) !== 0) { return; } const baggageKey = carrierKey.substring(baggageKeyPrefix.length); spanContext.baggage[baggageKey] = valueDecoder(carrier[carrierKey]); });
test('#inject(noop, http, {})', setup(function (t) { const agent = getAgent() agent._conf.transactionSampleRate = 0 const tracer = new Tracer(agent) const span1 = tracer.startSpan('foo') t.equal(span1._isTransaction, true) t.equal(span1._span.sampled, false) const span2 = tracer.startSpan('foo') t.ok(span2 instanceof UnsampledSpan) const carrier = {} tracer.inject(span2, opentracing.FORMAT_HTTP_HEADERS, carrier) t.equal(carrier['elastic-apm-traceparent'], span1.context().toString()) agent._conf.transactionSampleRate = 1 t.end() }))
// This currently doesn't behave in a logical way as when the followsFrom // reference is being ignored, the agent will simply automatically associate // span2 with span1, because span1 is a transaction test.skip('#startSpan(name, {references: [followsFrom]})', setup(function (t) { const tracer = new Tracer(getAgent()) const span1 = tracer.startSpan('foo') const references = [ new opentracing.Reference(opentracing.REFERENCE_FOLLOWS_FROM, span1.context()) ] const span2 = tracer.startSpan('bar', { references }) const _span1 = span1.context()._context const _span2 = span2.context()._context t.notEqual(_span1.traceId, _span1.traceId) t.notEqual(_span1.id, _span1.id) t.equal(_span2.parentId, undefined) t.equal(_span1.parentId, undefined) t.end() }))
test('#startSpan() - ended transaction', setup(function (t) { const tracer = new Tracer(getAgent()) const span1 = tracer.startSpan('foo') span1.finish() const span2 = tracer.startSpan('bar') t.equal(span1._isTransaction, true) t.equal(span2._isTransaction, true) t.equal(span1.context()._context.parentId, undefined) t.equal(span2.context()._context.parentId, undefined) t.end() }))
test('#extract(http, {elastic-apm-traceparent: valid})', setup(function (t) { const tracer = new Tracer(getAgent()) const context = tracer.extract(opentracing.FORMAT_HTTP_HEADERS, { 'elastic-apm-traceparent': '00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01' }) t.ok(context instanceof SpanContext) t.equal(context.toString(), '00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01') t.end() }))
test('#inject(context, http, {})', setup(function (t) { const tracer = new Tracer(getAgent()) const span = tracer.startSpan('foo') const carrier = {} tracer.inject(span.context(), opentracing.FORMAT_HTTP_HEADERS, carrier) t.equal(carrier['elastic-apm-traceparent'], span.context().toString()) t.end() }))