Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename formatter to propagator #851

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Beginning BasicTracerProvider with BatchSpanProcessor Benchmark...
#startSpan with 100 attributes x 3,459 ops/sec ±4.56% (20 runs sampled)


Beginning B3Format Benchmark...
Beginning B3Propagator Benchmark...
2 tests completed.

#Inject x 5,086,366 ops/sec ±3.18% (100 runs sampled)
Expand Down
4 changes: 2 additions & 2 deletions benchmark/propagator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const opentelemetry = require('../packages/opentelemetry-core');

const setups = [
{
name: 'B3Format',
propagator: new opentelemetry.B3Format(),
name: 'B3Propagator',
propagator: new opentelemetry.B3Propagator(),
injectCarrier: {},
extractCarrier: {
'x-b3-traceid': 'd4cda95b652f4a1592b449d5929fda1b',
Expand Down
4 changes: 2 additions & 2 deletions examples/tracer-web/examples/user-interaction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { XMLHttpRequestPlugin } from '@opentelemetry/plugin-xml-http-request';
import { UserInteractionPlugin } from '@opentelemetry/plugin-user-interaction';
import { ZoneScopeManager } from '@opentelemetry/scope-zone';
import { CollectorExporter } from '@opentelemetry/exporter-collector';
import { B3Format } from '@opentelemetry/core';
import { B3Propagator } from '@opentelemetry/core';

const providerWithZone = new WebTracerProvider({
httpTextFormat: new B3Format(),
HttpTextPropagator: new B3Propagator(),
scopeManager: new ZoneScopeManager(),
plugins: [
new UserInteractionPlugin(),
Expand Down
4 changes: 2 additions & 2 deletions examples/tracer-web/examples/xml-http-request/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { WebTracerProvider } from '@opentelemetry/web';
import { XMLHttpRequestPlugin } from '@opentelemetry/plugin-xml-http-request';
import { ZoneScopeManager } from '@opentelemetry/scope-zone';
import { CollectorExporter } from '@opentelemetry/exporter-collector';
import { B3Format } from '@opentelemetry/core';
import { B3Propagator } from '@opentelemetry/core';

const providerWithZone = new WebTracerProvider({
httpTextFormat: new B3Format(),
HttpTextPropagator: new B3Propagator(),
scopeManager: new ZoneScopeManager(),
plugins: [
new XMLHttpRequestPlugin({
Expand Down
10 changes: 6 additions & 4 deletions packages/opentelemetry-api/src/api/propagation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import { Context } from '@opentelemetry/scope-base';
import { defaultGetter, GetterFunction } from '../context/propagation/getter';
import { HttpTextFormat } from '../context/propagation/HttpTextFormat';
import { NOOP_HTTP_TEXT_FORMAT } from '../context/propagation/NoopHttpTextFormat';
import { HttpTextPropagator } from '../context/propagation/HttpTextPropagator';
import { NOOP_HTTP_TEXT_PROPAGATOR } from '../context/propagation/NoopHttpTextPropagator';
import { defaultSetter, SetterFunction } from '../context/propagation/setter';
import { ContextAPI } from './context';

Expand All @@ -28,7 +28,7 @@ const contextApi = ContextAPI.getInstance();
*/
export class PropagationAPI {
private static _instance?: PropagationAPI;
private _propagator: HttpTextFormat = NOOP_HTTP_TEXT_FORMAT;
private _propagator: HttpTextPropagator = NOOP_HTTP_TEXT_PROPAGATOR;

/** Empty private constructor prevents end users from constructing a new instance of the API */
private constructor() {}
Expand All @@ -45,7 +45,9 @@ export class PropagationAPI {
/**
* Set the current propagator. Returns the initialized propagator
*/
public setGlobalPropagator(propagator: HttpTextFormat): HttpTextFormat {
public setGlobalPropagator(
propagator: HttpTextPropagator
): HttpTextPropagator {
this._propagator = propagator;
return propagator;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import { GetterFunction } from './getter';
* The carrier of propagated data on both the client (injector) and server
* (extractor) side is usually an object such as http headers.
*/
export interface HttpTextFormat {
export interface HttpTextPropagator {
/**
* Injects values from a given {@link Context} into a carrier.
*
* OpenTelemetry defines a common set of format values (HTTPTextFormat), and
* OpenTelemetry defines a common set of format values (HttpTextPropagator), and
* each has an expected `carrier` type.
*
* @param context the Context from which to extract values to transmit over
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/

import { Context } from '@opentelemetry/scope-base';
import { HttpTextFormat } from './HttpTextFormat';
import { HttpTextPropagator } from './HttpTextPropagator';

/**
* No-op implementations of {@link HttpTextFormat}.
* No-op implementations of {@link HttpTextPropagator}.
*/
export class NoopHttpTextFormat implements HttpTextFormat {
export class NoopHttpTextPropagator implements HttpTextPropagator {
/** Noop inject function does nothing */
inject(context: Context, carrier: unknown, setter: Function): void {}
/** Noop extract function does nothing and returns the input context */
Expand All @@ -29,4 +29,4 @@ export class NoopHttpTextFormat implements HttpTextFormat {
}
}

export const NOOP_HTTP_TEXT_FORMAT = new NoopHttpTextFormat();
export const NOOP_HTTP_TEXT_PROPAGATOR = new NoopHttpTextPropagator();
4 changes: 2 additions & 2 deletions packages/opentelemetry-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
export * from './common/Logger';
export * from './common/Time';
export * from './context/propagation/getter';
export * from './context/propagation/HttpTextFormat';
export * from './context/propagation/NoopHttpTextFormat';
export * from './context/propagation/HttpTextPropagator';
export * from './context/propagation/NoopHttpTextPropagator';
export * from './context/propagation/setter';
export * from './correlation_context/CorrelationContext';
export * from './correlation_context/EntryValue';
Expand Down
8 changes: 1 addition & 7 deletions packages/opentelemetry-api/src/trace/NoopTracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
* limitations under the License.
*/

import { HttpTextFormat, Span, SpanOptions, Tracer } from '..';
import { NOOP_HTTP_TEXT_FORMAT } from '../context/propagation/NoopHttpTextFormat';
import { Span, SpanOptions, Tracer } from '..';
import { NOOP_SPAN } from './NoopSpan';

/**
Expand All @@ -41,11 +40,6 @@ export class NoopTracer implements Tracer {
bind<T>(target: T, span?: Span): T {
return target;
}

// By default does nothing
getHttpTextFormat(): HttpTextFormat {
dyladan marked this conversation as resolved.
Show resolved Hide resolved
return NOOP_HTTP_TEXT_FORMAT;
}
}

export const NOOP_TRACER = new NoopTracer();
7 changes: 1 addition & 6 deletions packages/opentelemetry-api/test/api/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ import api, {
} from '../../src';

describe('API', () => {
const functions = [
'getCurrentSpan',
'startSpan',
'withSpan',
'getHttpTextFormat',
dyladan marked this conversation as resolved.
Show resolved Hide resolved
];
const functions = ['getCurrentSpan', 'startSpan', 'withSpan'];

it('should expose a tracer provider via getTracerProvider', () => {
const tracer = api.trace.getTracerProvider();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@
* limitations under the License.
*/

import { Context } from '@opentelemetry/scope-base';
import * as assert from 'assert';
import { NoopTracer, NOOP_SPAN, SpanKind } from '../../src';
import { defaultGetter } from '../../src/context/propagation/getter';
import { defaultSetter } from '../../src/context/propagation/setter';

describe('NoopTracer', () => {
it('should not crash', () => {
Expand All @@ -37,14 +34,6 @@ describe('NoopTracer', () => {
);

assert.deepStrictEqual(tracer.getCurrentSpan(), NOOP_SPAN);
const httpTextFormat = tracer.getHttpTextFormat();
assert.ok(httpTextFormat);

httpTextFormat.inject(Context.ROOT_CONTEXT, {}, defaultSetter);
assert.deepStrictEqual(
httpTextFormat.extract(Context.ROOT_CONTEXT, {}, defaultGetter),
Context.ROOT_CONTEXT
);
});

it('should not crash when .withSpan()', done => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import {
Context,
GetterFunction,
HttpTextFormat,
HttpTextPropagator,
SetterFunction,
TraceFlags,
} from '@opentelemetry/api';
Expand All @@ -42,7 +42,7 @@ function isValidSpanId(spanId: string): boolean {
* Propagator for the B3 HTTP header format.
* Based on: https://github.com/openzipkin/b3-propagation
*/
export class B3Format implements HttpTextFormat {
export class B3Propagator implements HttpTextPropagator {
inject(context: Context, carrier: unknown, setter: SetterFunction) {
const spanContext = getParentSpanContext(context);
if (!spanContext) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import {
Context,
GetterFunction,
HttpTextFormat,
HttpTextPropagator,
SetterFunction,
SpanContext,
TraceFlags,
Expand Down Expand Up @@ -63,7 +63,7 @@ export function parseTraceParent(traceParent: string): SpanContext | null {
* Based on the Trace Context specification:
* https://www.w3.org/TR/trace-context/
*/
export class HttpTraceContext implements HttpTextFormat {
export class HttpTraceContext implements HttpTextPropagator {
inject(context: Context, carrier: unknown, setter: SetterFunction) {
const spanContext = getParentSpanContext(context);
if (!spanContext) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
import {
Context,
GetterFunction,
HttpTextFormat,
HttpTextPropagator,
Logger,
SetterFunction,
} from '@opentelemetry/api';
import { NoopLogger } from '../../common/NoopLogger';
import { CompositePropagatorConfig } from './types';

/** Combines multiple propagators into a single propagator. */
export class CompositePropagator implements HttpTextFormat {
private readonly _propagators: HttpTextFormat[];
export class CompositePropagator implements HttpTextPropagator {
private readonly _propagators: HttpTextPropagator[];
private readonly _logger: Logger;

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-core/src/context/propagation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { HttpTextFormat, Logger } from '@opentelemetry/api';
import { HttpTextPropagator, Logger } from '@opentelemetry/api';

/** Configuration object for composite propagator */
export interface CompositePropagatorConfig {
Expand All @@ -23,7 +23,7 @@ export interface CompositePropagatorConfig {
* list order. If a propagator later in the list writes the same context
* key as a propagator earlier in the list, the later on will "win".
*/
propagators?: HttpTextFormat[];
propagators?: HttpTextPropagator[];

/** Instance of logger */
logger?: Logger;
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export * from './common/time';
export * from './common/types';
export * from './version';
export * from './context/context';
export * from './context/propagation/B3Format';
export * from './context/propagation/B3Propagator';
export * from './context/propagation/composite';
export * from './context/propagation/HttpTraceContext';
export * from './context/propagation/types';
Expand Down
Loading