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 trace context propagation
between native Deno APIs (like Deno.serve
or fetch
) and custom user
code. Deno also provides APIs that allow exporting custom telemetry data
via the same OTLP channel used by the Deno runtime. This is done using the
jsr:@deno/otel
package.
Using OpenTelemetry API to create custom traces
Using OpenTelemetry API to create custom traces
import { trace } from "npm:@opentelemetry/api@1";
import "jsr:@deno/otel@0.0.2/register";
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 SpanExporter compatible with OpenTelemetry.js https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_sdk_trace_base.SpanExporter.html