( headers: Headers, spanName: string, attributes: Record<string, string | number | boolean> | undefined, fn: (span: Span) => Promise<T> )
| 219 | // Wrap an inbound handler that Go called into so its span parents |
| 220 | // under the Go-side trace (via `traceparent`). |
| 221 | export async function withIncomingGoSpan<T>( |
| 222 | headers: Headers, |
| 223 | spanName: string, |
| 224 | attributes: Record<string, string | number | boolean> | undefined, |
| 225 | fn: (span: Span) => Promise<T> |
| 226 | ): Promise<T> { |
| 227 | const parentContext = contextFromRequestHeaders(headers) |
| 228 | const tracer = getTracer() |
| 229 | return tracer.startActiveSpan( |
| 230 | spanName, |
| 231 | { kind: SpanKind.SERVER, attributes }, |
| 232 | parentContext, |
| 233 | async (span) => { |
| 234 | try { |
| 235 | const result = await fn(span) |
| 236 | span.setStatus({ code: SpanStatusCode.OK }) |
| 237 | return result |
| 238 | } catch (error) { |
| 239 | markSpanForError(span, error) |
| 240 | throw error |
| 241 | } finally { |
| 242 | span.end() |
| 243 | } |
| 244 | } |
| 245 | ) |
| 246 | } |
| 247 | |
| 248 | // Wrap a copilot-lifecycle op in an OTel span. Pass `parentContext` |
| 249 | // explicitly when AsyncLocalStorage-tracked context can be dropped |
no test coverage detected