APIs for working with the OpenTelemetry observability framework. Deno can export traces, metrics, and logs to OpenTelemetry compatible backends via the OTLP protocol.
Deno automatically instruments the runtime with OpenTelemetry traces and
metrics. This data is exported via OTLP to OpenTelemetry compatible
backends. User logs from the console
API are exported as OpenTelemetry
logs via OTLP.
User code can also create custom traces, metrics, and logs using the
OpenTelemetry API. This is done using the official OpenTelemetry package
for JavaScript:
npm:@opentelemetry/api
.
Deno integrates with this package to provide tracing, metrics, and trace
context propagation between native Deno APIs (like Deno.serve
or fetch
)
and custom user code. Deno automatically registers the providers with the
OpenTelemetry API, so users can start creating custom traces, metrics, and
logs without any additional setup.
Using OpenTelemetry API to create custom traces
Using OpenTelemetry API to create custom traces
import { trace } from "npm:@opentelemetry/api@1";
const tracer = trace.getTracer("example-tracer");
async function doWork() {
return tracer.startActiveSpan("doWork", async (span) => {
span.setAttribute("key", "value");
await new Promise((resolve) => setTimeout(resolve, 1000));
span.end();
});
}
Deno.serve(async (req) => {
await doWork();
const resp = await fetch("https://example.com");
return resp;
});
A ContextManager compatible with OpenTelemetry.js https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_api.ContextManager.html
A MeterProvider compatible with OpenTelemetry.js https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_api.MeterProvider.html
A TracerProvider compatible with OpenTelemetry.js https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_api.TracerProvider.html