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 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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ 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.
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
4 changes: 2 additions & 2 deletions packages/opentelemetry-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

export * from './baggage/propagation/HttpBaggage';
export * from './baggage/propagation/HttpBaggagePropagator';
export * from './common/attributes';
export * from './common/global-error-handler';
export * from './common/logging-error-handler';
Expand All @@ -23,7 +23,7 @@ export * from './common/types';
export * from './ExportResult';
export * from './platform';
export * from './propagation/composite';
export * from './trace/HttpTraceContext';
export * from './trace/HttpTraceContextPropagator';
export * from './trace/IdGenerator';
export * from './trace/sampler/AlwaysOffSampler';
export * from './trace/sampler/AlwaysOnSampler';
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
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
18 changes: 12 additions & 6 deletions packages/opentelemetry-core/test/propagation/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/trace/HttpTraceContext';
} from '../../src/trace/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
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/trace/HttpTraceContext';
} from '../../src/trace/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
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,8 +20,8 @@ import { BasicTracerProvider, Span } from '@opentelemetry/tracing';
import { SpanContextShim, SpanShim, TracerShim } from '../src/shim';
import {
CompositePropagator,
HttpBaggage,
HttpTraceContext,
HttpBaggagePropagator,
HttpTraceContextPropagator,
timeInputToHrTime,
} from '@opentelemetry/core';
import {
Expand All @@ -40,7 +40,10 @@ import { JaegerHttpTracePropagator } from '@opentelemetry/propagator-jaeger';

describe('OpenTracing Shim', () => {
const compositePropagator = new CompositePropagator({
propagators: [new HttpTraceContext(), new HttpBaggage()],
propagators: [
new HttpTraceContextPropagator(),
new HttpBaggagePropagator(),
],
});

propagation.setGlobalPropagator(compositePropagator);
Expand Down
Loading