(
name: string,
fn: (span: Span) => Promise<T>,
options?: SpanOptions,
ctx?: Context
)
| 52 | } |
| 53 | |
| 54 | startActiveSpan<T>( |
| 55 | name: string, |
| 56 | fn: (span: Span) => Promise<T>, |
| 57 | options?: SpanOptions, |
| 58 | ctx?: Context |
| 59 | ): Promise<T> { |
| 60 | const parentContext = ctx ?? context.active(); |
| 61 | |
| 62 | const attributes = options?.attributes ?? {}; |
| 63 | |
| 64 | return this.tracer.startActiveSpan( |
| 65 | name, |
| 66 | { |
| 67 | ...options, |
| 68 | attributes, |
| 69 | startTime: clock.preciseNow(), |
| 70 | }, |
| 71 | parentContext, |
| 72 | async (span) => { |
| 73 | this.tracer |
| 74 | .startSpan( |
| 75 | name, |
| 76 | { |
| 77 | ...options, |
| 78 | attributes: { |
| 79 | ...attributes, |
| 80 | [SemanticInternalAttributes.SPAN_PARTIAL]: true, |
| 81 | [SemanticInternalAttributes.SPAN_ID]: span.spanContext().spanId, |
| 82 | }, |
| 83 | }, |
| 84 | parentContext |
| 85 | ) |
| 86 | .end(); |
| 87 | |
| 88 | try { |
| 89 | return await fn(span); |
| 90 | } catch (e) { |
| 91 | if (typeof e === "string" || e instanceof Error) { |
| 92 | span.recordException(e); |
| 93 | } |
| 94 | |
| 95 | span.setStatus({ code: SpanStatusCode.ERROR }); |
| 96 | |
| 97 | throw e; |
| 98 | } finally { |
| 99 | span.end(clock.preciseNow()); |
| 100 | } |
| 101 | } |
| 102 | ); |
| 103 | } |
| 104 | |
| 105 | startSpan(name: string, options?: SpanOptions, ctx?: Context) { |
| 106 | const parentContext = ctx ?? context.active(); |
no test coverage detected