UNPKG

inngest

Version:

Official SDK for Inngest.com. Inngest is the reliability layer for modern applications. Inngest combines durable execution, events, and queues into a zero-infra platform with built-in observability.

52 lines (50 loc) 2.91 kB
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs'); const require_processor = require('./processor.cjs'); let __opentelemetry_api = require("@opentelemetry/api"); let __opentelemetry_auto_instrumentations_node = require("@opentelemetry/auto-instrumentations-node"); let __opentelemetry_context_async_hooks = require("@opentelemetry/context-async-hooks"); let __opentelemetry_instrumentation = require("@opentelemetry/instrumentation"); let __opentelemetry_sdk_trace_base = require("@opentelemetry/sdk-trace-base"); let __traceloop_instrumentation_anthropic = require("@traceloop/instrumentation-anthropic"); //#region src/components/execution/otel/util.ts const createProvider = (_behaviour, instrumentations = []) => { const processor = new require_processor.InngestSpanProcessor(); const p = new __opentelemetry_sdk_trace_base.BasicTracerProvider({ spanProcessors: [processor] }); (0, __opentelemetry_instrumentation.registerInstrumentations)({ instrumentations: [ ...instrumentations, ...(0, __opentelemetry_auto_instrumentations_node.getNodeAutoInstrumentations)(), new __traceloop_instrumentation_anthropic.AnthropicInstrumentation() ] }); __opentelemetry_api.trace.setGlobalTracerProvider(p); __opentelemetry_api.context.setGlobalContextManager(new __opentelemetry_context_async_hooks.AsyncHooksContextManager().enable()); return { success: true, processor }; }; /** * Attempts to extend the existing OTel provider with our processor. Returns true * if the provider was extended, false if it was not. */ const extendProvider = (behaviour) => { const globalProvider = __opentelemetry_api.trace.getTracerProvider(); if (!globalProvider) { if (behaviour !== "auto") console.warn("No existing OTel provider found and behaviour is \"extendProvider\". Inngest's OTel middleware will not work. Either allow the middleware to create a provider by setting `behaviour: \"createProvider\"` or `behaviour: \"auto\"`, or make sure that the provider is created and imported before the middleware is used."); return { success: false }; } const existingProvider = "getDelegate" in globalProvider && typeof globalProvider.getDelegate === "function" ? globalProvider.getDelegate() : globalProvider; if (!existingProvider || !("addSpanProcessor" in existingProvider) || typeof existingProvider.addSpanProcessor !== "function") { if (behaviour !== "auto") console.warn("Existing OTel provider is not a BasicTracerProvider. Inngest's OTel middleware will not work, as it can only extend an existing processor if it's a BasicTracerProvider."); return { success: false }; } const processor = new require_processor.InngestSpanProcessor(); existingProvider.addSpanProcessor(processor); return { success: true, processor }; }; //#endregion exports.createProvider = createProvider; exports.extendProvider = extendProvider; //# sourceMappingURL=util.cjs.map