From 60ed15ab1e96ae1b70a3ea29e18ca92fd43b2596 Mon Sep 17 00:00:00 2001 From: Phillip Carter Date: Sat, 11 Mar 2023 17:04:21 +0000 Subject: [PATCH 1/5] Add sampling doc for JS --- .../en/docs/instrumentation/js/sampling.md | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 content/en/docs/instrumentation/js/sampling.md diff --git a/content/en/docs/instrumentation/js/sampling.md b/content/en/docs/instrumentation/js/sampling.md new file mode 100644 index 000000000000..e90d3dea5a30 --- /dev/null +++ b/content/en/docs/instrumentation/js/sampling.md @@ -0,0 +1,96 @@ +--- +title: Sampling +weight: 9 +--- + +[Sampling](../../concepts/sampling/) is a process that restricts the amount of traces that are generated by a system. the JavaScript SDK offers several [head samplers](../../concepts/sampling#head-sampling). + +## Default behavior + +By default, all spans are sampled, and thus, 100% of traces are sampled. It is equivalent to setting the following: + +```js +new ParentBasedSampler({ + root: new AlwaysOnSampler(), +}) +``` + +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: + + +{{< 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 >}} + + +### Browser + +You can also configure the TraceIdRatioBasedSampler in code. Here's an example for browser apps: + + +{{< tabpane lang=shell persistLang=false >}} + +{{< tab TypeScript >}} +import { WebTracerProvider } from '@opentelemetry/sdk-trace-web'; +import { TraceIdRatioBasedSampler } from '@opentelemetry/sdk-trace-node'; + +const samplePercentage = 0.1; + +const provider = new WebTracerProvider({ + sampler: new TraceIdRatioBasedSampler(samplePercentage), +}); +{{< /tab >}} + +{{< tab JavaScript >}} +const { WebTracerProvider } = require('@opentelemetry/sdk-trace-web'); +const { TraceIdRatioBasedSampler } = require('@opentelemetry/sdk-trace-node'); + +const samplePercentage = 0.1; + +const provider = new WebTracerProvider({ + sampler: new TraceIdRatioBasedSampler(samplePercentage), +}); + +{{< /tabpane >}} + \ No newline at end of file From d8668ecae59c5b9b33428e0428d967e8c1214ddf Mon Sep 17 00:00:00 2001 From: Phillip Carter Date: Sat, 11 Mar 2023 17:08:04 +0000 Subject: [PATCH 2/5] formatting and links --- .../en/docs/instrumentation/js/sampling.md | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/content/en/docs/instrumentation/js/sampling.md b/content/en/docs/instrumentation/js/sampling.md index e90d3dea5a30..76ed8108db20 100644 --- a/content/en/docs/instrumentation/js/sampling.md +++ b/content/en/docs/instrumentation/js/sampling.md @@ -3,23 +3,28 @@ title: Sampling weight: 9 --- -[Sampling](../../concepts/sampling/) is a process that restricts the amount of traces that are generated by a system. the JavaScript SDK offers several [head samplers](../../concepts/sampling#head-sampling). +[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. It is equivalent to setting the following: +By default, all spans are sampled, and thus, 100% of traces are sampled. It is +equivalent to setting the following: ```js new ParentBasedSampler({ - root: new AlwaysOnSampler(), -}) + root: new AlwaysOnSampler(), +}); ``` 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. +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 @@ -34,7 +39,8 @@ 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: +You can also configure the TraceIdRatioBasedSampler in code. Here's an example +for Node.js: {{< tabpane lang=shell persistLang=false >}} @@ -66,7 +72,8 @@ const sdk = new NodeSDK({ ### Browser -You can also configure the TraceIdRatioBasedSampler in code. Here's an example for browser apps: +You can also configure the TraceIdRatioBasedSampler in code. Here's an example +for browser apps: {{< tabpane lang=shell persistLang=false >}} @@ -91,6 +98,7 @@ const samplePercentage = 0.1; const provider = new WebTracerProvider({ sampler: new TraceIdRatioBasedSampler(samplePercentage), }); +{{< /tab >}} {{< /tabpane >}} - \ No newline at end of file + From 930ac0bfeffdd6285cc948433ef9bcf5d78c8543 Mon Sep 17 00:00:00 2001 From: Phillip Carter Date: Sat, 11 Mar 2023 19:22:14 +0000 Subject: [PATCH 3/5] actually, don't show the default sampler equivalent --- content/en/docs/instrumentation/js/sampling.md | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/content/en/docs/instrumentation/js/sampling.md b/content/en/docs/instrumentation/js/sampling.md index 76ed8108db20..254f26e14d01 100644 --- a/content/en/docs/instrumentation/js/sampling.md +++ b/content/en/docs/instrumentation/js/sampling.md @@ -9,16 +9,8 @@ traces that are generated by a system. the JavaScript SDK offers several ## Default behavior -By default, all spans are sampled, and thus, 100% of traces are sampled. It is -equivalent to setting the following: - -```js -new ParentBasedSampler({ - root: new AlwaysOnSampler(), -}); -``` - -If you do not need to manage data volume, don't bother setting a sampler. +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 From 87bb933fe140aa767f18909de2aa2598b1fa3e65 Mon Sep 17 00:00:00 2001 From: Phillip Carter Date: Sat, 11 Mar 2023 12:04:39 -0800 Subject: [PATCH 4/5] Update content/en/docs/instrumentation/js/sampling.md Co-authored-by: Patrice Chalin --- content/en/docs/instrumentation/js/sampling.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/en/docs/instrumentation/js/sampling.md b/content/en/docs/instrumentation/js/sampling.md index 254f26e14d01..5a75a5cc2f4f 100644 --- a/content/en/docs/instrumentation/js/sampling.md +++ b/content/en/docs/instrumentation/js/sampling.md @@ -4,7 +4,7 @@ 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 +traces that are generated by a system. The JavaScript SDK offers several [head samplers](/docs/concepts/sampling#head-sampling). ## Default behavior From 76699b7751daa599abeeee1c5e5ada99f2725b40 Mon Sep 17 00:00:00 2001 From: Phillip Carter Date: Mon, 13 Mar 2023 07:33:53 -0700 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: Marc Pichler --- content/en/docs/instrumentation/js/sampling.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/content/en/docs/instrumentation/js/sampling.md b/content/en/docs/instrumentation/js/sampling.md index 5a75a5cc2f4f..31aa6a339700 100644 --- a/content/en/docs/instrumentation/js/sampling.md +++ b/content/en/docs/instrumentation/js/sampling.md @@ -71,8 +71,7 @@ for browser apps: {{< tabpane lang=shell persistLang=false >}} {{< tab TypeScript >}} -import { WebTracerProvider } from '@opentelemetry/sdk-trace-web'; -import { TraceIdRatioBasedSampler } from '@opentelemetry/sdk-trace-node'; +import { WebTracerProvider, TraceIdRatioBasedSampler } from '@opentelemetry/sdk-trace-web'; const samplePercentage = 0.1; @@ -82,8 +81,7 @@ const provider = new WebTracerProvider({ {{< /tab >}} {{< tab JavaScript >}} -const { WebTracerProvider } = require('@opentelemetry/sdk-trace-web'); -const { TraceIdRatioBasedSampler } = require('@opentelemetry/sdk-trace-node'); +const { WebTracerProvider, TraceIdRatioBasedSampler } = require('@opentelemetry/sdk-trace-web'); const samplePercentage = 0.1;