From 594a99817cbe44553b2c288578fbba8e1e9c1907 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 19 Nov 2024 00:55:22 +0100 Subject: feat(runtime): remove public OTEL trace API (#26854) This PR removes the public Deno.tracing.Span API. We are not confident we can ship an API that is better than the `@opentelemetry/api` API, because V8 CPED does not support us using `using` to manage span context. If this changes, we can revisit this decision. For now, users wanting custom spans can instrument their code using the `@opentelemetry/api` API and `@deno/otel`. This PR also speeds up the OTEL trace generation by a 30% by using Uint8Array instead of strings for the trace ID and span ID. --- tests/specs/cli/otel_basic/basic.out | 18 +++++++++--------- tests/specs/cli/otel_basic/basic.ts | 24 +++++++++++++++++------- tests/specs/cli/otel_basic/main.ts | 2 +- 3 files changed, 27 insertions(+), 17 deletions(-) (limited to 'tests/specs/cli/otel_basic') diff --git a/tests/specs/cli/otel_basic/basic.out b/tests/specs/cli/otel_basic/basic.out index 3f0554f96..3745cb7f3 100644 --- a/tests/specs/cli/otel_basic/basic.out +++ b/tests/specs/cli/otel_basic/basic.out @@ -1,10 +1,10 @@ { "spans": [ { - "traceId": "00000000000000000000000000000002", - "spanId": "0000000000000003", + "traceId": "10000000000000000000000000000002", + "spanId": "1000000000000003", "traceState": "", - "parentSpanId": "0000000000000001", + "parentSpanId": "1000000000000001", "flags": 1, "name": "inner span", "kind": 1, @@ -22,8 +22,8 @@ } }, { - "traceId": "00000000000000000000000000000002", - "spanId": "0000000000000001", + "traceId": "10000000000000000000000000000002", + "spanId": "1000000000000001", "traceState": "", "parentSpanId": "", "flags": 1, @@ -55,8 +55,8 @@ "attributes": [], "droppedAttributesCount": 0, "flags": 1, - "traceId": "00000000000000000000000000000002", - "spanId": "0000000000000003" + "traceId": "10000000000000000000000000000002", + "spanId": "1000000000000003" }, { "timeUnixNano": "0", @@ -69,8 +69,8 @@ "attributes": [], "droppedAttributesCount": 0, "flags": 1, - "traceId": "00000000000000000000000000000002", - "spanId": "0000000000000003" + "traceId": "10000000000000000000000000000002", + "spanId": "1000000000000003" } ] } diff --git a/tests/specs/cli/otel_basic/basic.ts b/tests/specs/cli/otel_basic/basic.ts index 5a178794a..5c4ae43cd 100644 --- a/tests/specs/cli/otel_basic/basic.ts +++ b/tests/specs/cli/otel_basic/basic.ts @@ -1,10 +1,17 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +import { trace } from "npm:@opentelemetry/api@1.9.0"; +import "jsr:@deno/otel@0.0.2/register"; + +const tracer = trace.getTracer("example-tracer"); + async function inner() { - using _span = new Deno.tracing.Span("inner span"); - console.log("log 1"); - await 1; - console.log("log 2"); + await tracer.startActiveSpan("inner span", async (span) => { + console.log("log 1"); + await 1; + console.log("log 2"); + span.end(); + }); } const server = Deno.serve({ @@ -17,8 +24,11 @@ const server = Deno.serve({ } }, handler: async (_req) => { - using _span = new Deno.tracing.Span("outer span"); - await inner(); - return new Response(null, { status: 200 }); + return await tracer.startActiveSpan("outer span", async (span) => { + await inner(); + const resp = new Response(null, { status: 200 }); + span.end(); + return resp; + }); }, }); diff --git a/tests/specs/cli/otel_basic/main.ts b/tests/specs/cli/otel_basic/main.ts index 6c49462a0..5415a7437 100644 --- a/tests/specs/cli/otel_basic/main.ts +++ b/tests/specs/cli/otel_basic/main.ts @@ -10,7 +10,7 @@ const server = Deno.serve( port: 0, onListen({ port }) { const command = new Deno.Command(Deno.execPath(), { - args: ["run", "-A", "--unstable-otel", Deno.args[0]], + args: ["run", "-A", "-q", "--unstable-otel", Deno.args[0]], env: { OTEL_EXPORTER_OTLP_PROTOCOL: "http/json", OTEL_EXPORTER_OTLP_ENDPOINT: `http://localhost:${port}`, -- cgit v1.2.3