Skip to content

Commit e31b975

Browse files
authored
Update core README with Built-in Implementations (#857)
* Update core README with Built-in Implementations * fix link * remove desc
1 parent ab9d48e commit e31b975

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

packages/opentelemetry-core/README.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,95 @@
77

88
This package provides default and no-op implementations of the OpenTelemetry API for trace and metrics. It's intended for use both on the server and in the browser.
99

10+
## Built-in Implementations
11+
12+
- [Built-in Propagators](#built-in-propagators)
13+
* [HttpTraceContext Propagator](#httptracecontext-propagator)
14+
* [B3 Propagator](#b3-propagator)
15+
* [Composite Propagator](#composite-propagator)
16+
- [Built-in Sampler](#built-in-sampler)
17+
* [Always Sampler](#always-sampler)
18+
* [Never Sampler](#never-sampler)
19+
* [Probability Sampler](#probability-sampler)
20+
21+
### Built-in Propagators
22+
23+
#### HttpTraceContext Propagator
24+
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.
25+
26+
> This is used as a default Propagator
27+
28+
```js
29+
const api = require("@opentelemetry/api");
30+
const { HttpTraceContext } = require("@opentelemetry/core");
31+
32+
/* Set Global Propagator */
33+
api.propagation.setGlobalPropagator(new HttpTraceContext());
34+
```
35+
36+
#### B3 Propagator
37+
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
38+
39+
```js
40+
const api = require("@opentelemetry/api");
41+
const { B3Propagator } = require("@opentelemetry/core");
42+
43+
/* Set Global Propagator */
44+
api.propagation.setGlobalPropagator(new B3Propagator());
45+
```
46+
47+
#### Composite Propagator
48+
Combines multiple propagators into a single propagator.
49+
50+
```js
51+
const api = require("@opentelemetry/api");
52+
const { CompositePropagator } = require("@opentelemetry/core");
53+
54+
/* Set Global Propagator */
55+
api.propagation.setGlobalPropagator(new CompositePropagator());
56+
```
57+
58+
### Built-in Sampler
59+
Sampler is used to make decisions on `Span` sampling.
60+
61+
#### Always Sampler
62+
Samples every trace regardless of upstream sampling decisions.
63+
64+
> This is used as a default Sampler
65+
66+
```js
67+
const { NodeTracerProvider } = require("@opentelemetry/node");
68+
const { ALWAYS_SAMPLER } = require("@opentelemetry/core");
69+
70+
const tracerProvider = new NodeTracerProvider({
71+
sampler: ALWAYS_SAMPLER
72+
});
73+
```
74+
75+
#### Never Sampler
76+
Doesn't sample any trace, regardless of upstream sampling decisions.
77+
78+
```js
79+
const { NodeTracerProvider } = require("@opentelemetry/node");
80+
const { NEVER_SAMPLER } = require("@opentelemetry/core");
81+
82+
const tracerProvider = new NodeTracerProvider({
83+
sampler: NEVER_SAMPLER
84+
});
85+
```
86+
87+
#### Probability Sampler
88+
Samples a configurable percentage of traces, and additionally samples any trace that was sampled upstream.
89+
90+
```js
91+
const { NodeTracerProvider } = require("@opentelemetry/node");
92+
const { ProbabilitySampler } = require("@opentelemetry/core");
93+
94+
const tracerProvider = new NodeTracerProvider({
95+
sampler: new ProbabilitySampler(0.5)
96+
});
97+
```
98+
1099
## Useful links
11100
- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
12101
- For more about OpenTelemetry JavaScript: <https://github.com/open-telemetry/opentelemetry-js>

0 commit comments

Comments
 (0)