UNPKG

@graphql-hive/plugin-opentelemetry

Version:
37 lines (34 loc) 1.07 kB
import { context } from '@opentelemetry/api'; export * from '@opentelemetry/api'; const defaultDelegate = { getActiveContext: () => context.active(), getExecutionRequestContext: () => context.active(), getHttpContext: () => context.active(), getOperationContext: () => context.active(), tracer: void 0 }; let delegate = defaultDelegate; const hive = { getActiveContext: (payload) => delegate.getActiveContext(payload), getExecutionRequestContext: (executionRequest) => delegate.getExecutionRequestContext(executionRequest), getHttpContext: (request) => delegate.getHttpContext(request), getOperationContext: (context2) => delegate.getOperationContext(context2), get tracer() { return delegate.tracer; }, setPluginUtils: (utils, log) => { if (delegate == defaultDelegate) { delegate = utils; return true; } else { log?.warn( "OpenTelemetry plugin's utils are already registered. This is a no-op" ); return false; } }, disable() { delegate = defaultDelegate; } }; export { hive };