Last active
January 4, 2024 16:09
-
-
Save thecraftman/27fdc2573ba1bf6c0853fc64b7593432 to your computer and use it in GitHub Desktop.
Send Otel Node traces to Axiom
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const opentelemetry = require('@opentelemetry/sdk-node'); | |
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node'); | |
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-proto'); | |
const { BatchSpanProcessor } = require('@opentelemetry/sdk-trace-base'); | |
const { Resource } = require('@opentelemetry/resources'); | |
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions'); | |
// Initialize OTLP trace exporter | |
const traceExporter = new OTLPTraceExporter({ | |
url: 'https://api.axiom.co/v1/traces', | |
headers: { | |
'Authorization': 'Bearer $API_TOKEN', | |
'X-Axiom-Dataset': '$DATASET' | |
}, | |
}); | |
const resource = new Resource({ | |
[SemanticResourceAttributes.SERVICE_NAME]: 'node traces', | |
}); | |
const sdk = new opentelemetry.NodeSDK({ | |
spanProcessor: new BatchSpanProcessor(traceExporter), | |
resource: resource, // Add the resource here | |
instrumentations: [getNodeAutoInstrumentations()], | |
}); | |
sdk.start(); |
Thanks. I got it working it working with the pino package.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The js logs package for Otel is still under development and experimental: https://opentelemetry.io/docs/instrumentation/js/