( tracer: Tracer, engineSpan: EngineSpan, allSpans: EngineSpan[], linkIds: Map<string, string>, ignoreSpanTypes: (string | RegExp)[], )
| 106 | } |
| 107 | |
| 108 | function dispatchEngineSpan( |
| 109 | tracer: Tracer, |
| 110 | engineSpan: EngineSpan, |
| 111 | allSpans: EngineSpan[], |
| 112 | linkIds: Map<string, string>, |
| 113 | ignoreSpanTypes: (string | RegExp)[], |
| 114 | ) { |
| 115 | if (shouldIgnoreSpan(engineSpan.name, ignoreSpanTypes)) return |
| 116 | |
| 117 | const spanOptions = { |
| 118 | attributes: engineSpan.attributes as Attributes, |
| 119 | kind: engineSpanKindToOtelSpanKind(engineSpan.kind), |
| 120 | startTime: engineSpan.startTime, |
| 121 | } satisfies SpanOptions |
| 122 | |
| 123 | tracer.startActiveSpan(engineSpan.name, spanOptions, (span) => { |
| 124 | linkIds.set(engineSpan.id, span.spanContext().spanId) |
| 125 | |
| 126 | if (engineSpan.links) { |
| 127 | span.addLinks( |
| 128 | engineSpan.links.flatMap((link) => { |
| 129 | const linkedId = linkIds.get(link) |
| 130 | if (!linkedId) { |
| 131 | return [] |
| 132 | } |
| 133 | return { |
| 134 | context: { |
| 135 | spanId: linkedId, |
| 136 | traceId: span.spanContext().traceId, |
| 137 | traceFlags: span.spanContext().traceFlags, |
| 138 | }, |
| 139 | } |
| 140 | }), |
| 141 | ) |
| 142 | } |
| 143 | |
| 144 | const children = allSpans.filter((s) => s.parentId === engineSpan.id) |
| 145 | for (const child of children) { |
| 146 | dispatchEngineSpan(tracer, child, allSpans, linkIds, ignoreSpanTypes) |
| 147 | } |
| 148 | |
| 149 | span.end(engineSpan.endTime) |
| 150 | }) |
| 151 | } |
| 152 | |
| 153 | function endSpan<T>(span: Span, result: T): T { |
| 154 | if (isPromiseLike(result)) { |
no test coverage detected