mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 19:08:15 +00:00
feat(unstable): Instrument fetch (#27057)
Add basic tracing to `fetch`. Also fix span kinds so that we can differentiate fetch and serve.
This commit is contained in:
parent
08a56763d4
commit
d59bd5e8c9
5 changed files with 223 additions and 90 deletions
|
@ -41,6 +41,8 @@ const { AsyncVariable, setAsyncContext } = core;
|
|||
let TRACING_ENABLED = false;
|
||||
let DETERMINISTIC = false;
|
||||
|
||||
// Note: These start at 0 in the JS library,
|
||||
// but start at 1 when serialized with JSON.
|
||||
enum SpanKind {
|
||||
INTERNAL = 0,
|
||||
SERVER = 1,
|
||||
|
@ -91,6 +93,11 @@ interface Attributes {
|
|||
|
||||
type SpanAttributes = Attributes;
|
||||
|
||||
interface SpanOptions {
|
||||
attributes?: Attributes;
|
||||
kind?: SpanKind;
|
||||
}
|
||||
|
||||
interface Link {
|
||||
context: SpanContext;
|
||||
attributes?: SpanAttributes;
|
||||
|
@ -354,7 +361,7 @@ export class Span {
|
|||
|
||||
#recording = TRACING_ENABLED;
|
||||
|
||||
#kind: number = 0;
|
||||
#kind: number = SpanKind.INTERNAL;
|
||||
#name: string;
|
||||
#startTime: number;
|
||||
#status: { code: number; message?: string } | null = null;
|
||||
|
@ -429,7 +436,7 @@ export class Span {
|
|||
|
||||
constructor(
|
||||
name: string,
|
||||
attributes?: Attributes,
|
||||
options?: SpanOptions,
|
||||
) {
|
||||
if (!this.isRecording) {
|
||||
this.#name = "";
|
||||
|
@ -442,7 +449,8 @@ export class Span {
|
|||
|
||||
this.#name = name;
|
||||
this.#startTime = now();
|
||||
this.#attributes = attributes ?? { __proto__: null } as never;
|
||||
this.#attributes = options?.attributes ?? { __proto__: null } as never;
|
||||
this.#kind = options?.kind ?? SpanKind.INTERNAL;
|
||||
|
||||
const currentSpan: Span | {
|
||||
spanContext(): { traceId: string; spanId: string };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue