Public documentation
Documentation indexRead as MarkdownJavaScript and TypeScript on Node.js
Languages · Shared configuration · Verification
This example targets a supported Node.js LTS runtime and the compatible OpenTelemetry 2.11.0 / 0.222.0 release family. Upstream traces and metrics are Stable; logs are Development as checked on 2026-09-28. Browser applications should use Corridora RUM.
Install
mkdir corridora-node
cd corridora-node
npm init -y
npm install --save-exact @opentelemetry/api@1.9.0 \
@opentelemetry/sdk-node@0.222.0 \
@opentelemetry/resources@2.11.0 \
@opentelemetry/exporter-trace-otlp-proto@0.222.0
export OTEL_EXPORTER_OTLP_ENDPOINT='http://127.0.0.1:4318'
export OTEL_METRICS_EXPORTER='none'
export OTEL_LOGS_EXPORTER='none'
unset OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
unset OTEL_EXPORTER_OTLP_HEADERS OTEL_EXPORTER_OTLP_TRACES_HEADERS
Start the local Collector. The otlp-proto exporter sends HTTP/protobuf. The similarly named otlp-http JavaScript package sends OTLP JSON; both formats are accepted by Corridora, but use one consistently.
Initialize and emit
Save this CommonJS example as app.cjs:
const { trace } = require('@opentelemetry/api');
const { NodeSDK } = require('@opentelemetry/sdk-node');
const { resourceFromAttributes } = require('@opentelemetry/resources');
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-proto');
const sdk = new NodeSDK({
resource: resourceFromAttributes({
'service.name': 'corridora-node',
'service.version': 'example-1',
'deployment.environment.name': 'development',
}),
traceExporter: new OTLPTraceExporter(),
});
sdk.start();
async function main() {
const tracer = trace.getTracer('corridora.examples.node');
await tracer.startActiveSpan('example.calculate', async (span) => {
try {
span.setAttribute('example.language', 'javascript');
await new Promise((resolve) => setTimeout(resolve, 50));
console.log(`trace_id=${span.spanContext().traceId}`);
} finally {
span.end();
}
});
}
main()
.catch((error) => { console.error(error); process.exitCode = 1; })
.finally(async () => {
try { await sdk.shutdown(); }
catch (error) { console.error(error); process.exitCode = 1; }
});
node app.cjs
Keep package-lock.json. TypeScript uses the same SDK APIs and packages; compile with your project's TypeScript configuration and preload the compiled initialization before importing instrumented application modules. The CommonJS sample avoids requiring a TypeScript runner or ESM loader just to verify export.
Automatic instrumentation and context
The example creates one manual span. For supported framework/client instrumentation, install a compatible @opentelemetry/auto-instrumentations-node release and pass instrumentations: [getNodeAutoInstrumentations()] to NodeSDK, importing the function from that package. Its version series is independent; resolve and lock a release whose peer dependencies match this SDK family.
Move SDK setup into a separate instrumentation.cjs and start CommonJS applications with node --require ./instrumentation.cjs server.cjs. The preload must finish before HTTP, framework, and database modules are loaded. ESM applications require the instrumentation packages' ESM loading support; changing the filename alone does not make CommonJS preload instructions equivalent.
Use startActiveSpan across the complete asynchronous operation, then end the span in finally. Avoid process.exit() immediately after creating a span: it can terminate before asynchronous export completes. A long-running server should stop accepting requests, await work, then await sdk.shutdown() on its shutdown path.
Supported HTTP instrumentation propagates traceparent. Custom messaging needs explicit propagation and the consumer must extract the producer's context. console.log() remains console output; it is not automatically an OTLP log. A supported Pino/Winston instrumentation or logging bridge can correlate logs, but forwarding logs also requires a logs provider and exporter.
Additional signals and direct export
Metrics require @opentelemetry/sdk-metrics, a periodic reader, and the matching OTLP metric exporter. Logs require @opentelemetry/sdk-logs, an OTLP log exporter, and a logging bridge. Keep stable packages on the same stable release family and experimental packages on the same experimental family. This sample deliberately disables both signals through the SDK environment settings.
For direct Corridora export, replace the base endpoint with your HTTPS ingest endpoint and set OTEL_EXPORTER_OTLP_HEADERS="X-CORRIDORA-KEY=${CORRIDORA_INGEST_KEY}" using the key-loading instructions in shared configuration. A url passed directly to OTLPTraceExporter overrides endpoint environment settings and must include /v1/traces.
Verify
Search for service corridora-node and the printed trace ID. Expect example.calculate lasting roughly 50 milliseconds. No application log or metric is expected from this sample. If a real application has no framework spans, check initialization order before changing sampling. If the manual sample is absent, check exporter errors, Collector receipt, process shutdown, and the shared verification steps.