From 4f672b3bbaa89a7ea8c294444ee920112e1f718c Mon Sep 17 00:00:00 2001 From: Bartlomiej Obecny Date: Thu, 22 Apr 2021 22:54:03 +0200 Subject: [PATCH 1/3] chore: adding sufix propagator to http baggage and http trace context --- README.md | 2 + benchmark/README.md | 4 +- benchmark/propagator.js | 4 +- .../validation-server.js | 4 +- packages/opentelemetry-core/README.md | 12 ++--- ...ttpBaggage.ts => HttpBaggagePropagator.ts} | 2 +- ...ntext.ts => HttpTraceContextPropagator.ts} | 2 +- packages/opentelemetry-core/src/index.ts | 4 +- .../test/baggage/HttpBaggage.test.ts | 44 ++++++++++++------- .../test/context/HttpTraceContext.test.ts | 8 ++-- .../test/context/composite.test.ts | 18 +++++--- .../test/helper.ts | 4 +- .../test/Shim.test.ts | 9 ++-- .../src/BasicTracerProvider.ts | 9 ++-- 14 files changed, 76 insertions(+), 50 deletions(-) rename packages/opentelemetry-core/src/baggage/propagation/{HttpBaggage.ts => HttpBaggagePropagator.ts} (98%) rename packages/opentelemetry-core/src/context/propagation/{HttpTraceContext.ts => HttpTraceContextPropagator.ts} (98%) diff --git a/README.md b/README.md index 30d8ba27cf..a36435603a 100644 --- a/README.md +++ b/README.md @@ -248,6 +248,8 @@ To request automatic tracing support for a module not on this list, please [file ### 0.19.0 to 1.0.0-rc.0 - All plugins have been removed in favor of instrumentations. +- `HttpBaggage` renamed to `HttpBaggagePropagator` +- `HttpTraceContext` renamed to `HttpTraceContextPropagator` ### 0.18.0 to 0.19.0 diff --git a/benchmark/README.md b/benchmark/README.md index 63ad35c4ca..81ceaab647 100644 --- a/benchmark/README.md +++ b/benchmark/README.md @@ -59,7 +59,7 @@ Beginning B3Propagator Benchmark... #Inject x 2,018,725 ops/sec ±3.49% (100 runs sampled) #Extract x 2,040,891 ops/sec ±1.75% (100 runs sampled) -Beginning HttpTraceContext Benchmark... +Beginning HttpTraceContextPropagator Benchmark... 2 tests completed. #Inject x 3,987,007 ops/sec ±1.87% (100 runs sampled) @@ -112,7 +112,7 @@ Beginning B3Propagator Benchmark... #Inject x 5,086,366 ops/sec ±3.18% (100 runs sampled) #Extract x 4,859,557 ops/sec ±3.80% (100 runs sampled) -Beginning HttpTraceContext Benchmark... +Beginning HttpTraceContextPropagator Benchmark... 2 tests completed. #Inject x 13,660,710 ops/sec ±1.84% (100 runs sampled) diff --git a/benchmark/propagator.js b/benchmark/propagator.js index e3e5617523..51a8058e1f 100644 --- a/benchmark/propagator.js +++ b/benchmark/propagator.js @@ -17,8 +17,8 @@ const setups = [ } }, { - name: 'HttpTraceContext', - propagator: new opentelemetry.HttpTraceContext(), + name: 'HttpTraceContextPropagator', + propagator: new opentelemetry.HttpTraceContextPropagator(), injectCarrier: {}, extractCarrier: { traceparent: '00-d4cda95b652f4a1592b449d5929fda1b-6e0c63257de34c92-00' diff --git a/integration-tests/propagation-validation-server/validation-server.js b/integration-tests/propagation-validation-server/validation-server.js index badcddb769..2c327cacb8 100644 --- a/integration-tests/propagation-validation-server/validation-server.js +++ b/integration-tests/propagation-validation-server/validation-server.js @@ -1,5 +1,5 @@ const axios = require("axios"); -const { HttpTraceContext } = require("@opentelemetry/core"); +const { HttpTraceContextPropagator } = require("@opentelemetry/core"); const { BasicTracerProvider } = require("@opentelemetry/tracing"); const { context, propagation, setSpan, trace, ROOT_CONTEXT } = require("@opentelemetry/api"); const { @@ -8,7 +8,7 @@ const { const bodyParser = require("body-parser"); // set global propagator -propagation.setGlobalPropagator(new HttpTraceContext()); +propagation.setGlobalPropagator(new HttpTraceContextPropagator()); // set global context manager context.setGlobalContextManager(new AsyncHooksContextManager()); diff --git a/packages/opentelemetry-core/README.md b/packages/opentelemetry-core/README.md index c2ea181750..f3ddb50cac 100644 --- a/packages/opentelemetry-core/README.md +++ b/packages/opentelemetry-core/README.md @@ -12,7 +12,7 @@ This package provides default implementations of the OpenTelemetry API for trace - [OpenTelemetry Core](#opentelemetry-core) - [Built-in Implementations](#built-in-implementations) - [Built-in Propagators](#built-in-propagators) - - [HttpTraceContext Propagator](#httptracecontext-propagator) + - [HttpTraceContextPropagator Propagator](#httptracecontext-propagator) - [Composite Propagator](#composite-propagator) - [Baggage Propagator](#baggage-propagator) - [Built-in Sampler](#built-in-sampler) @@ -25,16 +25,16 @@ This package provides default implementations of the OpenTelemetry API for trace ### Built-in Propagators -#### HttpTraceContext Propagator +#### HttpTraceContextPropagator Propagator OpenTelemetry provides a text-based approach to propagate context to remote services using the [W3C Trace Context](https://www.w3.org/TR/trace-context/) HTTP headers. ```js const api = require("@opentelemetry/api"); -const { HttpTraceContext } = require("@opentelemetry/core"); +const { HttpTraceContextPropagator } = require("@opentelemetry/core"); /* Set Global Propagator */ -api.propagation.setGlobalPropagator(new HttpTraceContext()); +api.propagation.setGlobalPropagator(new HttpTraceContextPropagator()); ``` #### Composite Propagator @@ -57,10 +57,10 @@ Provides a text-based approach to propagate [baggage](https://w3c.github.io/bagg ```js const api = require("@opentelemetry/api"); -const { HttpBaggage } = require("@opentelemetry/core"); +const { HttpBaggagePropagator } = require("@opentelemetry/core"); /* Set Global Propagator */ -api.propagation.setGlobalPropagator(new HttpBaggage()); +api.propagation.setGlobalPropagator(new HttpBaggagePropagator()); ``` ### Built-in Sampler diff --git a/packages/opentelemetry-core/src/baggage/propagation/HttpBaggage.ts b/packages/opentelemetry-core/src/baggage/propagation/HttpBaggagePropagator.ts similarity index 98% rename from packages/opentelemetry-core/src/baggage/propagation/HttpBaggage.ts rename to packages/opentelemetry-core/src/baggage/propagation/HttpBaggagePropagator.ts index 9452623b99..33f636dfdc 100644 --- a/packages/opentelemetry-core/src/baggage/propagation/HttpBaggage.ts +++ b/packages/opentelemetry-core/src/baggage/propagation/HttpBaggagePropagator.ts @@ -47,7 +47,7 @@ export const MAX_TOTAL_LENGTH = 8192; * Based on the Baggage specification: * https://w3c.github.io/baggage/ */ -export class HttpBaggage implements TextMapPropagator { +export class HttpBaggagePropagator implements TextMapPropagator { inject(context: Context, carrier: unknown, setter: TextMapSetter) { const baggage = getBaggage(context); if (!baggage || isInstrumentationSuppressed(context)) return; diff --git a/packages/opentelemetry-core/src/context/propagation/HttpTraceContext.ts b/packages/opentelemetry-core/src/context/propagation/HttpTraceContextPropagator.ts similarity index 98% rename from packages/opentelemetry-core/src/context/propagation/HttpTraceContext.ts rename to packages/opentelemetry-core/src/context/propagation/HttpTraceContextPropagator.ts index d40b447798..b792188492 100644 --- a/packages/opentelemetry-core/src/context/propagation/HttpTraceContext.ts +++ b/packages/opentelemetry-core/src/context/propagation/HttpTraceContextPropagator.ts @@ -72,7 +72,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 TextMapPropagator { +export class HttpTraceContextPropagator implements TextMapPropagator { inject(context: Context, carrier: unknown, setter: TextMapSetter) { const spanContext = getSpanContext(context); if ( diff --git a/packages/opentelemetry-core/src/index.ts b/packages/opentelemetry-core/src/index.ts index 9245f0148a..f3d206097d 100644 --- a/packages/opentelemetry-core/src/index.ts +++ b/packages/opentelemetry-core/src/index.ts @@ -22,9 +22,9 @@ export * from './common/types'; export * from './ExportResult'; export * from './version'; export * from './context/propagation/composite'; -export * from './context/propagation/HttpTraceContext'; +export * from './baggage/propagation/HttpBaggagePropagator'; +export * from './context/propagation/HttpTraceContextPropagator'; export * from './context/propagation/types'; -export * from './baggage/propagation/HttpBaggage'; export * from './platform'; export * from './trace/sampler/AlwaysOffSampler'; export * from './trace/sampler/AlwaysOnSampler'; diff --git a/packages/opentelemetry-core/test/baggage/HttpBaggage.test.ts b/packages/opentelemetry-core/test/baggage/HttpBaggage.test.ts index 464be7c2c9..f081693b45 100644 --- a/packages/opentelemetry-core/test/baggage/HttpBaggage.test.ts +++ b/packages/opentelemetry-core/test/baggage/HttpBaggage.test.ts @@ -27,11 +27,11 @@ import { ROOT_CONTEXT } from '@opentelemetry/api'; import * as assert from 'assert'; import { BAGGAGE_HEADER, - HttpBaggage, -} from '../../src/baggage/propagation/HttpBaggage'; + HttpBaggagePropagator, +} from '../../src/baggage/propagation/HttpBaggagePropagator'; -describe('HttpBaggage', () => { - const httpTraceContext = new HttpBaggage(); +describe('HttpBaggagePropagator', () => { + const httpBaggagePropagator = new HttpBaggagePropagator(); let carrier: { [key: string]: unknown }; @@ -47,7 +47,7 @@ describe('HttpBaggage', () => { 'with/slash': { value: 'with spaces' }, }); - httpTraceContext.inject( + httpBaggagePropagator.inject( setBaggage(ROOT_CONTEXT, baggage), carrier, defaultTextMapSetter @@ -64,7 +64,7 @@ describe('HttpBaggage', () => { key3: { value: 'c88815a7' }, }); - httpTraceContext.inject( + httpBaggagePropagator.inject( setBaggage(ROOT_CONTEXT, baggage), carrier, defaultTextMapSetter @@ -85,7 +85,7 @@ describe('HttpBaggage', () => { [shortKey]: { value: value }, }); - httpTraceContext.inject( + httpBaggagePropagator.inject( setBaggage(ROOT_CONTEXT, baggage), carrier, defaultTextMapSetter @@ -101,7 +101,7 @@ describe('HttpBaggage', () => { }); carrier = {}; - httpTraceContext.inject( + httpBaggagePropagator.inject( setBaggage(ROOT_CONTEXT, baggage), carrier, defaultTextMapSetter @@ -123,7 +123,7 @@ describe('HttpBaggage', () => { aa: { value: Array(88).fill('v').join('') }, }); - httpTraceContext.inject( + httpBaggagePropagator.inject( setBaggage(ROOT_CONTEXT, baggage), carrier, defaultTextMapSetter @@ -141,7 +141,7 @@ describe('HttpBaggage', () => { }); carrier = {}; - httpTraceContext.inject( + httpBaggagePropagator.inject( setBaggage(ROOT_CONTEXT, baggage), carrier, defaultTextMapSetter @@ -164,7 +164,7 @@ describe('HttpBaggage', () => { const baggage = createBaggage(entries); - httpTraceContext.inject( + httpBaggagePropagator.inject( setBaggage(ROOT_CONTEXT, baggage), carrier, defaultTextMapSetter @@ -181,7 +181,11 @@ describe('HttpBaggage', () => { carrier[BAGGAGE_HEADER] = 'key1=d4cda95b,key3=c88815a7, keyn = valn, keym =valm'; const extractedBaggage = getBaggage( - httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) + httpBaggagePropagator.extract( + ROOT_CONTEXT, + carrier, + defaultTextMapGetter + ) ); const expected = createBaggage({ @@ -196,7 +200,7 @@ describe('HttpBaggage', () => { describe('fields()', () => { it('returns the fields used by the baggage spec', () => { - const propagator = new HttpBaggage(); + const propagator = new HttpBaggagePropagator(); assert.deepStrictEqual(propagator.fields(), [BAGGAGE_HEADER]); }); }); @@ -204,7 +208,11 @@ describe('HttpBaggage', () => { it('returns undefined if header is missing', () => { assert.deepStrictEqual( getBaggage( - httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) + httpBaggagePropagator.extract( + ROOT_CONTEXT, + carrier, + defaultTextMapGetter + ) ), undefined ); @@ -213,7 +221,7 @@ describe('HttpBaggage', () => { it('returns keys with their properties', () => { carrier[BAGGAGE_HEADER] = 'key1=d4cda95b,key3=c88815a7;prop1=value1'; const bag = getBaggage( - httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) + httpBaggagePropagator.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) ); assert.ok(bag); @@ -265,7 +273,11 @@ describe('HttpBaggage', () => { carrier[BAGGAGE_HEADER] = testCases[testCase].header; const extractedSpanContext = getBaggage( - httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) + httpBaggagePropagator.extract( + ROOT_CONTEXT, + carrier, + defaultTextMapGetter + ) ); assert.deepStrictEqual( extractedSpanContext, diff --git a/packages/opentelemetry-core/test/context/HttpTraceContext.test.ts b/packages/opentelemetry-core/test/context/HttpTraceContext.test.ts index ca2bfabb7a..5bceba8f7b 100644 --- a/packages/opentelemetry-core/test/context/HttpTraceContext.test.ts +++ b/packages/opentelemetry-core/test/context/HttpTraceContext.test.ts @@ -28,14 +28,14 @@ import { } from '@opentelemetry/api'; import * as assert from 'assert'; import { - HttpTraceContext, + HttpTraceContextPropagator, TRACE_PARENT_HEADER, TRACE_STATE_HEADER, -} from '../../src/context/propagation/HttpTraceContext'; +} from '../../src/context/propagation/HttpTraceContextPropagator'; import { TraceState } from '../../src/trace/TraceState'; -describe('HttpTraceContext', () => { - const httpTraceContext = new HttpTraceContext(); +describe('HttpTraceContextPropagator', () => { + const httpTraceContext = new HttpTraceContextPropagator(); let carrier: { [key: string]: unknown }; beforeEach(() => { diff --git a/packages/opentelemetry-core/test/context/composite.test.ts b/packages/opentelemetry-core/test/context/composite.test.ts index 6addee1ff2..22afd98c95 100644 --- a/packages/opentelemetry-core/test/context/composite.test.ts +++ b/packages/opentelemetry-core/test/context/composite.test.ts @@ -26,7 +26,7 @@ import { Context, ROOT_CONTEXT } from '@opentelemetry/api'; import * as assert from 'assert'; import { CompositePropagator, - HttpTraceContext, + HttpTraceContextPropagator, RandomIdGenerator, } from '../../src'; import { @@ -39,7 +39,7 @@ import { import { TRACE_PARENT_HEADER, TRACE_STATE_HEADER, -} from '../../src/context/propagation/HttpTraceContext'; +} from '../../src/context/propagation/HttpTraceContextPropagator'; import { TraceState } from '../../src/trace/TraceState'; describe('Composite Propagator', () => { @@ -72,7 +72,7 @@ describe('Composite Propagator', () => { const composite = new CompositePropagator({ propagators: [ new B3Propagator({ injectEncoding: B3InjectEncoding.MULTI_HEADER }), - new HttpTraceContext(), + new HttpTraceContextPropagator(), ], }); composite.inject(ctxWithSpanContext, carrier, defaultTextMapSetter); @@ -89,7 +89,10 @@ describe('Composite Propagator', () => { it('should not throw', () => { const composite = new CompositePropagator({ - propagators: [new ThrowingPropagator(), new HttpTraceContext()], + propagators: [ + new ThrowingPropagator(), + new HttpTraceContextPropagator(), + ], }); composite.inject(ctxWithSpanContext, carrier, defaultTextMapSetter); @@ -117,7 +120,7 @@ describe('Composite Propagator', () => { const composite = new CompositePropagator({ propagators: [ new B3Propagator({ injectEncoding: B3InjectEncoding.MULTI_HEADER }), - new HttpTraceContext(), + new HttpTraceContextPropagator(), ], }); const spanContext = getSpanContext( @@ -137,7 +140,10 @@ describe('Composite Propagator', () => { it('should not throw', () => { const composite = new CompositePropagator({ - propagators: [new ThrowingPropagator(), new HttpTraceContext()], + propagators: [ + new ThrowingPropagator(), + new HttpTraceContextPropagator(), + ], }); const spanContext = getSpanContext( composite.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter) diff --git a/packages/opentelemetry-instrumentation-grpc/test/helper.ts b/packages/opentelemetry-instrumentation-grpc/test/helper.ts index 77665b6824..1c71e49430 100644 --- a/packages/opentelemetry-instrumentation-grpc/test/helper.ts +++ b/packages/opentelemetry-instrumentation-grpc/test/helper.ts @@ -21,7 +21,7 @@ import { setSpan, getSpan, } from '@opentelemetry/api'; -import { HttpTraceContext } from '@opentelemetry/core'; +import { HttpTraceContextPropagator } from '@opentelemetry/core'; import { NodeTracerProvider } from '@opentelemetry/node'; import { AsyncHooksContextManager } from '@opentelemetry/context-async-hooks'; import { ContextManager } from '@opentelemetry/api'; @@ -388,7 +388,7 @@ export const runTests = ( let contextManager: ContextManager; before(() => { - propagation.setGlobalPropagator(new HttpTraceContext()); + propagation.setGlobalPropagator(new HttpTraceContextPropagator()); }); beforeEach(() => { diff --git a/packages/opentelemetry-shim-opentracing/test/Shim.test.ts b/packages/opentelemetry-shim-opentracing/test/Shim.test.ts index b571150013..0948d571c4 100644 --- a/packages/opentelemetry-shim-opentracing/test/Shim.test.ts +++ b/packages/opentelemetry-shim-opentracing/test/Shim.test.ts @@ -20,9 +20,9 @@ import { BasicTracerProvider, Span } from '@opentelemetry/tracing'; import { TracerShim, SpanShim, SpanContextShim } from '../src/shim'; import { timeInputToHrTime, - HttpTraceContext, + HttpTraceContextPropagator, CompositePropagator, - HttpBaggage, + HttpBaggagePropagator, } from '@opentelemetry/core'; import { createBaggage, @@ -38,7 +38,10 @@ describe('OpenTracing Shim', () => { ); opentracing.initGlobalTracer(shimTracer); const compositePropagator = new CompositePropagator({ - propagators: [new HttpTraceContext(), new HttpBaggage()], + propagators: [ + new HttpTraceContextPropagator(), + new HttpBaggagePropagator(), + ], }); propagation.setGlobalPropagator(compositePropagator); diff --git a/packages/opentelemetry-tracing/src/BasicTracerProvider.ts b/packages/opentelemetry-tracing/src/BasicTracerProvider.ts index 5eee7bea22..c7c1c35674 100644 --- a/packages/opentelemetry-tracing/src/BasicTracerProvider.ts +++ b/packages/opentelemetry-tracing/src/BasicTracerProvider.ts @@ -22,8 +22,8 @@ import { } from '@opentelemetry/api'; import { CompositePropagator, - HttpBaggage, - HttpTraceContext, + HttpBaggagePropagator, + HttpTraceContextPropagator, } from '@opentelemetry/core'; import { Resource } from '@opentelemetry/resources'; import { SpanProcessor, Tracer } from '.'; @@ -87,7 +87,10 @@ export class BasicTracerProvider implements TracerProvider { trace.setGlobalTracerProvider(this); if (config.propagator === undefined) { config.propagator = new CompositePropagator({ - propagators: [new HttpBaggage(), new HttpTraceContext()], + propagators: [ + new HttpBaggagePropagator(), + new HttpTraceContextPropagator(), + ], }); } From ffff74c6d4de8816a5c4b6d5cba04309cf86d3a9 Mon Sep 17 00:00:00 2001 From: Bartlomiej Obecny Date: Fri, 23 Apr 2021 19:11:11 +0200 Subject: [PATCH 2/3] chore: readme --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ce72ec00ce..c06432774b 100644 --- a/README.md +++ b/README.md @@ -245,16 +245,18 @@ To request automatic tracing support for a module not on this list, please [file ## Upgrade guidelines +### 0.19.x to x + +- `HttpBaggage` renamed to `HttpBaggagePropagator` + +- `HttpTraceContext` renamed to `HttpTraceContextPropagator` + ### 0.18.x to 0.19.0 - API is now a peer dependency. This means that users will need to include `@opentelemetry/api` as a dependency of their project in order to use the SDK. NPM version 7+ (Node 15+) should do this automatically. - All plugins have been removed in favor of instrumentations. -- `HttpBaggage` renamed to `HttpBaggagePropagator` - -- `HttpTraceContext` renamed to `HttpTraceContextPropagator` - - The `@opentelemetry/propagator-b3` package previously exported three propagators: `B3Propagator`,`B3SinglePropagator`, and `B3MultiPropagator`, but now only exports the `B3Propagator`. It extracts b3 context in single and multi-header encodings, and injects context using the single-header encoding by default, but can be configured to inject context using the multi-header endcoding during construction: `new B3Propagator({ injectEncoding: B3InjectEncoding.MULTI_HEADER })`. If you were previously using the `B3SinglePropagator` or `B3MultiPropagator` directly, you should update your code to use the `B3Propagator` with the appropriate configuration. See the [readme](./packages/opentelemetry-propagator-b3/readme.md) for full details and usage. - Sampling configuration via environment variable has changed. If you were using `OTEL_SAMPLING_PROBABILITY` then you should replace it with `OTEL_TRACES_SAMPLER=parentbased_traceidratio` and `OTEL_TRACES_SAMPLER_ARG=` where `` is a number in the [0..1] range, e.g. "0.25". Default is 1.0 if unset. From 26961c05ab28c9534cf583a49d65529279b68aec Mon Sep 17 00:00:00 2001 From: Bartlomiej Obecny Date: Fri, 30 Apr 2021 20:31:04 +0200 Subject: [PATCH 3/3] chore: fixes after merge --- .../{HttpBaggage.test.ts => HttpBaggagePropagator.test.ts} | 0 ...ttpTraceContext.test.ts => HttpTraceContextPropagator.test.ts} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename packages/opentelemetry-core/test/baggage/{HttpBaggage.test.ts => HttpBaggagePropagator.test.ts} (100%) rename packages/opentelemetry-core/test/trace/{HttpTraceContext.test.ts => HttpTraceContextPropagator.test.ts} (100%) diff --git a/packages/opentelemetry-core/test/baggage/HttpBaggage.test.ts b/packages/opentelemetry-core/test/baggage/HttpBaggagePropagator.test.ts similarity index 100% rename from packages/opentelemetry-core/test/baggage/HttpBaggage.test.ts rename to packages/opentelemetry-core/test/baggage/HttpBaggagePropagator.test.ts diff --git a/packages/opentelemetry-core/test/trace/HttpTraceContext.test.ts b/packages/opentelemetry-core/test/trace/HttpTraceContextPropagator.test.ts similarity index 100% rename from packages/opentelemetry-core/test/trace/HttpTraceContext.test.ts rename to packages/opentelemetry-core/test/trace/HttpTraceContextPropagator.test.ts