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.
1 lines • 4.43 kB
Source Map (JSON)
{"version":3,"file":"util.cjs","names":["InngestSpanProcessor","BasicTracerProvider","AnthropicInstrumentation","AsyncHooksContextManager","trace"],"sources":["../../../../src/components/execution/otel/util.ts"],"sourcesContent":["import { context, trace } from \"@opentelemetry/api\";\nimport { getNodeAutoInstrumentations } from \"@opentelemetry/auto-instrumentations-node\";\nimport { AsyncHooksContextManager } from \"@opentelemetry/context-async-hooks\";\nimport {\n type Instrumentation,\n registerInstrumentations,\n} from \"@opentelemetry/instrumentation\";\nimport { BasicTracerProvider } from \"@opentelemetry/sdk-trace-base\";\nimport { AnthropicInstrumentation } from \"@traceloop/instrumentation-anthropic\";\nimport { InngestSpanProcessor } from \"./processor.ts\";\n\nexport type Behaviour = \"createProvider\" | \"extendProvider\" | \"off\" | \"auto\";\nexport type Instrumentations = (Instrumentation | Instrumentation[])[];\n\nexport const createProvider = (\n _behaviour: Behaviour,\n instrumentations: Instrumentations | undefined = [],\n): { success: true; processor: InngestSpanProcessor } | { success: false } => {\n // TODO Check if there's an existing provider\n const processor = new InngestSpanProcessor();\n\n const p = new BasicTracerProvider({\n spanProcessors: [processor],\n });\n\n const instrList: Instrumentations = [\n ...instrumentations,\n ...getNodeAutoInstrumentations(),\n new AnthropicInstrumentation(),\n ];\n\n registerInstrumentations({\n instrumentations: instrList,\n });\n\n trace.setGlobalTracerProvider(p);\n context.setGlobalContextManager(new AsyncHooksContextManager().enable());\n\n return { success: true, processor };\n};\n\n/**\n * Attempts to extend the existing OTel provider with our processor. Returns true\n * if the provider was extended, false if it was not.\n */\nexport const extendProvider = (\n behaviour: Behaviour,\n): { success: true; processor: InngestSpanProcessor } | { success: false } => {\n // Attempt to add our processor and export to the existing provider\n const globalProvider = trace.getTracerProvider();\n if (!globalProvider) {\n if (behaviour !== \"auto\") {\n console.warn(\n '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.',\n );\n }\n\n return { success: false };\n }\n\n // trace.getTracerProvider() returns a ProxyTracerProvider wrapper\n // Unwrap it to get the actual provider.\n const existingProvider =\n \"getDelegate\" in globalProvider &&\n typeof globalProvider.getDelegate === \"function\"\n ? globalProvider.getDelegate()\n : globalProvider;\n\n if (\n !existingProvider ||\n !(\"addSpanProcessor\" in existingProvider) ||\n typeof existingProvider.addSpanProcessor !== \"function\"\n ) {\n // TODO Could we also add a function the user can provide that takes the\n // processor and adds it? That way they could support many different\n // providers.\n if (behaviour !== \"auto\") {\n console.warn(\n \"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.\",\n );\n }\n\n return { success: false };\n }\n\n const processor = new InngestSpanProcessor();\n existingProvider.addSpanProcessor(processor);\n\n return { success: true, processor };\n};\n"],"mappings":";;;;;;;;;;AAcA,MAAa,kBACX,YACA,mBAAiD,EAAE,KACyB;CAE5E,MAAM,YAAY,IAAIA,wCAAsB;CAE5C,MAAM,IAAI,IAAIC,mDAAoB,EAChC,gBAAgB,CAAC,UAAU,EAC5B,CAAC;AAQF,+DAAyB,EACvB,kBAPkC;EAClC,GAAG;EACH,gFAAgC;EAChC,IAAIC,gEAA0B;EAC/B,EAIA,CAAC;AAEF,2BAAM,wBAAwB,EAAE;AAChC,6BAAQ,wBAAwB,IAAIC,8DAA0B,CAAC,QAAQ,CAAC;AAExE,QAAO;EAAE,SAAS;EAAM;EAAW;;;;;;AAOrC,MAAa,kBACX,cAC4E;CAE5E,MAAM,iBAAiBC,0BAAM,mBAAmB;AAChD,KAAI,CAAC,gBAAgB;AACnB,MAAI,cAAc,OAChB,SAAQ,KACN,4TACD;AAGH,SAAO,EAAE,SAAS,OAAO;;CAK3B,MAAM,mBACJ,iBAAiB,kBACjB,OAAO,eAAe,gBAAgB,aAClC,eAAe,aAAa,GAC5B;AAEN,KACE,CAAC,oBACD,EAAE,sBAAsB,qBACxB,OAAO,iBAAiB,qBAAqB,YAC7C;AAIA,MAAI,cAAc,OAChB,SAAQ,KACN,2KACD;AAGH,SAAO,EAAE,SAAS,OAAO;;CAG3B,MAAM,YAAY,IAAIJ,wCAAsB;AAC5C,kBAAiB,iBAAiB,UAAU;AAE5C,QAAO;EAAE,SAAS;EAAM;EAAW"}