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

chore: adding sufix propagator to http baggage and http trace context #2149

Merged
merged 7 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ To request automatic tracing support for a module not on this list, please [file

- All plugins have been removed in favor of instrumentations.

- `HttpBaggage` renamed to `HttpBaggagePropagator`
obecny marked this conversation as resolved.
Show resolved Hide resolved

- `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=<number>` where `<number>` is a number in the [0..1] range, e.g. "0.25". Default is 1.0 if unset.
Expand Down
4 changes: 2 additions & 2 deletions benchmark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions benchmark/propagator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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());
Expand Down
12 changes: 6 additions & 6 deletions packages/opentelemetry-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
44 changes: 28 additions & 16 deletions packages/opentelemetry-core/test/baggage/HttpBaggage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand All @@ -47,7 +47,7 @@ describe('HttpBaggage', () => {
'with/slash': { value: 'with spaces' },
});

httpTraceContext.inject(
httpBaggagePropagator.inject(
setBaggage(ROOT_CONTEXT, baggage),
carrier,
defaultTextMapSetter
Expand All @@ -64,7 +64,7 @@ describe('HttpBaggage', () => {
key3: { value: 'c88815a7' },
});

httpTraceContext.inject(
httpBaggagePropagator.inject(
setBaggage(ROOT_CONTEXT, baggage),
carrier,
defaultTextMapSetter
Expand All @@ -85,7 +85,7 @@ describe('HttpBaggage', () => {
[shortKey]: { value: value },
});

httpTraceContext.inject(
httpBaggagePropagator.inject(
setBaggage(ROOT_CONTEXT, baggage),
carrier,
defaultTextMapSetter
Expand All @@ -101,7 +101,7 @@ describe('HttpBaggage', () => {
});

carrier = {};
httpTraceContext.inject(
httpBaggagePropagator.inject(
setBaggage(ROOT_CONTEXT, baggage),
carrier,
defaultTextMapSetter
Expand All @@ -123,7 +123,7 @@ describe('HttpBaggage', () => {
aa: { value: Array(88).fill('v').join('') },
});

httpTraceContext.inject(
httpBaggagePropagator.inject(
setBaggage(ROOT_CONTEXT, baggage),
carrier,
defaultTextMapSetter
Expand All @@ -141,7 +141,7 @@ describe('HttpBaggage', () => {
});

carrier = {};
httpTraceContext.inject(
httpBaggagePropagator.inject(
setBaggage(ROOT_CONTEXT, baggage),
carrier,
defaultTextMapSetter
Expand All @@ -164,7 +164,7 @@ describe('HttpBaggage', () => {

const baggage = createBaggage(entries);

httpTraceContext.inject(
httpBaggagePropagator.inject(
setBaggage(ROOT_CONTEXT, baggage),
carrier,
defaultTextMapSetter
Expand All @@ -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({
Expand All @@ -196,15 +200,19 @@ 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]);
});
});

it('returns undefined if header is missing', () => {
assert.deepStrictEqual(
getBaggage(
httpTraceContext.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)
httpBaggagePropagator.extract(
ROOT_CONTEXT,
carrier,
defaultTextMapGetter
)
),
undefined
);
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
18 changes: 12 additions & 6 deletions packages/opentelemetry-core/test/context/composite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { Context, ROOT_CONTEXT } from '@opentelemetry/api';
import * as assert from 'assert';
import {
CompositePropagator,
HttpTraceContext,
HttpTraceContextPropagator,
RandomIdGenerator,
} from '../../src';
import {
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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(
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-instrumentation-grpc/test/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -388,7 +388,7 @@ export const runTests = (
let contextManager: ContextManager;

before(() => {
propagation.setGlobalPropagator(new HttpTraceContext());
propagation.setGlobalPropagator(new HttpTraceContextPropagator());
});

beforeEach(() => {
Expand Down
9 changes: 6 additions & 3 deletions packages/opentelemetry-shim-opentracing/test/Shim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down
Loading