Skip to content

Commit

Permalink
wait for otel detectors
Browse files Browse the repository at this point in the history
  • Loading branch information
robotastic committed Sep 14, 2024
1 parent 8950f5a commit d0ffb84
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
27 changes: 27 additions & 0 deletions backend/agents/otel-tracing.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ const { TraceIdRatioBasedSampler } = require('@opentelemetry/sdk-trace-node');
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http');
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
const { diag, DiagConsoleLogger, DiagLogLevel } = require('@opentelemetry/api');
const {
Detector,
DetectorSync,
IResource,
ResourceDetectionConfig,
envDetectorSync,
hostDetectorSync,
processDetectorSync,
} = require("@opentelemetry/resources")
// const {
// dockerCGroupV1Detector,
// } = require('@opentelemetry/resource-detector-docker');
Expand All @@ -19,6 +28,19 @@ console.log("OTEL_EXPORTER_OTLP_HEADERS: " + process.env.OTEL_EXPORTER_OTLP_HEAD
console.log("OTEL_SERVICE_NAME: " + process.env.OTEL_SERVICE_NAME);


// from https://github.com/open-telemetry/opentelemetry-js/issues/4638
// this is a workaround to wait for async attributes to be resolved
function awaitAttributes(detector){
return {
async detect(config) {
const resource = detector.detect(config)
await resource.waitForAsyncAttributes()

return resource
},
}
}

const samplePercentage = 0.05;

const sdk = new opentelemetry.NodeSDK({
Expand All @@ -36,6 +58,11 @@ const sdk = new opentelemetry.NodeSDK({
},
}),
],
resourceDetectors: [
awaitAttributes(envDetectorSync),
awaitAttributes(processDetectorSync),
awaitAttributes(hostDetectorSync),
],
//resourceDetectors: [dockerCGroupV1Detector],
});

Expand Down
1 change: 1 addition & 0 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@aws-sdk/credential-provider-process": "^3.306.0",
"@aws-sdk/credential-providers": "^3.309.0",
"@opentelemetry/auto-instrumentations-node": "^0.50.0",
"@opentelemetry/resources": "^1.26.0",
"@smithy/node-http-handler": "^3.1.4",
"adm-zip": "^0.5.10",
"axios": "1.3.5",
Expand Down

0 comments on commit d0ffb84

Please sign in to comment.