forked from denoland/deno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(runtime): remove public OTEL trace API (denoland#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.
- Loading branch information
1 parent
106d47a
commit 594a998
Showing
22 changed files
with
1,079 additions
and
604 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1252,80 +1252,53 @@ declare namespace Deno { | |
} | ||
|
||
/** | ||
* **UNSTABLE**: New API, yet to be vetted. | ||
* | ||
* 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`](https://opentelemetry.io/docs/languages/js/). | ||
* 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`](https://jsr.io/@deno/otel) package. | ||
* | ||
* @example Using OpenTelemetry API to create custom traces | ||
* ```ts,ignore | ||
* import { trace } from "npm:@opentelemetry/api@1"; | ||
* import "jsr:@deno/[email protected]/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; | ||
* }); | ||
* ``` | ||
* | ||
* @category Telemetry | ||
* @experimental | ||
*/ | ||
export namespace tracing { | ||
/** | ||
* Whether tracing is enabled. | ||
* @category Telemetry | ||
* @experimental | ||
*/ | ||
export const enabled: boolean; | ||
|
||
/** | ||
* Allowed attribute type. | ||
* @category Telemetry | ||
* @experimental | ||
*/ | ||
export type AttributeValue = string | number | boolean | bigint; | ||
|
||
/** | ||
* A tracing span. | ||
* @category Telemetry | ||
* @experimental | ||
*/ | ||
export class Span implements Disposable { | ||
readonly traceId: string; | ||
readonly spanId: string; | ||
readonly parentSpanId: string; | ||
readonly kind: string; | ||
readonly name: string; | ||
readonly startTime: number; | ||
readonly endTime: number; | ||
readonly status: null | { code: 1 } | { code: 2; message: string }; | ||
readonly attributes: Record<string, AttributeValue>; | ||
readonly traceFlags: number; | ||
|
||
/** | ||
* Construct a new Span and enter it as the "current" span. | ||
*/ | ||
constructor( | ||
name: string, | ||
kind?: "internal" | "server" | "client" | "producer" | "consumer", | ||
); | ||
|
||
/** | ||
* Set an attribute on this span. | ||
*/ | ||
setAttribute( | ||
name: string, | ||
value: AttributeValue, | ||
): void; | ||
|
||
/** | ||
* Enter this span as the "current" span. | ||
*/ | ||
enter(): void; | ||
|
||
/** | ||
* Exit this span as the "current" span and restore the previous one. | ||
*/ | ||
exit(): void; | ||
|
||
/** | ||
* End this span, and exit it as the "current" span. | ||
*/ | ||
end(): void; | ||
|
||
[Symbol.dispose](): void; | ||
|
||
/** | ||
* Get the "current" span, if one exists. | ||
*/ | ||
static current(): Span | undefined | null; | ||
} | ||
|
||
export namespace telemetry { | ||
/** | ||
* A SpanExporter compatible with OpenTelemetry.js | ||
* https://open-telemetry.github.io/opentelemetry-js/interfaces/_opentelemetry_sdk_trace_base.SpanExporter.html | ||
|
@@ -1345,14 +1318,6 @@ declare namespace Deno { | |
export {}; // only export exports | ||
} | ||
|
||
/** | ||
* @category Telemetry | ||
* @experimental | ||
*/ | ||
export namespace metrics { | ||
export {}; // only export exports | ||
} | ||
|
||
export {}; // only export exports | ||
} | ||
|
||
|
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.