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