Skip to content

Commit e423522

Browse files
authored
Merge 5536cf3 into 239745f
2 parents 239745f + 5536cf3 commit e423522

File tree

11 files changed

+70
-72
lines changed

11 files changed

+70
-72
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ To request automatic tracing support for a module not on this list, please [file
247247

248248
## Upgrade guidelines
249249

250+
### 0.18.0 to 0.19.0
251+
252+
- 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.
253+
250254
### 0.17.0 to 0.18.0
251255

252256
- `diag.setLogLevel` is removed and LogLevel can be set by an optional second parameter to `setLogger`

packages/opentelemetry-core/test/context/composite.test.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ import {
3030
RandomIdGenerator,
3131
} from '../../src';
3232
import {
33-
B3MultiPropagator,
33+
B3Propagator,
34+
B3InjectEncoding,
3435
X_B3_SAMPLED,
3536
X_B3_SPAN_ID,
3637
X_B3_TRACE_ID,
@@ -69,7 +70,10 @@ describe('Composite Propagator', () => {
6970

7071
it('should inject context using all configured propagators', () => {
7172
const composite = new CompositePropagator({
72-
propagators: [new B3MultiPropagator(), new HttpTraceContext()],
73+
propagators: [
74+
new B3Propagator({ injectEncoding: B3InjectEncoding.MULTI_HEADER }),
75+
new HttpTraceContext(),
76+
],
7377
});
7478
composite.inject(ctxWithSpanContext, carrier, defaultTextMapSetter);
7579

@@ -111,7 +115,10 @@ describe('Composite Propagator', () => {
111115

112116
it('should extract context using all configured propagators', () => {
113117
const composite = new CompositePropagator({
114-
propagators: [new B3MultiPropagator(), new HttpTraceContext()],
118+
propagators: [
119+
new B3Propagator({ injectEncoding: B3InjectEncoding.MULTI_HEADER }),
120+
new HttpTraceContext(),
121+
],
115122
});
116123
const spanContext = getSpanContext(
117124
composite.extract(ROOT_CONTEXT, carrier, defaultTextMapGetter)

packages/opentelemetry-propagator-b3/README.md

+14-48
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,15 @@ X-B3-Sampled: {SamplingState}
6565
- Optional
6666
- Debug is encoded as `X-B3-Flags`: 1. Absent or any other value can be ignored. Debug implies an accept decision, so don't also send the `X-B3-Sampled` header.
6767

68-
## Propagator Implementations
69-
70-
### B3Propagator
68+
## B3 Propagation
7169

7270
The default `B3Propagator` implements b3 propagation according to the
7371
[OpenTelemetry specification][otel-b3-requirements]. It extracts b3 context
7472
from multi and single header encodings and injects context using the
75-
single-header b3 encoding. The inject encoding can be changed to multi-header
76-
via configuration.
73+
single-header b3 encoding by default. The inject encoding can be changed to
74+
multi-header via configuration. See the examples below.
7775

78-
Example usage (default):
76+
### B3 Single-Header Configuration
7977

8078
```javascript
8179
const api = require('@opentelemetry/api');
@@ -84,7 +82,7 @@ const { B3Propagator } = require('@opentelemetry/propagator-b3');
8482
api.propagation.setGlobalPropagator(new B3Propagator());
8583
```
8684

87-
Example usage (specify inject encoding):
85+
### B3 Multi-Header Configuration
8886

8987
```javascript
9088
const api = require('@opentelemetry/api');
@@ -95,53 +93,21 @@ api.propagation.setGlobalPropagator(
9593
);
9694
```
9795

98-
### B3SinglePropagator
99-
100-
If a distributed system only needs support for the b3 single-header
101-
encoding it can use the `B3SinglePropagator` directly.
102-
103-
Example usage:
104-
105-
```javascript
106-
const api = require('@opentelemetry/api');
107-
const { B3SinglePropagator } = require('@opentelemetry/propagator-b3');
108-
109-
api.propagation.setGlobalPropagator(new B3SinglePropagator());
110-
```
111-
112-
### B3MultiPropagator
113-
114-
If a distributed system only needs support for the b3 multi-header
115-
encoding it can use the `B3MultiPropagator` directly.
116-
117-
Example usage:
118-
119-
```javascript
120-
const api = require('@opentelemetry/api');
121-
const { B3MultiPropagator } = require('@opentelemetry/propagator-b3');
122-
123-
api.propagation.setGlobalPropagator(new B3MultiPropagator());
124-
```
125-
126-
### CompositePropagator
127-
128-
If a distributed system needs to support both single and multiple header
129-
encodings for inject and extract the `B3SinglePropagator` and
130-
`B3MultiPropagator` can be used in conjunction with a `CompositePropagator`.
96+
### B3 Single and Multi-Header Configuration
13197

132-
Example usage:
98+
The B3Propagator always extracts both the single and multi-header b3 encodings.
99+
If you need to inject both encodings this can accomplished using a composite
100+
propagator.
133101

134102
```javascript
135103
const api = require('@opentelemetry/api');
136-
const { CompositePropagator } = require('@opentelemetry/core');
137-
const {
138-
B3SinglePropagator,
139-
B3MultiPropagator,
140-
} = require('@opentelemetry/propagator-b3');
141-
104+
const { B3Propagator } = require('@opentelemetry/propagator-b3');
142105
api.propagation.setGlobalPropagator(
143106
new CompositePropagator({
144-
propagators: [new B3SinglePropagator(), new B3MultiPropagator()],
107+
propagators: [
108+
new B3Propagator(),
109+
new B3Propagator({ injectEncoding: B3InjectEncoding.MULTI_HEADER }),
110+
],
145111
})
146112
);
147113
```

packages/opentelemetry-propagator-b3/src/B3MultiPropagator.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ import {
2626
TextMapSetter,
2727
TraceFlags,
2828
} from '@opentelemetry/api';
29+
import {
30+
X_B3_TRACE_ID,
31+
X_B3_SPAN_ID,
32+
X_B3_SAMPLED,
33+
X_B3_PARENT_SPAN_ID,
34+
X_B3_FLAGS,
35+
} from './constants';
2936
import { B3_DEBUG_FLAG_KEY } from './common';
3037

31-
/* b3 multi-header keys */
32-
export const X_B3_TRACE_ID = 'x-b3-traceid';
33-
export const X_B3_SPAN_ID = 'x-b3-spanid';
34-
export const X_B3_SAMPLED = 'x-b3-sampled';
35-
export const X_B3_PARENT_SPAN_ID = 'x-b3-parentspanid';
36-
export const X_B3_FLAGS = 'x-b3-flags';
37-
3838
const VALID_SAMPLED_VALUES = new Set([true, 'true', 'True', '1', 1]);
3939
const VALID_UNSAMPLED_VALUES = new Set([false, 'false', 'False', '0', 0]);
4040

packages/opentelemetry-propagator-b3/src/B3Propagator.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import {
2121
TextMapSetter,
2222
} from '@opentelemetry/api';
2323
import { B3MultiPropagator } from './B3MultiPropagator';
24-
import { B3SinglePropagator, B3_CONTEXT_HEADER } from './B3SinglePropagator';
24+
import { B3SinglePropagator } from './B3SinglePropagator';
25+
import { B3_CONTEXT_HEADER } from './constants';
2526
import { B3InjectEncoding, B3PropagatorConfig } from './types';
2627

2728
/**

packages/opentelemetry-propagator-b3/src/B3SinglePropagator.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ import {
2626
TextMapSetter,
2727
TraceFlags,
2828
} from '@opentelemetry/api';
29+
import { B3_CONTEXT_HEADER } from './constants';
2930
import { B3_DEBUG_FLAG_KEY } from './common';
3031

31-
/** B3 single-header name */
32-
export const B3_CONTEXT_HEADER = 'b3';
33-
3432
const B3_CONTEXT_REGEX = /((?:[0-9a-f]{16}){1,2})-([0-9a-f]{16})(?:-([01d](?![0-9a-f])))?(?:-([0-9a-f]{16}))?/;
3533
const PADDING = '0'.repeat(16);
3634
const SAMPLED_VALUES = new Set(['d', '1']);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/** B3 single-header key */
18+
export const B3_CONTEXT_HEADER = 'b3';
19+
20+
/* b3 multi-header keys */
21+
export const X_B3_TRACE_ID = 'x-b3-traceid';
22+
export const X_B3_SPAN_ID = 'x-b3-spanid';
23+
export const X_B3_SAMPLED = 'x-b3-sampled';
24+
export const X_B3_PARENT_SPAN_ID = 'x-b3-parentspanid';
25+
export const X_B3_FLAGS = 'x-b3-flags';

packages/opentelemetry-propagator-b3/src/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@
1515
*/
1616

1717
export * from './B3Propagator';
18-
export * from './B3SinglePropagator';
19-
export * from './B3MultiPropagator';
18+
export * from './constants';
2019
export * from './types';

packages/opentelemetry-propagator-b3/test/B3MultiPropagator.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ import {
2424
} from '@opentelemetry/api';
2525
import { ROOT_CONTEXT } from '@opentelemetry/api';
2626
import * as assert from 'assert';
27+
import { B3MultiPropagator } from '../src/B3MultiPropagator';
2728
import {
28-
B3MultiPropagator,
2929
X_B3_FLAGS,
3030
X_B3_PARENT_SPAN_ID,
3131
X_B3_SAMPLED,
3232
X_B3_SPAN_ID,
3333
X_B3_TRACE_ID,
34-
} from '../src/B3MultiPropagator';
34+
} from '../src/constants';
3535
import { B3_DEBUG_FLAG_KEY } from '../src/common';
3636

3737
describe('B3MultiPropagator', () => {

packages/opentelemetry-propagator-b3/test/B3Propagator.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ import {
2626
} from '@opentelemetry/api';
2727
import { B3Propagator } from '../src/B3Propagator';
2828
import { B3InjectEncoding } from '../src/types';
29-
import { B3_CONTEXT_HEADER } from '../src/B3SinglePropagator';
3029
import {
30+
B3_CONTEXT_HEADER,
3131
X_B3_FLAGS,
3232
X_B3_PARENT_SPAN_ID,
3333
X_B3_SAMPLED,
3434
X_B3_SPAN_ID,
3535
X_B3_TRACE_ID,
36-
} from '../src/B3MultiPropagator';
36+
} from '../src/constants';
3737

3838
describe('B3Propagator', () => {
3939
let propagator: B3Propagator;

packages/opentelemetry-propagator-b3/test/B3SinglePropagator.test.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ import {
2626
} from '@opentelemetry/api';
2727
import { ROOT_CONTEXT } from '@opentelemetry/api';
2828
import * as assert from 'assert';
29-
import {
30-
B3SinglePropagator,
31-
B3_CONTEXT_HEADER,
32-
} from '../src/B3SinglePropagator';
29+
import { B3SinglePropagator } from '../src/B3SinglePropagator';
30+
import { B3_CONTEXT_HEADER } from '../src/constants';
3331
import { B3_DEBUG_FLAG_KEY } from '../src/common';
3432

3533
describe('B3SinglePropagator', () => {

0 commit comments

Comments
 (0)