Skip to content

Commit

Permalink
chore!: move b3 into its own package (#1595)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwear committed Oct 26, 2020
1 parent e5b7de9 commit 46f31dd
Show file tree
Hide file tree
Showing 32 changed files with 590 additions and 67 deletions.
3 changes: 2 additions & 1 deletion benchmark/propagator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ const benchmark = require('./benchmark');
const opentelemetry = require('../packages/opentelemetry-core');
const api = require('../packages/opentelemetry-api');
const { Context } = require('../packages/opentelemetry-context-base');
const { B3Propagator } = require('../packages/opentelemetry-propagator-b3');

const setups = [
{
name: 'B3Propagator',
propagator: new opentelemetry.B3Propagator(),
propagator: new B3Propagator(),
injectCarrier: {},
extractCarrier: {
'x-b3-traceid': 'd4cda95b652f4a1592b449d5929fda1b',
Expand Down
2 changes: 1 addition & 1 deletion examples/tracer-web/examples/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CollectorTraceExporter } from '@opentelemetry/exporter-collector';
import { WebTracerProvider } from '@opentelemetry/web';
import { FetchPlugin } from '@opentelemetry/plugin-fetch';
import { ZoneContextManager } from '@opentelemetry/context-zone';
import { B3Propagator } from '@opentelemetry/core';
import { B3Propagator } from '@opentelemetry/propagator-b3';

const provider = new WebTracerProvider({
plugins: [
Expand Down
2 changes: 1 addition & 1 deletion examples/tracer-web/examples/xml-http-request/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { WebTracerProvider } from '@opentelemetry/web';
import { XMLHttpRequestPlugin } from '@opentelemetry/plugin-xml-http-request';
import { ZoneContextManager } from '@opentelemetry/context-zone';
import { CollectorTraceExporter } from '@opentelemetry/exporter-collector';
import { B3Propagator } from '@opentelemetry/core';
import { B3Propagator } from '@opentelemetry/propagator-b3';

const providerWithZone = new WebTracerProvider({
plugins: [
Expand Down
1 change: 1 addition & 0 deletions examples/tracer-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@opentelemetry/exporter-collector": "^0.12.0",
"@opentelemetry/exporter-zipkin": "^0.12.0",
"@opentelemetry/metrics": "^0.12.0",
"@opentelemetry/propagator-b3": "^0.12.0",
"@opentelemetry/plugin-document-load": "^0.9.0",
"@opentelemetry/plugin-fetch": "^0.12.0",
"@opentelemetry/plugin-user-interaction": "^0.9.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Because the npm installer and node module resolution algorithm could potentially
If you prefer to choose your own propagator or context manager, you may pass an options object into the `tracerProvider.register()` method. Omitted or `undefined` options will be replaced by a default value and `null` values will be skipped.

```javascript
const { B3Propagator } = require("@opentelemetry/core");
const { B3Propagator } = require("@opentelemetry/propagator-b3");

tracerProvider.register({
// Use B3 Propagation
Expand Down
13 changes: 0 additions & 13 deletions packages/opentelemetry-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ This package provides default implementations of the OpenTelemetry API for trace
- [Built-in Implementations](#built-in-implementations)
- [Built-in Propagators](#built-in-propagators)
- [HttpTraceContext Propagator](#httptracecontext-propagator)
- [B3 Propagator](#b3-propagator)
- [Composite Propagator](#composite-propagator)
- [Correlation Context Propagator](#correlation-context-propagator)
- [Built-in Sampler](#built-in-sampler)
Expand All @@ -38,18 +37,6 @@ const { HttpTraceContext } = require("@opentelemetry/core");
api.propagation.setGlobalPropagator(new HttpTraceContext());
```

#### B3 Propagator

This is propagator for the B3 HTTP header format, which sends a `SpanContext` on the wire in an HTTP request, allowing other services to create spans with the right context. Based on: <https://github.com/openzipkin/b3-propagation>

```js
const api = require("@opentelemetry/api");
const { B3Propagator } = require("@opentelemetry/core");

/* Set Global Propagator */
api.propagation.setGlobalPropagator(new B3Propagator());
```

#### Composite Propagator

Combines multiple propagators into a single propagator.
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"access": "public"
},
"devDependencies": {
"@opentelemetry/propagator-b3": "^0.12.0",
"@types/mocha": "8.0.2",
"@types/node": "14.0.27",
"@types/semver": "7.3.2",
Expand Down
3 changes: 0 additions & 3 deletions packages/opentelemetry-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ export * from './common/time';
export * from './common/types';
export * from './ExportResult';
export * from './version';
export * from './context/propagation/B3Propagator';
export * from './context/propagation/B3SinglePropagator';
export * from './context/propagation/B3MultiPropagator';
export * from './context/propagation/composite';
export * from './context/propagation/HttpTraceContext';
export * from './context/propagation/types';
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-core/test/context/composite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
X_B3_SAMPLED,
X_B3_SPAN_ID,
X_B3_TRACE_ID,
} from '../../src/context/propagation/B3MultiPropagator';
} from '@opentelemetry/propagator-b3';
import {
TRACE_PARENT_HEADER,
TRACE_STATE_HEADER,
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-plugin-fetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"devDependencies": {
"@babel/core": "7.11.1",
"@opentelemetry/context-zone": "^0.12.0",
"@opentelemetry/propagator-b3": "^0.12.0",
"@opentelemetry/tracing": "^0.12.0",
"@types/mocha": "8.0.2",
"@types/node": "14.0.27",
Expand Down
37 changes: 22 additions & 15 deletions packages/opentelemetry-plugin-fetch/test/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
*/
import * as api from '@opentelemetry/api';
import * as core from '@opentelemetry/core';
import {
B3Propagator,
B3InjectEncoding,
X_B3_TRACE_ID,
X_B3_SPAN_ID,
X_B3_SAMPLED,
} from '@opentelemetry/propagator-b3';
import { ZoneContextManager } from '@opentelemetry/context-zone';
import * as tracing from '@opentelemetry/tracing';
import {
Expand Down Expand Up @@ -219,8 +226,8 @@ describe('fetch', () => {

before(() => {
api.propagation.setGlobalPropagator(
new core.B3Propagator({
injectEncoding: core.B3InjectEncoding.MULTI_HEADER,
new B3Propagator({
injectEncoding: B3InjectEncoding.MULTI_HEADER,
})
);
});
Expand Down Expand Up @@ -449,26 +456,26 @@ describe('fetch', () => {
it('should set trace headers', () => {
const span: api.Span = exportSpy.args[1][0][0];
assert.strictEqual(
lastResponse.headers[core.X_B3_TRACE_ID],
lastResponse.headers[X_B3_TRACE_ID],
span.context().traceId,
`trace header '${core.X_B3_TRACE_ID}' not set`
`trace header '${X_B3_TRACE_ID}' not set`
);
assert.strictEqual(
lastResponse.headers[core.X_B3_SPAN_ID],
lastResponse.headers[X_B3_SPAN_ID],
span.context().spanId,
`trace header '${core.X_B3_SPAN_ID}' not set`
`trace header '${X_B3_SPAN_ID}' not set`
);
assert.strictEqual(
lastResponse.headers[core.X_B3_SAMPLED],
lastResponse.headers[X_B3_SAMPLED],
String(span.context().traceFlags),
`trace header '${core.X_B3_SAMPLED}' not set`
`trace header '${X_B3_SAMPLED}' not set`
);
});

it('should set trace headers with a request object', () => {
const r = new Request('url');
window.fetch(r);
assert.ok(typeof r.headers.get(core.X_B3_TRACE_ID) === 'string');
assert.ok(typeof r.headers.get(X_B3_TRACE_ID) === 'string');
});

it('should NOT clear the resources', () => {
Expand All @@ -486,19 +493,19 @@ describe('fetch', () => {
});
it('should NOT set trace headers', () => {
assert.strictEqual(
lastResponse.headers[core.X_B3_TRACE_ID],
lastResponse.headers[X_B3_TRACE_ID],
undefined,
`trace header '${core.X_B3_TRACE_ID}' should not be set`
`trace header '${X_B3_TRACE_ID}' should not be set`
);
assert.strictEqual(
lastResponse.headers[core.X_B3_SPAN_ID],
lastResponse.headers[X_B3_SPAN_ID],
undefined,
`trace header '${core.X_B3_SPAN_ID}' should not be set`
`trace header '${X_B3_SPAN_ID}' should not be set`
);
assert.strictEqual(
lastResponse.headers[core.X_B3_SAMPLED],
lastResponse.headers[X_B3_SAMPLED],
undefined,
`trace header '${core.X_B3_SAMPLED}' should not be set`
`trace header '${X_B3_SAMPLED}' should not be set`
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"devDependencies": {
"@babel/core": "7.11.1",
"@opentelemetry/context-zone": "^0.12.0",
"@opentelemetry/propagator-b3": "^0.12.0",
"@opentelemetry/tracing": "^0.12.0",
"@types/mocha": "8.0.2",
"@types/node": "14.0.27",
Expand Down
12 changes: 7 additions & 5 deletions packages/opentelemetry-plugin-xml-http-request/test/xhr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@
*/
import * as api from '@opentelemetry/api';
import {
B3Propagator,
LogLevel,
otperformance as performance,
X_B3_SAMPLED,
X_B3_SPAN_ID,
X_B3_TRACE_ID,
isWrapped,
NoopLogger,
B3InjectEncoding,
} from '@opentelemetry/core';
import {
B3Propagator,
B3InjectEncoding,
X_B3_SAMPLED,
X_B3_SPAN_ID,
X_B3_TRACE_ID,
} from '@opentelemetry/propagator-b3';
import { ZoneContextManager } from '@opentelemetry/context-zone';
import * as tracing from '@opentelemetry/tracing';
import { HttpAttribute } from '@opentelemetry/semantic-conventions';
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-propagator-b3/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
9 changes: 9 additions & 0 deletions packages/opentelemetry-propagator-b3/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
"env": {
"mocha": true,
"commonjs": true,
"node": true,
"browser": true
},
...require('../../eslint.config.js')
}
4 changes: 4 additions & 0 deletions packages/opentelemetry-propagator-b3/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/bin
/coverage
/doc
/test
Loading

0 comments on commit 46f31dd

Please sign in to comment.