Skip to content

Commit

Permalink
Added OpenTelemetry detectors from resources
Browse files Browse the repository at this point in the history
This iwll help us better identify/detect resources
  • Loading branch information
saidsef committed Aug 14, 2023
1 parent 886c68b commit f6bdc14
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 144 deletions.
27 changes: 14 additions & 13 deletions libs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* limitations under the License.
*/

const { CompositePropagator, W3CBaggagePropagator, W3CTraceContextPropagator } = require('@opentelemetry/core');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { BatchSpanProcessor } = require('@opentelemetry/sdk-trace-base');
Expand All @@ -27,7 +28,6 @@ const { Resource } = require('@opentelemetry/resources');
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { AwsInstrumentation } = require('@opentelemetry/instrumentation-aws-sdk');
const { PinoInstrumentation } = require('@opentelemetry/instrumentation-pino');
const { JaegerPropagator } = require('@opentelemetry/propagator-jaeger');

diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO);

Expand All @@ -39,7 +39,7 @@ function setupTracing(serviceName, appName="application", endpoint=null) {
[SemanticResourceAttributes.CONTAINER_NAME]: serviceName,
[SemanticResourceAttributes.HOST_NAME]: serviceName,
instrumentationLibrarySemanticConvention: true,
}),
})
});

// Configure exporter with the Collector endpoint - uses gRPC
Expand All @@ -51,25 +51,23 @@ function setupTracing(serviceName, appName="application", endpoint=null) {
// Register the span processor with the tracer provider
provider.addSpanProcessor(new BatchSpanProcessor(new OTLPTraceExporter(exportOptions)));

// Ignore spans from static assets.
const ignoreIncomingRequestHook = (req) => {
const isStaticAsset = !!req.url.match(/^\/metrics|\/healthz.*$/);
return isStaticAsset;
}

// Register instrumentations
registerInstrumentations({
tracerProvider: provider,
instrumentations: [
new ExpressInstrumentation({
ignoreIncomingRequestHook(req) {
// Ignore spans from static assets.
const isStaticAsset = !!req.url.match(/^\/metrics.*$/);
return isStaticAsset;
}
ignoreIncomingRequestHook,
}),
new HttpInstrumentation({
requireParentforOutgoingSpans: false,
requireParentforIncomingSpans: false,
ignoreIncomingRequestHook(req) {
// Ignore spans from static assets.
const isStaticAsset = !!req.url.match(/^\/metrics.*$/);
return isStaticAsset;
}
ignoreIncomingRequestHook,
}),
new AwsInstrumentation({
sqsExtractContextPropagationFromPayload: true
Expand All @@ -83,7 +81,10 @@ function setupTracing(serviceName, appName="application", endpoint=null) {
});

// Initialize the tracer provider
provider.register({propagator: new JaegerPropagator()});
provider.register({
propagator: new CompositePropagator({
propagators: [new W3CBaggagePropagator(), new W3CTraceContextPropagator()],
})});

// Return the tracer for the service
return provider.getTracer(serviceName);
Expand Down
Loading

0 comments on commit f6bdc14

Please sign in to comment.