| 36 | |
| 37 | /** @internal */ |
| 38 | export class NativeSpan implements Tracer.Span { |
| 39 | readonly _tag = "Span" |
| 40 | readonly spanId: string |
| 41 | readonly traceId: string = "native" |
| 42 | readonly sampled = true |
| 43 | |
| 44 | status: Tracer.SpanStatus |
| 45 | attributes: Map<string, unknown> |
| 46 | events: Array<[name: string, startTime: bigint, attributes: Record<string, unknown>]> = [] |
| 47 | links: Array<Tracer.SpanLink> |
| 48 | |
| 49 | constructor( |
| 50 | readonly name: string, |
| 51 | readonly parent: Option.Option<Tracer.AnySpan>, |
| 52 | readonly context: Context.Context<never>, |
| 53 | links: Iterable<Tracer.SpanLink>, |
| 54 | readonly startTime: bigint, |
| 55 | readonly kind: Tracer.SpanKind |
| 56 | ) { |
| 57 | this.status = { |
| 58 | _tag: "Started", |
| 59 | startTime |
| 60 | } |
| 61 | this.attributes = new Map() |
| 62 | this.traceId = parent._tag === "Some" ? parent.value.traceId : randomHexString(32) |
| 63 | this.spanId = randomHexString(16) |
| 64 | this.links = Array.from(links) |
| 65 | } |
| 66 | |
| 67 | end(endTime: bigint, exit: Exit.Exit<unknown, unknown>): void { |
| 68 | this.status = { |
| 69 | _tag: "Ended", |
| 70 | endTime, |
| 71 | exit, |
| 72 | startTime: this.status.startTime |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | attribute(key: string, value: unknown): void { |
| 77 | this.attributes.set(key, value) |
| 78 | } |
| 79 | |
| 80 | event(name: string, startTime: bigint, attributes?: Record<string, unknown>): void { |
| 81 | this.events.push([name, startTime, attributes ?? {}]) |
| 82 | } |
| 83 | |
| 84 | addLinks(links: ReadonlyArray<Tracer.SpanLink>): void { |
| 85 | // eslint-disable-next-line no-restricted-syntax |
| 86 | this.links.push(...links) |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | /** @internal */ |
| 91 | export const nativeTracer: Tracer.Tracer = make({ |
nothing calls this directly
no outgoing calls
no test coverage detected