Add sampling doc for JS (#2482)
Co-authored-by: Patrice Chalin <chalin@users.noreply.github.com> Co-authored-by: Severin Neumann <neumanns@cisco.com> Co-authored-by: Marc Pichler <marcpi@edu.aau.at>
This commit is contained in:
parent
d9acfd25ea
commit
23b6d15c49
|
|
@ -0,0 +1,94 @@
|
||||||
|
---
|
||||||
|
title: Sampling
|
||||||
|
weight: 9
|
||||||
|
---
|
||||||
|
|
||||||
|
[Sampling](/docs/concepts/sampling/) is a process that restricts the amount of
|
||||||
|
traces that are generated by a system. The JavaScript SDK offers several
|
||||||
|
[head samplers](/docs/concepts/sampling#head-sampling).
|
||||||
|
|
||||||
|
## Default behavior
|
||||||
|
|
||||||
|
By default, all spans are sampled, and thus, 100% of traces are sampled. If you
|
||||||
|
do not need to manage data volume, don't bother setting a sampler.
|
||||||
|
|
||||||
|
## TraceIDRatioBasedSampler
|
||||||
|
|
||||||
|
When sampling, the most common head sampler to use is the
|
||||||
|
TraceIdRatioBasedSampler. It deterministically samples a percentage of traces
|
||||||
|
that you pass in as a parameter.
|
||||||
|
|
||||||
|
### Environment Variables
|
||||||
|
|
||||||
|
You can configure the TraceIdRatioBasedSampler with environment variables:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
export OTEL_TRACES_SAMPLER="traceidratio"
|
||||||
|
export OTEL_TRACES_SAMPLER_ARG="0.1"
|
||||||
|
```
|
||||||
|
|
||||||
|
This tells the SDK to sample spans such that only 10% of traces get created.
|
||||||
|
|
||||||
|
### Node.js
|
||||||
|
|
||||||
|
You can also configure the TraceIdRatioBasedSampler in code. Here's an example
|
||||||
|
for Node.js:
|
||||||
|
|
||||||
|
<!-- prettier-ignore-start -->
|
||||||
|
{{< tabpane lang=shell persistLang=false >}}
|
||||||
|
|
||||||
|
{{< tab TypeScript >}}
|
||||||
|
import { TraceIdRatioBasedSampler } from '@opentelemetry/sdk-trace-node';
|
||||||
|
|
||||||
|
const samplePercentage = 0.1;
|
||||||
|
|
||||||
|
const sdk = new NodeSDK({
|
||||||
|
// Other SDK configuration parameters go here
|
||||||
|
sampler: new TraceIdRatioBasedSampler(samplePercentage),
|
||||||
|
});
|
||||||
|
{{< /tab >}}
|
||||||
|
|
||||||
|
{{< tab JavaScript >}}
|
||||||
|
const { TraceIdRatioBasedSampler } = require('@opentelemetry/sdk-trace-node');
|
||||||
|
|
||||||
|
const samplePercentage = 0.1;
|
||||||
|
|
||||||
|
const sdk = new NodeSDK({
|
||||||
|
// Other SDK configuration parameters go here
|
||||||
|
sampler: new TraceIdRatioBasedSampler(samplePercentage),
|
||||||
|
});
|
||||||
|
{{< /tab >}}
|
||||||
|
|
||||||
|
{{< /tabpane >}}
|
||||||
|
<!-- prettier-ignore-end -->
|
||||||
|
|
||||||
|
### Browser
|
||||||
|
|
||||||
|
You can also configure the TraceIdRatioBasedSampler in code. Here's an example
|
||||||
|
for browser apps:
|
||||||
|
|
||||||
|
<!-- prettier-ignore-start -->
|
||||||
|
{{< tabpane lang=shell persistLang=false >}}
|
||||||
|
|
||||||
|
{{< tab TypeScript >}}
|
||||||
|
import { WebTracerProvider, TraceIdRatioBasedSampler } from '@opentelemetry/sdk-trace-web';
|
||||||
|
|
||||||
|
const samplePercentage = 0.1;
|
||||||
|
|
||||||
|
const provider = new WebTracerProvider({
|
||||||
|
sampler: new TraceIdRatioBasedSampler(samplePercentage),
|
||||||
|
});
|
||||||
|
{{< /tab >}}
|
||||||
|
|
||||||
|
{{< tab JavaScript >}}
|
||||||
|
const { WebTracerProvider, TraceIdRatioBasedSampler } = require('@opentelemetry/sdk-trace-web');
|
||||||
|
|
||||||
|
const samplePercentage = 0.1;
|
||||||
|
|
||||||
|
const provider = new WebTracerProvider({
|
||||||
|
sampler: new TraceIdRatioBasedSampler(samplePercentage),
|
||||||
|
});
|
||||||
|
{{< /tab >}}
|
||||||
|
|
||||||
|
{{< /tabpane >}}
|
||||||
|
<!-- prettier-ignore-end -->
|
||||||
Loading…
Reference in New Issue