elastic / elastic-otel-node

https://github.com/elastic/elastic-otel-node/tree/main/packages/opentelemetry-node#readme
Apache License 2.0
3 stars 2 forks source link

compatible sampling support #359

Open trentm opened 1 month ago

trentm commented 1 month ago

We should test whether sampling with distributed tracing works at all. Take this dev patch:

diff --git a/examples/start-elastic-sdk.js b/examples/start-elastic-sdk.js
index 99875f0..f0f0116 100644
--- a/examples/start-elastic-sdk.js
+++ b/examples/start-elastic-sdk.js
@@ -42,6 +42,9 @@ const {
     ExpressInstrumentation,
 } = require('@opentelemetry/instrumentation-express');

+const {tracing} = require('@opentelemetry/sdk-node');
+const {ParentBasedSampler, TraceIdRatioBasedSampler} = tracing;
+
 const sdk = new ElasticNodeSDK({
     serviceName: path.parse(process.argv[1]).name,
     // One can **override** completely the instrumentations provided by ElasticNodeSDK
@@ -69,6 +91,9 @@ const sdk = new ElasticNodeSDK({
         // the OTel NodeSDK, for example:
         //  new AnotherInstrumentation(),
     ],
+    sampler: new ParentBasedSampler({
+        root: new TraceIdRatioBasedSampler(0.5),
+    }),
 });