| 52 | |
| 53 | export const tracingCollectorContext = { |
| 54 | getActive(): TracingCollector | undefined { |
| 55 | const collector = context.active().getValue(TRACING_COLLECTOR_KEY) |
| 56 | |
| 57 | if (collector === undefined) { |
| 58 | return undefined |
| 59 | } |
| 60 | |
| 61 | if (collector instanceof TracingCollector) { |
| 62 | return collector |
| 63 | } |
| 64 | |
| 65 | throw new Error('Active tracing collector is not an instance of TracingCollector') |
| 66 | }, |
| 67 | |
| 68 | withActive<T>(collector: TracingCollector, fn: () => T): T { |
| 69 | return context.with(context.active().setValue(TRACING_COLLECTOR_KEY, collector), fn) |