From f7df52da3663ab47f2d95096bed7bdaf03a35b2e Mon Sep 17 00:00:00 2001 From: vmarchaud Date: Sat, 19 Sep 2020 15:26:15 +0200 Subject: [PATCH 1/2] feat(api): propagate spanContext only using API #1456 --- benchmark/propagator.js | 2 +- .../src/context/context.ts | 12 ++---- packages/opentelemetry-api/src/index.ts | 1 + .../opentelemetry-api/src/trace/NoopTracer.ts | 31 ++++++++++++-- .../test/context/context.test.ts | 22 ++++------ .../noop-implementations/noop-tracer.test.ts | 40 ++++++++++++++++++- .../src/context/propagation/B3Propagator.ts | 6 ++- .../context/propagation/HttpTraceContext.ts | 3 +- packages/opentelemetry-core/src/index.ts | 1 - .../test/context/B3Propagator.test.ts | 6 +-- .../test/context/HttpTraceContext.test.ts | 6 +-- .../test/context/composite.test.ts | 6 +-- .../test/NodeTracerProvider.test.ts | 3 +- .../opentelemetry-plugin-http/src/http.ts | 2 +- .../test/utils/DummyPropagation.ts | 6 ++- .../test/utils/DummyPropagation.ts | 6 ++- .../src/shim.ts | 11 ++--- packages/opentelemetry-tracing/src/Tracer.ts | 14 +++---- .../src/export/BatchSpanProcessor.ts | 3 +- .../src/export/SimpleSpanProcessor.ts | 3 +- .../test/BasicTracerProvider.test.ts | 4 +- .../opentelemetry-tracing/test/Tracer.test.ts | 2 +- .../test/export/InMemorySpanExporter.test.ts | 4 +- 23 files changed, 117 insertions(+), 77 deletions(-) rename packages/{opentelemetry-core => opentelemetry-api}/src/context/context.ts (94%) rename packages/{opentelemetry-core => opentelemetry-api}/test/context/context.test.ts (82%) diff --git a/benchmark/propagator.js b/benchmark/propagator.js index 33e4c5865a3..f40d4221b39 100644 --- a/benchmark/propagator.js +++ b/benchmark/propagator.js @@ -31,7 +31,7 @@ for (const setup of setups) { const suite = benchmark(100) .add('#Inject', function () { propagator.inject( - opentelemetry.setExtractedSpanContext(Context.ROOT_CONTEXT, { + api.setExtractedSpanContext(Context.ROOT_CONTEXT, { traceId: 'd4cda95b652f4a1592b449d5929fda1b', spanId: '6e0c63257de34c92' }), setup.injectCarrier, api.defaultSetter); diff --git a/packages/opentelemetry-core/src/context/context.ts b/packages/opentelemetry-api/src/context/context.ts similarity index 94% rename from packages/opentelemetry-core/src/context/context.ts rename to packages/opentelemetry-api/src/context/context.ts index 1d06ba8dcdf..2b3e22a2c73 100644 --- a/packages/opentelemetry-core/src/context/context.ts +++ b/packages/opentelemetry-api/src/context/context.ts @@ -14,17 +14,13 @@ * limitations under the License. */ -import { - Span, - SpanContext, - createContextKey, - Context, -} from '@opentelemetry/api'; +import { Span, SpanContext } from '../'; +import { Context, createContextKey } from '@opentelemetry/context-base'; /** * Active span key */ -export const ACTIVE_SPAN_KEY = createContextKey( +const ACTIVE_SPAN_KEY = createContextKey( 'OpenTelemetry Context Key ACTIVE_SPAN' ); const EXTRACTED_SPAN_CONTEXT_KEY = createContextKey( @@ -34,7 +30,7 @@ const EXTRACTED_SPAN_CONTEXT_KEY = createContextKey( * Shared key for indicating if instrumentation should be suppressed beyond * this current scope. */ -export const SUPPRESS_INSTRUMENTATION_KEY = createContextKey( +const SUPPRESS_INSTRUMENTATION_KEY = createContextKey( 'OpenTelemetry Context Key SUPPRESS_INSTRUMENTATION' ); diff --git a/packages/opentelemetry-api/src/index.ts b/packages/opentelemetry-api/src/index.ts index d7e99d2efdc..a5432436bd0 100644 --- a/packages/opentelemetry-api/src/index.ts +++ b/packages/opentelemetry-api/src/index.ts @@ -17,6 +17,7 @@ export * from './common/Exception'; export * from './common/Logger'; export * from './common/Time'; +export * from './context/context'; export * from './context/propagation/getter'; export * from './context/propagation/TextMapPropagator'; export * from './context/propagation/NoopTextMapPropagator'; diff --git a/packages/opentelemetry-api/src/trace/NoopTracer.ts b/packages/opentelemetry-api/src/trace/NoopTracer.ts index 2fdc4dc3104..877a405cbb7 100644 --- a/packages/opentelemetry-api/src/trace/NoopTracer.ts +++ b/packages/opentelemetry-api/src/trace/NoopTracer.ts @@ -14,8 +14,11 @@ * limitations under the License. */ -import { Span, SpanOptions, Tracer } from '..'; -import { NOOP_SPAN } from './NoopSpan'; +import { Span, SpanOptions, Tracer, SpanContext } from '..'; +import { Context } from '@opentelemetry/context-base'; +import { NoopSpan, NOOP_SPAN } from './NoopSpan'; +import { isSpanContextValid } from './spancontext-utils'; +import { getExtractedSpanContext } from '../context/context'; /** * No-op implementations of {@link Tracer}. @@ -26,8 +29,19 @@ export class NoopTracer implements Tracer { } // startSpan starts a noop span. - startSpan(name: string, options?: SpanOptions): Span { - return NOOP_SPAN; + startSpan(name: string, options?: SpanOptions, context?: Context): Span { + const parent = options?.parent; + const parentFromContext = context && getExtractedSpanContext(context); + if (isSpanContext(parent) && isSpanContextValid(parent)) { + return new NoopSpan(parent); + } else if ( + isSpanContext(parentFromContext) && + isSpanContextValid(parentFromContext) + ) { + return new NoopSpan(parentFromContext); + } else { + return NOOP_SPAN; + } } withSpan ReturnType>( @@ -42,4 +56,13 @@ export class NoopTracer implements Tracer { } } +function isSpanContext(spanContext: any): spanContext is SpanContext { + return ( + typeof spanContext === 'object' && + typeof spanContext['spanId'] === 'string' && + typeof spanContext['traceId'] === 'string' && + typeof spanContext['traceFlags'] === 'number' + ); +} + export const NOOP_TRACER = new NoopTracer(); diff --git a/packages/opentelemetry-core/test/context/context.test.ts b/packages/opentelemetry-api/test/context/context.test.ts similarity index 82% rename from packages/opentelemetry-core/test/context/context.test.ts rename to packages/opentelemetry-api/test/context/context.test.ts index 5abb1d785c2..e07526b7c02 100644 --- a/packages/opentelemetry-core/test/context/context.test.ts +++ b/packages/opentelemetry-api/test/context/context.test.ts @@ -15,37 +15,29 @@ */ import * as assert from 'assert'; - +import { ROOT_CONTEXT, createContextKey } from '@opentelemetry/context-base' import { - SUPPRESS_INSTRUMENTATION_KEY, suppressInstrumentation, unsuppressInstrumentation, isInstrumentationSuppressed, } from '../../src/context/context'; -import { ROOT_CONTEXT } from '@opentelemetry/api'; + +const SUPPRESS_INSTRUMENTATION_KEY = createContextKey( + 'OpenTelemetry Context Key SUPPRESS_INSTRUMENTATION' +); describe('Context Helpers', () => { describe('suppressInstrumentation', () => { it('should set suppress to true', () => { - const expectedValue = true; const context = suppressInstrumentation(ROOT_CONTEXT); - - const value = context.getValue(SUPPRESS_INSTRUMENTATION_KEY); - const boolValue = value as boolean; - - assert.equal(boolValue, expectedValue); + assert.deepStrictEqual(isInstrumentationSuppressed(context), true); }); }); describe('unsuppressInstrumentation', () => { it('should set suppress to false', () => { - const expectedValue = false; const context = unsuppressInstrumentation(ROOT_CONTEXT); - - const value = context.getValue(SUPPRESS_INSTRUMENTATION_KEY); - const boolValue = value as boolean; - - assert.equal(boolValue, expectedValue); + assert.deepStrictEqual(isInstrumentationSuppressed(context), false); }); }); diff --git a/packages/opentelemetry-api/test/noop-implementations/noop-tracer.test.ts b/packages/opentelemetry-api/test/noop-implementations/noop-tracer.test.ts index 62ed24bb8ee..3f68c8a14c9 100644 --- a/packages/opentelemetry-api/test/noop-implementations/noop-tracer.test.ts +++ b/packages/opentelemetry-api/test/noop-implementations/noop-tracer.test.ts @@ -15,7 +15,15 @@ */ import * as assert from 'assert'; -import { NoopTracer, NOOP_SPAN, SpanKind } from '../../src'; +import { + NoopTracer, + NOOP_SPAN, + SpanContext, + SpanKind, + TraceFlags, + context, + setExtractedSpanContext, +} from '../../src'; describe('NoopTracer', () => { it('should not crash', () => { @@ -51,4 +59,34 @@ describe('NoopTracer', () => { const patchedFn = tracer.bind(fn, NOOP_SPAN); return patchedFn(); }); + + it('should propagate valid spanContext on the span (from parent)', () => { + const tracer = new NoopTracer(); + const parent: SpanContext = { + traceId: 'd4cda95b652f4a1592b449d5929fda1b', + spanId: '6e0c63257de34c92', + traceFlags: TraceFlags.NONE, + }; + const span = tracer.startSpan('test-1', { parent }); + assert(span.context().traceId === parent.traceId); + assert(span.context().spanId === parent.spanId); + assert(span.context().traceFlags === parent.traceFlags); + }); + + it('should propagate valid spanContext on the span (from context)', () => { + const tracer = new NoopTracer(); + const parent: SpanContext = { + traceId: 'd4cda95b652f4a1592b449dd92ffda3b', + spanId: '6e0c63ffe4e34c42', + traceFlags: TraceFlags.NONE, + }; + const span = tracer.startSpan( + 'test-1', + {}, + setExtractedSpanContext(context.active(), parent) + ); + assert(span.context().traceId === parent.traceId); + assert(span.context().spanId === parent.spanId); + assert(span.context().traceFlags === parent.traceFlags); + }); }); diff --git a/packages/opentelemetry-core/src/context/propagation/B3Propagator.ts b/packages/opentelemetry-core/src/context/propagation/B3Propagator.ts index d4b11894a49..c3b55a3eb0b 100644 --- a/packages/opentelemetry-core/src/context/propagation/B3Propagator.ts +++ b/packages/opentelemetry-core/src/context/propagation/B3Propagator.ts @@ -20,9 +20,11 @@ import { TextMapPropagator, SetterFunction, TraceFlags, - createContextKey, + getParentSpanContext, + setExtractedSpanContext, } from '@opentelemetry/api'; -import { getParentSpanContext, setExtractedSpanContext } from '../context'; + +import { createContextKey } from '@opentelemetry/context-base' export const X_B3_TRACE_ID = 'x-b3-traceid'; export const X_B3_SPAN_ID = 'x-b3-spanid'; diff --git a/packages/opentelemetry-core/src/context/propagation/HttpTraceContext.ts b/packages/opentelemetry-core/src/context/propagation/HttpTraceContext.ts index 2ba75607d62..3d196d803b4 100644 --- a/packages/opentelemetry-core/src/context/propagation/HttpTraceContext.ts +++ b/packages/opentelemetry-core/src/context/propagation/HttpTraceContext.ts @@ -21,9 +21,10 @@ import { SetterFunction, SpanContext, TraceFlags, + getParentSpanContext, + setExtractedSpanContext, } from '@opentelemetry/api'; import { TraceState } from '../../trace/TraceState'; -import { getParentSpanContext, setExtractedSpanContext } from '../context'; export const TRACE_PARENT_HEADER = 'traceparent'; export const TRACE_STATE_HEADER = 'tracestate'; diff --git a/packages/opentelemetry-core/src/index.ts b/packages/opentelemetry-core/src/index.ts index b72be1e4834..4746653672e 100644 --- a/packages/opentelemetry-core/src/index.ts +++ b/packages/opentelemetry-core/src/index.ts @@ -21,7 +21,6 @@ export * from './common/time'; export * from './common/types'; export * from './ExportResult'; export * from './version'; -export * from './context/context'; export * from './context/propagation/B3Propagator'; export * from './context/propagation/composite'; export * from './context/propagation/HttpTraceContext'; diff --git a/packages/opentelemetry-core/test/context/B3Propagator.test.ts b/packages/opentelemetry-core/test/context/B3Propagator.test.ts index fc4dcb67bb5..6baf2076f65 100644 --- a/packages/opentelemetry-core/test/context/B3Propagator.test.ts +++ b/packages/opentelemetry-core/test/context/B3Propagator.test.ts @@ -19,13 +19,11 @@ import { defaultSetter, SpanContext, TraceFlags, + getExtractedSpanContext, + setExtractedSpanContext, } from '@opentelemetry/api'; import { ROOT_CONTEXT } from '@opentelemetry/context-base'; import * as assert from 'assert'; -import { - getExtractedSpanContext, - setExtractedSpanContext, -} from '../../src/context/context'; import { B3Propagator, X_B3_FLAGS, diff --git a/packages/opentelemetry-core/test/context/HttpTraceContext.test.ts b/packages/opentelemetry-core/test/context/HttpTraceContext.test.ts index 05fe343f1e1..c8ad71cb12a 100644 --- a/packages/opentelemetry-core/test/context/HttpTraceContext.test.ts +++ b/packages/opentelemetry-core/test/context/HttpTraceContext.test.ts @@ -19,13 +19,11 @@ import { defaultSetter, SpanContext, TraceFlags, + getExtractedSpanContext, + setExtractedSpanContext, } from '@opentelemetry/api'; import { ROOT_CONTEXT } from '@opentelemetry/context-base'; import * as assert from 'assert'; -import { - getExtractedSpanContext, - setExtractedSpanContext, -} from '../../src/context/context'; import { HttpTraceContext, TRACE_PARENT_HEADER, diff --git a/packages/opentelemetry-core/test/context/composite.test.ts b/packages/opentelemetry-core/test/context/composite.test.ts index 1b1bb24196f..0291c532505 100644 --- a/packages/opentelemetry-core/test/context/composite.test.ts +++ b/packages/opentelemetry-core/test/context/composite.test.ts @@ -19,6 +19,8 @@ import { defaultSetter, TextMapPropagator, SpanContext, + getExtractedSpanContext, + setExtractedSpanContext, } from '@opentelemetry/api'; import { Context, ROOT_CONTEXT } from '@opentelemetry/context-base'; import * as assert from 'assert'; @@ -27,10 +29,6 @@ import { HttpTraceContext, RandomIdGenerator, } from '../../src'; -import { - getExtractedSpanContext, - setExtractedSpanContext, -} from '../../src/context/context'; import { B3Propagator, X_B3_SAMPLED, diff --git a/packages/opentelemetry-node/test/NodeTracerProvider.test.ts b/packages/opentelemetry-node/test/NodeTracerProvider.test.ts index d1b00006b13..debbca3dcec 100644 --- a/packages/opentelemetry-node/test/NodeTracerProvider.test.ts +++ b/packages/opentelemetry-node/test/NodeTracerProvider.test.ts @@ -14,13 +14,12 @@ * limitations under the License. */ -import { context, TraceFlags } from '@opentelemetry/api'; +import { context, TraceFlags, setActiveSpan } from '@opentelemetry/api'; import { AlwaysOnSampler, AlwaysOffSampler, NoopLogger, NoRecordingSpan, - setActiveSpan, } from '@opentelemetry/core'; import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks'; import { Span } from '@opentelemetry/tracing'; diff --git a/packages/opentelemetry-plugin-http/src/http.ts b/packages/opentelemetry-plugin-http/src/http.ts index fbca014ece5..7ead39cef07 100644 --- a/packages/opentelemetry-plugin-http/src/http.ts +++ b/packages/opentelemetry-plugin-http/src/http.ts @@ -23,11 +23,11 @@ import { Status, SpanContext, TraceFlags, + getExtractedSpanContext, } from '@opentelemetry/api'; import { BasePlugin, NoRecordingSpan, - getExtractedSpanContext, } from '@opentelemetry/core'; import type { ClientRequest, diff --git a/packages/opentelemetry-plugin-http/test/utils/DummyPropagation.ts b/packages/opentelemetry-plugin-http/test/utils/DummyPropagation.ts index 0c787501a94..eaa3e5d4db4 100644 --- a/packages/opentelemetry-plugin-http/test/utils/DummyPropagation.ts +++ b/packages/opentelemetry-plugin-http/test/utils/DummyPropagation.ts @@ -13,11 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Context, TextMapPropagator, TraceFlags } from '@opentelemetry/api'; import { + Context, + TextMapPropagator, + TraceFlags, getParentSpanContext, setExtractedSpanContext, -} from '@opentelemetry/core'; +} from '@opentelemetry/api'; import * as http from 'http'; export class DummyPropagation implements TextMapPropagator { diff --git a/packages/opentelemetry-plugin-https/test/utils/DummyPropagation.ts b/packages/opentelemetry-plugin-https/test/utils/DummyPropagation.ts index 4acd3835dc4..e2f3faa2230 100644 --- a/packages/opentelemetry-plugin-https/test/utils/DummyPropagation.ts +++ b/packages/opentelemetry-plugin-https/test/utils/DummyPropagation.ts @@ -13,11 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Context, TextMapPropagator, TraceFlags } from '@opentelemetry/api'; import { + Context, + TextMapPropagator, + TraceFlags, setExtractedSpanContext, getParentSpanContext, -} from '@opentelemetry/core'; +} from '@opentelemetry/api'; import * as http from 'http'; export class DummyPropagation implements TextMapPropagator { diff --git a/packages/opentelemetry-shim-opentracing/src/shim.ts b/packages/opentelemetry-shim-opentracing/src/shim.ts index 1d2e559bbc8..a9a03bf08c1 100644 --- a/packages/opentelemetry-shim-opentracing/src/shim.ts +++ b/packages/opentelemetry-shim-opentracing/src/shim.ts @@ -16,11 +16,8 @@ import * as api from '@opentelemetry/api'; import { - getExtractedSpanContext, NoopLogger, - setExtractedSpanContext, setCorrelationContext, - setActiveSpan, getCorrelationContext, } from '@opentelemetry/core'; import * as opentracing from 'opentracing'; @@ -57,9 +54,9 @@ function translateSpanOptions( function getContextWithParent(options: opentracing.SpanOptions) { if (options.childOf) { if (options.childOf instanceof SpanShim) { - return setActiveSpan(api.context.active(), options.childOf.getSpan()); + return api.setActiveSpan(api.context.active(), options.childOf.getSpan()); } else if (options.childOf instanceof SpanContextShim) { - return setExtractedSpanContext( + return api.setExtractedSpanContext( api.context.active(), options.childOf.getSpanContext() ); @@ -181,7 +178,7 @@ export class TracerShim extends opentracing.Tracer { carrier, api.defaultSetter, setCorrelationContext( - setExtractedSpanContext(api.ROOT_CONTEXT, oTelSpanContext), + api.setExtractedSpanContext(api.ROOT_CONTEXT, oTelSpanContext), oTelSpanCorrelationContext ) ); @@ -203,7 +200,7 @@ export class TracerShim extends opentracing.Tracer { case opentracing.FORMAT_HTTP_HEADERS: case opentracing.FORMAT_TEXT_MAP: { const context: api.Context = api.propagation.extract(carrier); - const spanContext = getExtractedSpanContext(context); + const spanContext = api.getExtractedSpanContext(context); const correlationContext = getCorrelationContext(context); if (!spanContext) { diff --git a/packages/opentelemetry-tracing/src/Tracer.ts b/packages/opentelemetry-tracing/src/Tracer.ts index ec04742c060..e1a7430f42f 100644 --- a/packages/opentelemetry-tracing/src/Tracer.ts +++ b/packages/opentelemetry-tracing/src/Tracer.ts @@ -17,14 +17,10 @@ import * as api from '@opentelemetry/api'; import { ConsoleLogger, - getActiveSpan, - getParentSpanContext, InstrumentationLibrary, NoRecordingSpan, IdGenerator, RandomIdGenerator, - setActiveSpan, - isInstrumentationSuppressed, sanitizeAttributes, } from '@opentelemetry/core'; import { Resource } from '@opentelemetry/resources'; @@ -70,7 +66,7 @@ export class Tracer implements api.Tracer { options: api.SpanOptions = {}, context = api.context.active() ): api.Span { - if (isInstrumentationSuppressed(context)) { + if (api.isInstrumentationSuppressed(context)) { this.logger.debug('Instrumentation suppressed, returning Noop Span'); return api.NOOP_SPAN; } @@ -133,7 +129,7 @@ export class Tracer implements api.Tracer { getCurrentSpan(): api.Span | undefined { const ctx = api.context.active(); // Get the current Span from the context or null if none found. - return getActiveSpan(ctx); + return api.getActiveSpan(ctx); } /** @@ -144,7 +140,7 @@ export class Tracer implements api.Tracer { fn: T ): ReturnType { // Set given span to context. - return api.context.with(setActiveSpan(api.context.active(), span), fn); + return api.context.with(api.setActiveSpan(api.context.active(), span), fn); } /** @@ -153,7 +149,7 @@ export class Tracer implements api.Tracer { bind(target: T, span?: api.Span): T { return api.context.bind( target, - span ? setActiveSpan(api.context.active(), span) : api.context.active() + span ? api.setActiveSpan(api.context.active(), span) : api.context.active() ); } @@ -180,7 +176,7 @@ function getParent( ): api.SpanContext | undefined { if (options.parent === null) return undefined; if (options.parent) return getContext(options.parent); - return getParentSpanContext(context); + return api.getParentSpanContext(context); } function getContext(span: api.Span | api.SpanContext): api.SpanContext { diff --git a/packages/opentelemetry-tracing/src/export/BatchSpanProcessor.ts b/packages/opentelemetry-tracing/src/export/BatchSpanProcessor.ts index 948119966de..e3ae904d014 100644 --- a/packages/opentelemetry-tracing/src/export/BatchSpanProcessor.ts +++ b/packages/opentelemetry-tracing/src/export/BatchSpanProcessor.ts @@ -14,11 +14,10 @@ * limitations under the License. */ -import { context } from '@opentelemetry/api'; +import { context, suppressInstrumentation } from '@opentelemetry/api'; import { ExportResult, unrefTimer, - suppressInstrumentation, } from '@opentelemetry/core'; import { SpanProcessor } from '../SpanProcessor'; import { BufferConfig } from '../types'; diff --git a/packages/opentelemetry-tracing/src/export/SimpleSpanProcessor.ts b/packages/opentelemetry-tracing/src/export/SimpleSpanProcessor.ts index 286d965d37b..b0cbbe873ec 100644 --- a/packages/opentelemetry-tracing/src/export/SimpleSpanProcessor.ts +++ b/packages/opentelemetry-tracing/src/export/SimpleSpanProcessor.ts @@ -17,8 +17,7 @@ import { SpanProcessor } from '../SpanProcessor'; import { SpanExporter } from './SpanExporter'; import { ReadableSpan } from './ReadableSpan'; -import { context } from '@opentelemetry/api'; -import { suppressInstrumentation } from '@opentelemetry/core'; +import { context, suppressInstrumentation } from '@opentelemetry/api'; /** * An implementation of the {@link SpanProcessor} that converts the {@link Span} diff --git a/packages/opentelemetry-tracing/test/BasicTracerProvider.test.ts b/packages/opentelemetry-tracing/test/BasicTracerProvider.test.ts index f5e6d8def09..ac204f2770e 100644 --- a/packages/opentelemetry-tracing/test/BasicTracerProvider.test.ts +++ b/packages/opentelemetry-tracing/test/BasicTracerProvider.test.ts @@ -20,14 +20,14 @@ import { TraceFlags, ContextManager, ROOT_CONTEXT, + setActiveSpan, + setExtractedSpanContext, } from '@opentelemetry/api'; import { AlwaysOnSampler, AlwaysOffSampler, NoopLogger, NoRecordingSpan, - setActiveSpan, - setExtractedSpanContext, TraceState, } from '@opentelemetry/core'; import { Resource } from '@opentelemetry/resources'; diff --git a/packages/opentelemetry-tracing/test/Tracer.test.ts b/packages/opentelemetry-tracing/test/Tracer.test.ts index 1a2ea19b9ea..9e28fa46f89 100644 --- a/packages/opentelemetry-tracing/test/Tracer.test.ts +++ b/packages/opentelemetry-tracing/test/Tracer.test.ts @@ -22,6 +22,7 @@ import { NOOP_SPAN, TraceFlags, ROOT_CONTEXT, + suppressInstrumentation, } from '@opentelemetry/api'; import { BasicTracerProvider, Tracer, Span } from '../src'; import { @@ -29,7 +30,6 @@ import { NoopLogger, AlwaysOnSampler, AlwaysOffSampler, - suppressInstrumentation, } from '@opentelemetry/core'; describe('Tracer', () => { diff --git a/packages/opentelemetry-tracing/test/export/InMemorySpanExporter.test.ts b/packages/opentelemetry-tracing/test/export/InMemorySpanExporter.test.ts index b8c05e4a0fe..9b0a5251b45 100644 --- a/packages/opentelemetry-tracing/test/export/InMemorySpanExporter.test.ts +++ b/packages/opentelemetry-tracing/test/export/InMemorySpanExporter.test.ts @@ -20,8 +20,8 @@ import { SimpleSpanProcessor, BasicTracerProvider, } from '../../src'; -import { context } from '@opentelemetry/api'; -import { ExportResult, setActiveSpan } from '@opentelemetry/core'; +import { context, setActiveSpan } from '@opentelemetry/api'; +import { ExportResult } from '@opentelemetry/core'; describe('InMemorySpanExporter', () => { let memoryExporter: InMemorySpanExporter; From 76575d9bbcf43c3ab6eba6215606ed3d5ac8926e Mon Sep 17 00:00:00 2001 From: vmarchaud Date: Sat, 19 Sep 2020 15:58:28 +0200 Subject: [PATCH 2/2] chore: lint --- packages/opentelemetry-api/test/context/context.test.ts | 2 +- .../src/context/propagation/B3Propagator.ts | 2 +- packages/opentelemetry-plugin-http/src/http.ts | 5 +---- packages/opentelemetry-tracing/src/Tracer.ts | 4 +++- .../opentelemetry-tracing/src/export/BatchSpanProcessor.ts | 5 +---- 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/packages/opentelemetry-api/test/context/context.test.ts b/packages/opentelemetry-api/test/context/context.test.ts index e07526b7c02..5c3c50929c6 100644 --- a/packages/opentelemetry-api/test/context/context.test.ts +++ b/packages/opentelemetry-api/test/context/context.test.ts @@ -15,7 +15,7 @@ */ import * as assert from 'assert'; -import { ROOT_CONTEXT, createContextKey } from '@opentelemetry/context-base' +import { ROOT_CONTEXT, createContextKey } from '@opentelemetry/context-base'; import { suppressInstrumentation, unsuppressInstrumentation, diff --git a/packages/opentelemetry-core/src/context/propagation/B3Propagator.ts b/packages/opentelemetry-core/src/context/propagation/B3Propagator.ts index c3b55a3eb0b..af51087ca74 100644 --- a/packages/opentelemetry-core/src/context/propagation/B3Propagator.ts +++ b/packages/opentelemetry-core/src/context/propagation/B3Propagator.ts @@ -24,7 +24,7 @@ import { setExtractedSpanContext, } from '@opentelemetry/api'; -import { createContextKey } from '@opentelemetry/context-base' +import { createContextKey } from '@opentelemetry/context-base'; export const X_B3_TRACE_ID = 'x-b3-traceid'; export const X_B3_SPAN_ID = 'x-b3-spanid'; diff --git a/packages/opentelemetry-plugin-http/src/http.ts b/packages/opentelemetry-plugin-http/src/http.ts index 7ead39cef07..90cac100e19 100644 --- a/packages/opentelemetry-plugin-http/src/http.ts +++ b/packages/opentelemetry-plugin-http/src/http.ts @@ -25,10 +25,7 @@ import { TraceFlags, getExtractedSpanContext, } from '@opentelemetry/api'; -import { - BasePlugin, - NoRecordingSpan, -} from '@opentelemetry/core'; +import { BasePlugin, NoRecordingSpan } from '@opentelemetry/core'; import type { ClientRequest, IncomingMessage, diff --git a/packages/opentelemetry-tracing/src/Tracer.ts b/packages/opentelemetry-tracing/src/Tracer.ts index e1a7430f42f..b0286fc65d6 100644 --- a/packages/opentelemetry-tracing/src/Tracer.ts +++ b/packages/opentelemetry-tracing/src/Tracer.ts @@ -149,7 +149,9 @@ export class Tracer implements api.Tracer { bind(target: T, span?: api.Span): T { return api.context.bind( target, - span ? api.setActiveSpan(api.context.active(), span) : api.context.active() + span + ? api.setActiveSpan(api.context.active(), span) + : api.context.active() ); } diff --git a/packages/opentelemetry-tracing/src/export/BatchSpanProcessor.ts b/packages/opentelemetry-tracing/src/export/BatchSpanProcessor.ts index e3ae904d014..ba151c4c542 100644 --- a/packages/opentelemetry-tracing/src/export/BatchSpanProcessor.ts +++ b/packages/opentelemetry-tracing/src/export/BatchSpanProcessor.ts @@ -15,10 +15,7 @@ */ import { context, suppressInstrumentation } from '@opentelemetry/api'; -import { - ExportResult, - unrefTimer, -} from '@opentelemetry/core'; +import { ExportResult, unrefTimer } from '@opentelemetry/core'; import { SpanProcessor } from '../SpanProcessor'; import { BufferConfig } from '../types'; import { ReadableSpan } from './ReadableSpan';