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

refactor: rename HttpText to TextMap propagator #1458

Merged
merged 5 commits into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions packages/opentelemetry-api/src/api/global-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { ContextManager } from '@opentelemetry/context-base';
import { HttpTextPropagator } from '../context/propagation/HttpTextPropagator';
import { TextMapPropagator } from '../context/propagation/TextMapPropagator';
dengliming marked this conversation as resolved.
Show resolved Hide resolved
import { MeterProvider } from '../metrics/MeterProvider';
import { TracerProvider } from '../trace/tracer_provider';
import { _globalThis } from '../platform';
Expand All @@ -35,7 +35,7 @@ type Get<T> = (version: number) => T;
type OtelGlobal = Partial<{
[GLOBAL_CONTEXT_MANAGER_API_KEY]: Get<ContextManager>;
[GLOBAL_METRICS_API_KEY]: Get<MeterProvider>;
[GLOBAL_PROPAGATION_API_KEY]: Get<HttpTextPropagator>;
[GLOBAL_PROPAGATION_API_KEY]: Get<TextMapPropagator>;
[GLOBAL_TRACE_API_KEY]: Get<TracerProvider>;
}>;

Expand Down
14 changes: 6 additions & 8 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/context-base';
import { defaultGetter, GetterFunction } from '../context/propagation/getter';
import { HttpTextPropagator } from '../context/propagation/HttpTextPropagator';
import { NOOP_HTTP_TEXT_PROPAGATOR } from '../context/propagation/NoopHttpTextPropagator';
import { TextMapPropagator } from '../context/propagation/TextMapPropagator';
import { NOOP_TEXT_MAP_PROPAGATOR } from '../context/propagation/NoopTextMapPropagator';
import { defaultSetter, SetterFunction } from '../context/propagation/setter';
import { ContextAPI } from './context';
import {
Expand Down Expand Up @@ -50,9 +50,7 @@ export class PropagationAPI {
/**
* Set the current propagator. Returns the initialized propagator
*/
public setGlobalPropagator(
propagator: HttpTextPropagator
): HttpTextPropagator {
public setGlobalPropagator(propagator: TextMapPropagator): TextMapPropagator {
if (_global[GLOBAL_PROPAGATION_API_KEY]) {
// global propagator has already been set
return this._getGlobalPropagator();
Expand All @@ -61,7 +59,7 @@ export class PropagationAPI {
_global[GLOBAL_PROPAGATION_API_KEY] = makeGetter(
API_BACKWARDS_COMPATIBILITY_VERSION,
propagator,
NOOP_HTTP_TEXT_PROPAGATOR
NOOP_TEXT_MAP_PROPAGATOR
);

return propagator;
Expand Down Expand Up @@ -102,11 +100,11 @@ export class PropagationAPI {
delete _global[GLOBAL_PROPAGATION_API_KEY];
}

private _getGlobalPropagator(): HttpTextPropagator {
private _getGlobalPropagator(): TextMapPropagator {
return (
_global[GLOBAL_PROPAGATION_API_KEY]?.(
API_BACKWARDS_COMPATIBILITY_VERSION
) ?? NOOP_HTTP_TEXT_PROPAGATOR
) ?? NOOP_TEXT_MAP_PROPAGATOR
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/

import { Context } from '@opentelemetry/context-base';
import { HttpTextPropagator } from './HttpTextPropagator';
import { TextMapPropagator } from './TextMapPropagator';

/**
* No-op implementations of {@link HttpTextPropagator}.
* No-op implementations of {@link TextMapPropagator}.
*/
export class NoopHttpTextPropagator implements HttpTextPropagator {
export class NoopTextMapPropagator implements TextMapPropagator {
/** 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 NoopHttpTextPropagator implements HttpTextPropagator {
}
}

export const NOOP_HTTP_TEXT_PROPAGATOR = new NoopHttpTextPropagator();
export const NOOP_TEXT_MAP_PROPAGATOR = new NoopTextMapPropagator();
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ import { GetterFunction } from './getter';
* usually implemented via library-specific request interceptors, where the
* client-side injects values and the server-side extracts them.
*/
export interface HttpTextPropagator {
export interface TextMapPropagator {
/**
* Injects values from a given `Context` into a carrier.
*
* OpenTelemetry defines a common set of format values (HttpTextPropagator),
* OpenTelemetry defines a common set of format values (TextMapPropagator),
* and each has an expected `carrier` type.
*
* @param context the Context from which to extract values to transmit over
Expand Down
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/HttpTextPropagator';
export * from './context/propagation/NoopHttpTextPropagator';
export * from './context/propagation/TextMapPropagator';
export * from './context/propagation/NoopTextMapPropagator';
export * from './context/propagation/setter';
export * from './correlation_context/CorrelationContext';
export * from './correlation_context/EntryValue';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import {
Context,
GetterFunction,
HttpTextPropagator,
TextMapPropagator,
SetterFunction,
TraceFlags,
} from '@opentelemetry/api';
Expand Down Expand Up @@ -120,7 +120,7 @@ function getTraceFlags(
* Propagator for the B3 HTTP header format.
* Based on: https://github.com/openzipkin/b3-propagation
*/
export class B3Propagator implements HttpTextPropagator {
export class B3Propagator implements TextMapPropagator {
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,
HttpTextPropagator,
TextMapPropagator,
SetterFunction,
SpanContext,
TraceFlags,
Expand Down Expand Up @@ -83,7 +83,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 HttpTextPropagator {
export class HttpTraceContext implements TextMapPropagator {
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,
HttpTextPropagator,
TextMapPropagator,
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 HttpTextPropagator {
private readonly _propagators: HttpTextPropagator[];
export class CompositePropagator implements TextMapPropagator {
private readonly _propagators: TextMapPropagator[];
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 { HttpTextPropagator, Logger } from '@opentelemetry/api';
import { TextMapPropagator, 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?: HttpTextPropagator[];
propagators?: TextMapPropagator[];

/** Instance of logger */
logger?: Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
Context,
CorrelationContext,
GetterFunction,
HttpTextPropagator,
TextMapPropagator,
SetterFunction,
} from '@opentelemetry/api';
import {
Expand Down Expand Up @@ -49,7 +49,7 @@ type KeyPair = {
* Based on the Correlation Context specification:
* https://w3c.github.io/correlation-context/
*/
export class HttpCorrelationContext implements HttpTextPropagator {
export class HttpCorrelationContext implements TextMapPropagator {
inject(context: Context, carrier: unknown, setter: SetterFunction) {
const correlationContext = getCorrelationContext(context);
if (!correlationContext) return;
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-core/test/context/composite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import {
defaultGetter,
defaultSetter,
HttpTextPropagator,
TextMapPropagator,
SpanContext,
} from '@opentelemetry/api';
import { Context } from '@opentelemetry/context-base';
Expand Down Expand Up @@ -154,7 +154,7 @@ describe('Composite Propagator', () => {
});
});

class ThrowingPropagator implements HttpTextPropagator {
class ThrowingPropagator implements TextMapPropagator {
inject(context: Context, carrier: unknown) {
throw new Error('this propagator throws');
}
Expand Down
6 changes: 3 additions & 3 deletions packages/opentelemetry-node/test/registration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import {
context,
NoopHttpTextPropagator,
NoopTextMapPropagator,
propagation,
trace,
} from '@opentelemetry/api';
Expand Down Expand Up @@ -50,7 +50,7 @@ describe('API registration', () => {
const tracerProvider = new NodeTracerProvider();

const contextManager = new NoopContextManager();
const propagator = new NoopHttpTextPropagator();
const propagator = new NoopTextMapPropagator();

tracerProvider.register({
contextManager,
Expand Down Expand Up @@ -84,7 +84,7 @@ describe('API registration', () => {
});

assert.ok(
propagation['_getGlobalPropagator']() instanceof NoopHttpTextPropagator
propagation['_getGlobalPropagator']() instanceof NoopTextMapPropagator
);

assert.ok(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Context, HttpTextPropagator, TraceFlags } from '@opentelemetry/api';
import { Context, TextMapPropagator, TraceFlags } from '@opentelemetry/api';
import {
getParentSpanContext,
setExtractedSpanContext,
} from '@opentelemetry/core';
import * as http from 'http';

export class DummyPropagation implements HttpTextPropagator {
export class DummyPropagation implements TextMapPropagator {
static TRACE_CONTEXT_KEY = 'x-dummy-trace-id';
static SPAN_CONTEXT_KEY = 'x-dummy-span-id';
extract(context: Context, carrier: http.OutgoingHttpHeaders) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Context, HttpTextPropagator, TraceFlags } from '@opentelemetry/api';
import { Context, TextMapPropagator, TraceFlags } from '@opentelemetry/api';
import {
setExtractedSpanContext,
getParentSpanContext,
} from '@opentelemetry/core';
import * as http from 'http';

export class DummyPropagation implements HttpTextPropagator {
export class DummyPropagation implements TextMapPropagator {
static TRACE_CONTEXT_KEY = 'x-dummy-trace-id';
static SPAN_CONTEXT_KEY = 'x-dummy-span-id';
extract(context: Context, carrier: http.OutgoingHttpHeaders) {
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-sdk-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Detect resources automatically from the environment using the default resource d

Use a custom context manager. Default: [AsyncHooksContextManager](../opentelemetry-context-async-hooks/README.md)

### httpTextPropagator
### textMapPropagator

Use a custom propagator. Default: [CompositePropagator](../opentelemetry-core/src/context/propagation/composite.ts) using [W3C Trace Context](../opentelemetry-core/README.md#httptracecontext-propagator) and [Correlation Context](../opentelemetry-core/README.md#correlation-context-propagator)

Expand Down
12 changes: 6 additions & 6 deletions packages/opentelemetry-sdk-node/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { HttpTextPropagator, metrics } from '@opentelemetry/api';
import { TextMapPropagator, metrics } from '@opentelemetry/api';
import { ContextManager } from '@opentelemetry/context-base';
import { MeterConfig, MeterProvider } from '@opentelemetry/metrics';
import { NodeTracerConfig, NodeTracerProvider } from '@opentelemetry/node';
Expand All @@ -35,7 +35,7 @@ export class NodeSDK {
tracerConfig: NodeTracerConfig;
spanProcessor: SpanProcessor;
contextManager?: ContextManager;
httpTextPropagator?: HttpTextPropagator;
textMapPropagator?: TextMapPropagator;
};
private _meterProviderConfig?: MeterConfig;

Expand Down Expand Up @@ -78,7 +78,7 @@ export class NodeSDK {
tracerProviderConfig,
spanProcessor,
configuration.contextManager,
configuration.httpTextPropagator
configuration.textMapPropagator
);
}

Expand Down Expand Up @@ -110,13 +110,13 @@ export class NodeSDK {
tracerConfig: NodeTracerConfig,
spanProcessor: SpanProcessor,
contextManager?: ContextManager,
httpTextPropagator?: HttpTextPropagator
textMapPropagator?: TextMapPropagator
) {
this._tracerProviderConfig = {
tracerConfig,
spanProcessor,
contextManager,
httpTextPropagator,
textMapPropagator,
};
}

Expand Down Expand Up @@ -157,7 +157,7 @@ export class NodeSDK {
tracerProvider.addSpanProcessor(this._tracerProviderConfig.spanProcessor);
tracerProvider.register({
contextManager: this._tracerProviderConfig.contextManager,
propagator: this._tracerProviderConfig.httpTextPropagator,
propagator: this._tracerProviderConfig.textMapPropagator,
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-sdk-node/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface NodeSDKConfiguration {
autoDetectResources: boolean;
contextManager: ContextManager;
defaultAttributes: api.Attributes;
httpTextPropagator: api.HttpTextPropagator;
textMapPropagator: api.TextMapPropagator;
logger: api.Logger;
logLevel: core.LogLevel;
metricBatcher: metrics.Batcher;
Expand Down
6 changes: 3 additions & 3 deletions packages/opentelemetry-sdk-node/test/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as nock from 'nock';
import {
context,
metrics,
NoopHttpTextPropagator,
NoopTextMapPropagator,
NoopMeterProvider,
NoopTracerProvider,
propagation,
Expand Down Expand Up @@ -102,7 +102,7 @@ describe('Node SDK', () => {

assert.ok(context['_getContextManager']() instanceof NoopContextManager);
assert.ok(
propagation['_getGlobalPropagator']() instanceof NoopHttpTextPropagator
propagation['_getGlobalPropagator']() instanceof NoopTextMapPropagator
);

assert.ok(trace.getTracerProvider() instanceof NoopTracerProvider);
Expand Down Expand Up @@ -162,7 +162,7 @@ describe('Node SDK', () => {

assert.ok(context['_getContextManager']() instanceof NoopContextManager);
assert.ok(
propagation['_getGlobalPropagator']() instanceof NoopHttpTextPropagator
propagation['_getGlobalPropagator']() instanceof NoopTextMapPropagator
);

assert.ok(trace.getTracerProvider() instanceof NoopTracerProvider);
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-tracing/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { HttpTextPropagator, Logger, Sampler } from '@opentelemetry/api';
import { TextMapPropagator, Logger, Sampler } from '@opentelemetry/api';
import { LogLevel, IdGenerator } from '@opentelemetry/core';

import { ContextManager } from '@opentelemetry/context-base';
Expand Down Expand Up @@ -60,7 +60,7 @@ export interface TracerConfig {
*/
export interface SDKRegistrationConfig {
/** Propagator to register as the global propagator */
propagator?: HttpTextPropagator | null;
propagator?: TextMapPropagator | null;

/** Context manager to register as the global context manager */
contextManager?: ContextManager | null;
Expand Down
Loading