inngest 4.5.1 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/api/schema.d.cts +2 -2
- package/api/schema.d.cts.map +1 -1
- package/api/schema.d.ts +2 -2
- package/api/schema.d.ts.map +1 -1
- package/components/Inngest.cjs +3 -0
- package/components/Inngest.cjs.map +1 -1
- package/components/Inngest.d.cts.map +1 -1
- package/components/Inngest.d.ts.map +1 -1
- package/components/Inngest.js +4 -1
- package/components/Inngest.js.map +1 -1
- package/components/InngestFunction.cjs +3 -0
- package/components/InngestFunction.cjs.map +1 -1
- package/components/InngestFunction.d.cts +2 -0
- package/components/InngestFunction.d.cts.map +1 -1
- package/components/InngestFunction.d.ts +2 -0
- package/components/InngestFunction.d.ts.map +1 -1
- package/components/InngestFunction.js +3 -0
- package/components/InngestFunction.js.map +1 -1
- package/components/InngestGroupTools.cjs +2 -2
- package/components/InngestGroupTools.cjs.map +1 -1
- package/components/InngestGroupTools.js +2 -2
- package/components/InngestGroupTools.js.map +1 -1
- package/components/InngestMetadata.cjs.map +1 -1
- package/components/InngestMetadata.d.cts +1 -1
- package/components/InngestMetadata.d.cts.map +1 -1
- package/components/InngestMetadata.d.ts +1 -1
- package/components/InngestMetadata.d.ts.map +1 -1
- package/components/InngestMetadata.js.map +1 -1
- package/components/execution/engine.cjs +15 -0
- package/components/execution/engine.cjs.map +1 -1
- package/components/execution/engine.d.cts +8 -0
- package/components/execution/engine.d.cts.map +1 -1
- package/components/execution/engine.d.ts +8 -0
- package/components/execution/engine.d.ts.map +1 -1
- package/components/execution/engine.js +15 -0
- package/components/execution/engine.js.map +1 -1
- package/components/execution/otel/aiExtractor.cjs +114 -0
- package/components/execution/otel/aiExtractor.cjs.map +1 -0
- package/components/execution/otel/aiExtractor.d.cts +16 -0
- package/components/execution/otel/aiExtractor.d.cts.map +1 -0
- package/components/execution/otel/aiExtractor.d.ts +19 -0
- package/components/execution/otel/aiExtractor.d.ts.map +1 -0
- package/components/execution/otel/aiExtractor.js +111 -0
- package/components/execution/otel/aiExtractor.js.map +1 -0
- package/components/execution/otel/metadataProcessor.cjs +195 -0
- package/components/execution/otel/metadataProcessor.cjs.map +1 -0
- package/components/execution/otel/metadataProcessor.js +193 -0
- package/components/execution/otel/metadataProcessor.js.map +1 -0
- package/components/execution/otel/middleware.cjs +1 -1
- package/components/execution/otel/middleware.d.cts +5 -5
- package/components/execution/otel/middleware.d.ts +5 -5
- package/components/execution/otel/middleware.js +1 -1
- package/components/execution/otel/processor.cjs +1 -1
- package/components/execution/otel/processor.js +1 -1
- package/components/execution/otel/util.cjs.map +1 -1
- package/components/execution/otel/util.js.map +1 -1
- package/package.json +1 -1
- package/types.cjs.map +1 -1
- package/types.d.cts +17 -15
- package/types.d.cts.map +1 -1
- package/types.d.ts +17 -15
- package/types.d.ts.map +1 -1
- package/types.js.map +1 -1
- package/version.cjs +1 -1
- package/version.cjs.map +1 -1
- package/version.d.cts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.js.map +1 -1
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { isRecord } from "../../../helpers/types.js";
|
|
2
|
+
import { extractAIMetadataFromAttributes } from "./aiExtractor.js";
|
|
3
|
+
import { debugPrefix } from "./consts.js";
|
|
4
|
+
import Debug from "debug";
|
|
5
|
+
import { trace } from "@opentelemetry/api";
|
|
6
|
+
|
|
7
|
+
//#region src/components/execution/otel/metadataProcessor.ts
|
|
8
|
+
const processorDevDebug = Debug(`${debugPrefix}:InngestMetadataSpanProcessor`);
|
|
9
|
+
/**
|
|
10
|
+
* Resolve the currently-registered global OTel tracer provider, unwrapping
|
|
11
|
+
* the `ProxyTracerProvider` wrapper that `trace.getTracerProvider()` returns.
|
|
12
|
+
* Returns `undefined` when no provider is registered.
|
|
13
|
+
*/
|
|
14
|
+
const getGlobalProvider = () => {
|
|
15
|
+
const globalProvider = trace.getTracerProvider();
|
|
16
|
+
if (!globalProvider) return;
|
|
17
|
+
return ("getDelegate" in globalProvider && typeof globalProvider.getDelegate === "function" ? globalProvider.getDelegate() : globalProvider) ?? void 0;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Attempts to add the given span processor to the given OTel provider.
|
|
21
|
+
* Returns `true` if the processor was attached, `false` if the provider could
|
|
22
|
+
* not be extended.
|
|
23
|
+
*
|
|
24
|
+
* It handles both OTel SDK v1 (`addSpanProcessor()`) and v2 (internal
|
|
25
|
+
* `_spanProcessors` array).
|
|
26
|
+
*
|
|
27
|
+
* This intentionally duplicates the attach logic inside `extendProvider`
|
|
28
|
+
* (`util.ts`) to avoid imports with instrumentation side effects.
|
|
29
|
+
*/
|
|
30
|
+
const attachToProvider = (provider, processor) => {
|
|
31
|
+
if ("addSpanProcessor" in provider && typeof provider.addSpanProcessor === "function") {
|
|
32
|
+
provider.addSpanProcessor(processor);
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
const spanProcessors = getInternalSpanProcessors(provider);
|
|
36
|
+
if (spanProcessors) {
|
|
37
|
+
spanProcessors.push(processor);
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Extract the internal span processors array from a BasicTracerProvider.
|
|
44
|
+
* Returns the mutable array if accessible, undefined otherwise.
|
|
45
|
+
*
|
|
46
|
+
* BasicTracerProvider._activeSpanProcessor is a MultiSpanProcessor,
|
|
47
|
+
* which holds a _spanProcessors: SpanProcessor[] array.
|
|
48
|
+
* Both are TypeScript `private` (not ES #private), so accessible at runtime.
|
|
49
|
+
*
|
|
50
|
+
* Wrapped in try/catch because this accesses internal OTel fields that may
|
|
51
|
+
* change — must never crash the host app.
|
|
52
|
+
*/
|
|
53
|
+
function getInternalSpanProcessors(provider) {
|
|
54
|
+
if (!isRecord(provider)) return;
|
|
55
|
+
try {
|
|
56
|
+
const active = provider._activeSpanProcessor;
|
|
57
|
+
if (!isRecord(active)) return void 0;
|
|
58
|
+
const arr = active._spanProcessors;
|
|
59
|
+
return Array.isArray(arr) ? arr : void 0;
|
|
60
|
+
} catch {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Builds the `#spanSinks` key for a span. Span IDs are only guaranteed unique
|
|
66
|
+
* within a single trace, so spans are keyed by trace ID + span ID to avoid
|
|
67
|
+
* cross-trace collisions.
|
|
68
|
+
*/
|
|
69
|
+
const spanSinkKey = (traceId, spanId) => `${traceId}:${spanId}`;
|
|
70
|
+
/**
|
|
71
|
+
* A read-only OTel span processor that is independent of the Extended Traces
|
|
72
|
+
* processor (`InngestSpanProcessor`).
|
|
73
|
+
*
|
|
74
|
+
* It tracks which spans belong to an Inngest step (seeded by
|
|
75
|
+
* {@link declareStartingSpan} and passed from parent to child in `onStart`).
|
|
76
|
+
*
|
|
77
|
+
* When a tracked span ends, it extracts {@link AIMetadata} from the span's
|
|
78
|
+
* attributes and pushes it to the span's {@link AIMetadataSink}.
|
|
79
|
+
*/
|
|
80
|
+
var InngestMetadataSpanProcessor = class {
|
|
81
|
+
/**
|
|
82
|
+
* A map of tracked spans to their sink.
|
|
83
|
+
*
|
|
84
|
+
* We use traceId:spanID as the key, which uniquely identifies each span. See
|
|
85
|
+
* {@link spanSinkKey}
|
|
86
|
+
*
|
|
87
|
+
* The engine seeds the map during {@link declareStartingSpan} with the root
|
|
88
|
+
* span and its sink.
|
|
89
|
+
*
|
|
90
|
+
* During onStart, the processor looks up the span's parent's sink and then
|
|
91
|
+
* records the span as also using that sink. If the parent is not found, then
|
|
92
|
+
* the span is not descended from a root step span, and therefore does not
|
|
93
|
+
* need to have a sink.
|
|
94
|
+
*
|
|
95
|
+
* All spans with the same root span that started the step will share the
|
|
96
|
+
* same sink.
|
|
97
|
+
*/
|
|
98
|
+
#spanSinks = /* @__PURE__ */ new Map();
|
|
99
|
+
/**
|
|
100
|
+
* A registry used to clean up items from `#spanSinks` when spans fall out of
|
|
101
|
+
* reference without ending. Avoids leaking entries (and the engine sink
|
|
102
|
+
* closures they reference) for spans that are never ended and are GC'd.
|
|
103
|
+
*/
|
|
104
|
+
#spanCleanup = new FinalizationRegistry((key) => {
|
|
105
|
+
if (key) this.#spanSinks.delete(key);
|
|
106
|
+
});
|
|
107
|
+
/**
|
|
108
|
+
* Latches once this processor has been attached to a global OTel provider, so
|
|
109
|
+
* {@link attach} can never push it into a provider's processor list twice
|
|
110
|
+
* (which would double-process every span and double-count tokens).
|
|
111
|
+
*/
|
|
112
|
+
#attached = false;
|
|
113
|
+
/**
|
|
114
|
+
* Idempotently attach this processor to the global OTel provider that already
|
|
115
|
+
* exists, so it begins receiving span lifecycle events.
|
|
116
|
+
*/
|
|
117
|
+
attach() {
|
|
118
|
+
if (this.#attached) return;
|
|
119
|
+
const provider = getGlobalProvider();
|
|
120
|
+
if (!provider) return;
|
|
121
|
+
if (attachToProvider(provider, this)) {
|
|
122
|
+
this.#attached = true;
|
|
123
|
+
processorDevDebug("attached to global OTel provider");
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Declare the step's root span. Seeds tracking so that the root and all of
|
|
128
|
+
* its descendants share the same AIMetadata sink.
|
|
129
|
+
*/
|
|
130
|
+
declareStartingSpan({ span, traceparent, onAIMetadata }) {
|
|
131
|
+
if (!this.#attached) return;
|
|
132
|
+
if (!traceparent) return processorDevDebug("no traceparent found for span", span.spanContext().spanId, "so skipping it");
|
|
133
|
+
this.trackSpan(span, onAIMetadata);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Mark a span as tracked, recording its step's sink and registering it for
|
|
137
|
+
* cleanup.
|
|
138
|
+
*
|
|
139
|
+
* Read-only: unlike the Extended Traces processor, no attributes
|
|
140
|
+
* are stamped on the span.
|
|
141
|
+
*/
|
|
142
|
+
trackSpan(span, sink) {
|
|
143
|
+
const { traceId, spanId } = span.spanContext();
|
|
144
|
+
const key = spanSinkKey(traceId, spanId);
|
|
145
|
+
this.#spanCleanup.register(span, key, span);
|
|
146
|
+
this.#spanSinks.set(key, sink);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Clean up references to a span that has ended (or been GC'd).
|
|
150
|
+
*/
|
|
151
|
+
cleanupSpan(span) {
|
|
152
|
+
const { traceId, spanId } = span.spanContext();
|
|
153
|
+
this.#spanCleanup.unregister(span);
|
|
154
|
+
this.#spanSinks.delete(spanSinkKey(traceId, spanId));
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Track children of spans we already care about, so the whole subtree under a
|
|
158
|
+
* declared root is captured.
|
|
159
|
+
*/
|
|
160
|
+
onStart(span, parentContext) {
|
|
161
|
+
const parentSpanId = trace.getSpanContext(parentContext)?.spanId;
|
|
162
|
+
if (!parentSpanId) return;
|
|
163
|
+
const sink = this.#spanSinks.get(spanSinkKey(span.spanContext().traceId, parentSpanId));
|
|
164
|
+
if (!sink) return;
|
|
165
|
+
this.trackSpan(span, sink);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* On end, extract any AI metadata from the span's attributes and push it to
|
|
169
|
+
* its sink, then clean up the span's tracking entry.
|
|
170
|
+
*/
|
|
171
|
+
onEnd(span) {
|
|
172
|
+
const { traceId, spanId } = span.spanContext();
|
|
173
|
+
try {
|
|
174
|
+
const sink = this.#spanSinks.get(spanSinkKey(traceId, spanId));
|
|
175
|
+
if (!sink) return;
|
|
176
|
+
const aiMetadata = extractAIMetadataFromAttributes(span.attributes);
|
|
177
|
+
if (Object.keys(aiMetadata).length === 0) return;
|
|
178
|
+
sink(aiMetadata);
|
|
179
|
+
} finally {
|
|
180
|
+
this.cleanupSpan(span);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
async forceFlush() {}
|
|
184
|
+
async shutdown() {}
|
|
185
|
+
};
|
|
186
|
+
/**
|
|
187
|
+
* The process-wide metadata span processor instance.
|
|
188
|
+
*/
|
|
189
|
+
const metadataSpanProcessor = new InngestMetadataSpanProcessor();
|
|
190
|
+
|
|
191
|
+
//#endregion
|
|
192
|
+
export { metadataSpanProcessor };
|
|
193
|
+
//# sourceMappingURL=metadataProcessor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadataProcessor.js","names":["#spanSinks","#attached","#spanCleanup"],"sources":["../../../../src/components/execution/otel/metadataProcessor.ts"],"sourcesContent":["import { type Context, type Span, trace } from \"@opentelemetry/api\";\nimport type {\n ReadableSpan,\n SpanProcessor,\n} from \"@opentelemetry/sdk-trace-base\";\nimport Debug from \"debug\";\nimport { isRecord } from \"../../../helpers/types.ts\";\nimport {\n type AIMetadata,\n extractAIMetadataFromAttributes,\n} from \"./aiExtractor.ts\";\nimport { debugPrefix } from \"./consts.ts\";\n\nconst processorDevDebug = Debug(`${debugPrefix}:InngestMetadataSpanProcessor`);\n\n/**\n * Receives {@link AIMetadata} extracted from a span the moment it ends.\n * Supplied by the engine; the engine owns all aggregation and\n * step-attribution of the pushed values.\n */\nexport type AIMetadataSink = (metadata: AIMetadata) => void;\n\n/**\n * Resolve the currently-registered global OTel tracer provider, unwrapping\n * the `ProxyTracerProvider` wrapper that `trace.getTracerProvider()` returns.\n * Returns `undefined` when no provider is registered.\n */\nconst getGlobalProvider = (): object | undefined => {\n const globalProvider = trace.getTracerProvider();\n if (!globalProvider) {\n return undefined;\n }\n\n const existingProvider =\n \"getDelegate\" in globalProvider &&\n typeof globalProvider.getDelegate === \"function\"\n ? globalProvider.getDelegate()\n : globalProvider;\n\n return existingProvider ?? undefined;\n};\n\n/**\n * Attempts to add the given span processor to the given OTel provider.\n * Returns `true` if the processor was attached, `false` if the provider could\n * not be extended.\n *\n * It handles both OTel SDK v1 (`addSpanProcessor()`) and v2 (internal\n * `_spanProcessors` array).\n *\n * This intentionally duplicates the attach logic inside `extendProvider`\n * (`util.ts`) to avoid imports with instrumentation side effects.\n */\nconst attachToProvider = (\n provider: object,\n processor: SpanProcessor,\n): boolean => {\n // OTel SDK v1 exposes addSpanProcessor() on BasicTracerProvider.\n if (\n \"addSpanProcessor\" in provider &&\n typeof (provider as { addSpanProcessor?: unknown }).addSpanProcessor ===\n \"function\"\n ) {\n (\n provider as unknown as {\n addSpanProcessor: (p: SpanProcessor) => void;\n }\n ).addSpanProcessor(processor);\n return true;\n }\n\n // OTel SDK v2 removed addSpanProcessor() — span processors are constructor-only.\n // No public API exists to add processors post-construction (OTel issue #5299),\n // so push into the internal _spanProcessors array.\n // These fields are TypeScript `private` (not #private), so accessible at runtime.\n const spanProcessors = getInternalSpanProcessors(provider);\n if (spanProcessors) {\n spanProcessors.push(processor);\n return true;\n }\n\n return false;\n};\n\n/**\n * Extract the internal span processors array from a BasicTracerProvider.\n * Returns the mutable array if accessible, undefined otherwise.\n *\n * BasicTracerProvider._activeSpanProcessor is a MultiSpanProcessor,\n * which holds a _spanProcessors: SpanProcessor[] array.\n * Both are TypeScript `private` (not ES #private), so accessible at runtime.\n *\n * Wrapped in try/catch because this accesses internal OTel fields that may\n * change — must never crash the host app.\n */\nfunction getInternalSpanProcessors(provider: unknown): unknown[] | undefined {\n if (!isRecord(provider)) {\n return undefined;\n }\n\n try {\n const active = provider._activeSpanProcessor;\n if (!isRecord(active)) return undefined;\n\n const arr = active._spanProcessors;\n return Array.isArray(arr) ? arr : undefined;\n } catch {\n return undefined;\n }\n}\n\n/**\n * Builds the `#spanSinks` key for a span. Span IDs are only guaranteed unique\n * within a single trace, so spans are keyed by trace ID + span ID to avoid\n * cross-trace collisions.\n */\nconst spanSinkKey = (traceId: string, spanId: string): string =>\n `${traceId}:${spanId}`;\n\n/**\n * A read-only OTel span processor that is independent of the Extended Traces\n * processor (`InngestSpanProcessor`).\n *\n * It tracks which spans belong to an Inngest step (seeded by\n * {@link declareStartingSpan} and passed from parent to child in `onStart`).\n *\n * When a tracked span ends, it extracts {@link AIMetadata} from the span's\n * attributes and pushes it to the span's {@link AIMetadataSink}.\n */\nexport class InngestMetadataSpanProcessor implements SpanProcessor {\n /**\n * A map of tracked spans to their sink.\n *\n * We use traceId:spanID as the key, which uniquely identifies each span. See\n * {@link spanSinkKey}\n *\n * The engine seeds the map during {@link declareStartingSpan} with the root\n * span and its sink.\n *\n * During onStart, the processor looks up the span's parent's sink and then\n * records the span as also using that sink. If the parent is not found, then\n * the span is not descended from a root step span, and therefore does not\n * need to have a sink.\n *\n * All spans with the same root span that started the step will share the\n * same sink.\n */\n #spanSinks = new Map<string, AIMetadataSink>();\n\n /**\n * A registry used to clean up items from `#spanSinks` when spans fall out of\n * reference without ending. Avoids leaking entries (and the engine sink\n * closures they reference) for spans that are never ended and are GC'd.\n */\n #spanCleanup = new FinalizationRegistry<string>((key) => {\n if (key) {\n this.#spanSinks.delete(key);\n }\n });\n\n /**\n * Latches once this processor has been attached to a global OTel provider, so\n * {@link attach} can never push it into a provider's processor list twice\n * (which would double-process every span and double-count tokens).\n */\n #attached = false;\n\n /**\n * Idempotently attach this processor to the global OTel provider that already\n * exists, so it begins receiving span lifecycle events.\n */\n attach(): void {\n if (this.#attached) {\n return;\n }\n\n const provider = getGlobalProvider();\n if (!provider) {\n return;\n }\n\n if (attachToProvider(provider, this)) {\n this.#attached = true;\n processorDevDebug(\"attached to global OTel provider\");\n }\n }\n\n /**\n * Declare the step's root span. Seeds tracking so that the root and all of\n * its descendants share the same AIMetadata sink.\n */\n public declareStartingSpan({\n span,\n traceparent,\n onAIMetadata,\n }: {\n span: Span;\n traceparent: string | undefined;\n onAIMetadata: AIMetadataSink;\n }): void {\n // If this processor is not attached to a provider, we don't need to\n // declare starting spans.\n if (!this.#attached) {\n return;\n }\n\n // If we don't have a traceparent, then this isn't a step the Executor is\n // tracking, so we don't track it either.\n if (!traceparent) {\n return processorDevDebug(\n \"no traceparent found for span\",\n span.spanContext().spanId,\n \"so skipping it\",\n );\n }\n\n this.trackSpan(span, onAIMetadata);\n }\n\n /**\n * Mark a span as tracked, recording its step's sink and registering it for\n * cleanup.\n *\n * Read-only: unlike the Extended Traces processor, no attributes\n * are stamped on the span.\n */\n private trackSpan(span: Span, sink: AIMetadataSink): void {\n const { traceId, spanId } = span.spanContext();\n const key = spanSinkKey(traceId, spanId);\n\n this.#spanCleanup.register(span, key, span);\n this.#spanSinks.set(key, sink);\n }\n\n /**\n * Clean up references to a span that has ended (or been GC'd).\n */\n private cleanupSpan(span: ReadableSpan): void {\n const { traceId, spanId } = span.spanContext();\n this.#spanCleanup.unregister(span);\n this.#spanSinks.delete(spanSinkKey(traceId, spanId));\n }\n\n /**\n * Track children of spans we already care about, so the whole subtree under a\n * declared root is captured.\n */\n onStart(span: Span, parentContext: Context): void {\n const parentSpanId = trace.getSpanContext(parentContext)?.spanId;\n\n if (!parentSpanId) {\n return;\n }\n\n // A child span always shares its parent's trace ID, so the parent's key\n // can be built from the child's own span context.\n const sink = this.#spanSinks.get(\n spanSinkKey(span.spanContext().traceId, parentSpanId),\n );\n if (!sink) {\n return;\n }\n\n this.trackSpan(span, sink);\n }\n\n /**\n * On end, extract any AI metadata from the span's attributes and push it to\n * its sink, then clean up the span's tracking entry.\n */\n onEnd(span: ReadableSpan): void {\n const { traceId, spanId } = span.spanContext();\n\n try {\n const sink = this.#spanSinks.get(spanSinkKey(traceId, spanId));\n if (!sink) {\n return;\n }\n\n const aiMetadata = extractAIMetadataFromAttributes(span.attributes);\n if (Object.keys(aiMetadata).length === 0) {\n return;\n }\n\n sink(aiMetadata);\n } finally {\n this.cleanupSpan(span);\n }\n }\n\n // Nothing to flush or shut down: this processor is read-only and has no\n // exporter.\n async forceFlush(): Promise<void> {}\n\n async shutdown(): Promise<void> {}\n}\n\n/**\n * The process-wide metadata span processor instance.\n */\nexport const metadataSpanProcessor = new InngestMetadataSpanProcessor();\n"],"mappings":";;;;;;;AAaA,MAAM,oBAAoB,MAAM,GAAG,YAAY,+BAA+B;;;;;;AAc9E,MAAM,0BAA8C;CAClD,MAAM,iBAAiB,MAAM,mBAAmB;AAChD,KAAI,CAAC,eACH;AASF,SALE,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S,WAAW,KAAK,aAAa;EAC9C,MAAM,MAAM,YAAY,SAAS,OAAO;AAExC,QAAKC,YAAa,SAAS,MAAM,KAAK,KAAK;AAC3C,QAAKF,UAAW,IAAI,KAAK,KAAK;;;;;CAMhC,AAAQ,YAAY,MAA0B;EAC5C,MAAM,EAAE,SAAS,WAAW,KAAK,aAAa;AAC9C,QAAKE,YAAa,WAAW,KAAK;AAClC,QAAKF,UAAW,OAAO,YAAY,SAAS,OAAO,CAAC;;;;;;CAOtD,QAAQ,MAAY,eAA8B;EAChD,MAAM,eAAe,MAAM,eAAe,cAAc,EAAE;AAE1D,MAAI,CAAC,aACH;EAKF,MAAM,OAAO,MAAKA,UAAW,IAC3B,YAAY,KAAK,aAAa,CAAC,SAAS,aAAa,CACtD;AACD,MAAI,CAAC,KACH;AAGF,OAAK,UAAU,MAAM,KAAK;;;;;;CAO5B,MAAM,MAA0B;EAC9B,MAAM,EAAE,SAAS,WAAW,KAAK,aAAa;AAE9C,MAAI;GACF,MAAM,OAAO,MAAKA,UAAW,IAAI,YAAY,SAAS,OAAO,CAAC;AAC9D,OAAI,CAAC,KACH;GAGF,MAAM,aAAa,gCAAgC,KAAK,WAAW;AACnE,OAAI,OAAO,KAAK,WAAW,CAAC,WAAW,EACrC;AAGF,QAAK,WAAW;YACR;AACR,QAAK,YAAY,KAAK;;;CAM1B,MAAM,aAA4B;CAElC,MAAM,WAA0B;;;;;AAMlC,MAAa,wBAAwB,IAAI,8BAA8B"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_version = require('../../../version.cjs');
|
|
3
|
+
const require_consts = require('./consts.cjs');
|
|
3
4
|
const require_middleware = require('../../middleware/middleware.cjs');
|
|
4
5
|
const require_access = require('./access.cjs');
|
|
5
|
-
const require_consts = require('./consts.cjs');
|
|
6
6
|
const require_util = require('./util.cjs');
|
|
7
7
|
let debug = require("debug");
|
|
8
8
|
debug = require_rolldown_runtime.__toESM(debug);
|
|
@@ -72,6 +72,11 @@ declare const extendedTracesMiddleware: ({
|
|
|
72
72
|
ctx: {
|
|
73
73
|
tracer: _opentelemetry_api0.Tracer;
|
|
74
74
|
event: Simplify<EventPayload>;
|
|
75
|
+
defer: DeferFn;
|
|
76
|
+
events: AsTuple<Simplify<EventPayload>>;
|
|
77
|
+
runId: string;
|
|
78
|
+
requestId?: string | undefined;
|
|
79
|
+
jobId?: string | undefined;
|
|
75
80
|
step: {
|
|
76
81
|
sendEvent: (idOrOptions: StepOptionsOrId, payload: SendEventPayload) => Promise<SendEventOutput<ClientOptions>>;
|
|
77
82
|
waitForSignal: <TData>(idOrOptions: StepOptionsOrId, opts: {
|
|
@@ -153,11 +158,6 @@ declare const extendedTracesMiddleware: ({
|
|
|
153
158
|
}) => InvocationResult<Jsonify<GetFunctionOutputRaw<TFunction>>>;
|
|
154
159
|
fetch: StepFetch;
|
|
155
160
|
};
|
|
156
|
-
defer: DeferFn;
|
|
157
|
-
events: AsTuple<Simplify<EventPayload>>;
|
|
158
|
-
runId: string;
|
|
159
|
-
requestId?: string | undefined;
|
|
160
|
-
jobId?: string | undefined;
|
|
161
161
|
group: ReturnType<typeof createGroupTools>;
|
|
162
162
|
attempt: number;
|
|
163
163
|
maxAttempts?: number | undefined;
|
|
@@ -72,6 +72,11 @@ declare const extendedTracesMiddleware: ({
|
|
|
72
72
|
ctx: {
|
|
73
73
|
tracer: _opentelemetry_api0.Tracer;
|
|
74
74
|
event: Simplify<EventPayload>;
|
|
75
|
+
defer: DeferFn;
|
|
76
|
+
events: AsTuple<Simplify<EventPayload>>;
|
|
77
|
+
runId: string;
|
|
78
|
+
requestId?: string | undefined;
|
|
79
|
+
jobId?: string | undefined;
|
|
75
80
|
step: {
|
|
76
81
|
sendEvent: (idOrOptions: StepOptionsOrId, payload: SendEventPayload) => Promise<SendEventOutput<ClientOptions>>;
|
|
77
82
|
waitForSignal: <TData>(idOrOptions: StepOptionsOrId, opts: {
|
|
@@ -153,11 +158,6 @@ declare const extendedTracesMiddleware: ({
|
|
|
153
158
|
}) => InvocationResult<Jsonify<GetFunctionOutputRaw<TFunction>>>;
|
|
154
159
|
fetch: StepFetch;
|
|
155
160
|
};
|
|
156
|
-
defer: DeferFn;
|
|
157
|
-
events: AsTuple<Simplify<EventPayload>>;
|
|
158
|
-
runId: string;
|
|
159
|
-
requestId?: string | undefined;
|
|
160
|
-
jobId?: string | undefined;
|
|
161
161
|
group: ReturnType<typeof createGroupTools>;
|
|
162
162
|
attempt: number;
|
|
163
163
|
maxAttempts?: number | undefined;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { version } from "../../../version.js";
|
|
2
|
+
import { debugPrefix } from "./consts.js";
|
|
2
3
|
import { Middleware } from "../../middleware/middleware.js";
|
|
3
4
|
import { clientProcessorMap } from "./access.js";
|
|
4
|
-
import { debugPrefix } from "./consts.js";
|
|
5
5
|
import { createProvider, extendProvider } from "./util.js";
|
|
6
6
|
import Debug from "debug";
|
|
7
7
|
import { DiagLogLevel, diag, trace } from "@opentelemetry/api";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_strings = require('../../../helpers/strings.cjs');
|
|
3
3
|
const require_als = require('../als.cjs');
|
|
4
|
-
const require_access = require('./access.cjs');
|
|
5
4
|
const require_consts = require('./consts.cjs');
|
|
5
|
+
const require_access = require('./access.cjs');
|
|
6
6
|
const require_deterministicId = require('../../../helpers/deterministicId.cjs');
|
|
7
7
|
let debug = require("debug");
|
|
8
8
|
debug = require_rolldown_runtime.__toESM(debug);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { hashSigningKey } from "../../../helpers/strings.js";
|
|
2
2
|
import { getAsyncCtx } from "../als.js";
|
|
3
|
-
import { clientProcessorMap } from "./access.js";
|
|
4
3
|
import { Attribute, TraceStateKey, debugPrefix } from "./consts.js";
|
|
4
|
+
import { clientProcessorMap } from "./access.js";
|
|
5
5
|
import { deterministicSpanID } from "../../../helpers/deterministicId.js";
|
|
6
6
|
import Debug from "debug";
|
|
7
7
|
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.cjs","names":["debug","debugPrefix","InngestSpanProcessor","BasicTracerProvider","trace"],"sources":["../../../../src/components/execution/otel/util.ts"],"sourcesContent":["import { context, trace } from \"@opentelemetry/api\";\nimport type { Instrumentation } from \"@opentelemetry/instrumentation\";\nimport { BasicTracerProvider } from \"@opentelemetry/sdk-trace-base\";\nimport Debug from \"debug\";\nimport { debugPrefix } from \"./consts.ts\";\nimport { InngestSpanProcessor } from \"./processor.ts\";\n\nconst debug = Debug(`${debugPrefix}:createProvider`);\n\nexport type Behaviour = \"createProvider\" | \"extendProvider\" | \"off\" | \"auto\";\nexport type Instrumentations = (Instrumentation | Instrumentation[])[];\n\nexport const createProvider = async (\n _behaviour: Behaviour,\n instrumentations: Instrumentations | undefined = [],\n): Promise<\n | { success: true; processor: InngestSpanProcessor }\n | { success: false; error?: unknown }\n> => {\n try {\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 // Dynamic imports to avoid loading the full auto-instrumentation suite at\n // module evaluation time. These are only needed when creating a new provider,\n // not when extending an existing one. Static imports here caused version\n // conflicts with host app OTel setups (e.g. Sentry) and silently broke\n // inngest.send(). See #1324.\n const { getNodeAutoInstrumentations } = await import(\n \"@opentelemetry/auto-instrumentations-node\"\n );\n const { registerInstrumentations } = await import(\n \"@opentelemetry/instrumentation\"\n );\n const { AnthropicInstrumentation } = await import(\n \"@traceloop/instrumentation-anthropic\"\n );\n const { AsyncHooksContextManager } = await import(\n \"@opentelemetry/context-async-hooks\"\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 } catch (err) {\n debug(\"failed to create provider:\", err);\n return { success: false, error: err };\n }\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 (!existingProvider) {\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\n // OTel SDK v1 exposes addSpanProcessor() on BasicTracerProvider.\n if (\n \"addSpanProcessor\" in existingProvider &&\n typeof existingProvider.addSpanProcessor === \"function\"\n ) {\n existingProvider.addSpanProcessor(processor);\n return { success: true, processor };\n }\n\n // OTel SDK v2 removed addSpanProcessor() — span processors are constructor-only.\n // No public API exists to add processors post-construction (OTel issue #5299),\n // so push into the internal _spanProcessors array.\n // These fields are TypeScript `private` (not #private), so accessible at runtime.\n const spanProcessors = getInternalSpanProcessors(existingProvider);\n if (spanProcessors) {\n spanProcessors.push(processor);\n return { success: true, processor };\n }\n\n if (behaviour !== \"auto\") {\n console.warn(\n \"Unable to add InngestSpanProcessor to existing OTel provider. \" +\n \"The provider does not support addSpanProcessor() (OTel SDK v1) \" +\n \"or expose _activeSpanProcessor._spanProcessors (OTel SDK v2).\",\n );\n }\n\n return { success: false };\n};\n\n/**\n * Extract the internal span processors array from a BasicTracerProvider.\n * Returns the mutable array if accessible, undefined otherwise.\n *\n * BasicTracerProvider._activeSpanProcessor is a MultiSpanProcessor,\n * which holds a _spanProcessors: SpanProcessor[] array.\n * Both are TypeScript `private` (not ES #private), so accessible at runtime.\n *\n * Wrapped in try/catch because this accesses internal OTel fields that may\n * change — must never crash the host app.\n */\nfunction getInternalSpanProcessors(provider: unknown): unknown[] | undefined {\n try {\n const active = (provider as Record<string, unknown>)?._activeSpanProcessor;\n if (typeof active !== \"object\" || active === null) return undefined;\n\n const arr = (active as Record<string, unknown>)._spanProcessors;\n return Array.isArray(arr) ? arr : undefined;\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;AAOA,MAAMA,6BAAc,GAAGC,2BAAY,iBAAiB;AAKpD,MAAa,iBAAiB,OAC5B,YACA,mBAAiD,EAAE,KAIhD;AACH,KAAI;EAEF,MAAM,YAAY,IAAIC,wCAAsB;EAE5C,MAAM,IAAI,IAAIC,mDAAoB,EAChC,gBAAgB,CAAC,UAAU,EAC5B,CAAC;EAOF,MAAM,EAAE,gCAAgC,MAAM,OAC5C;EAEF,MAAM,EAAE,6BAA6B,MAAM,OACzC;EAEF,MAAM,EAAE,6BAA6B,MAAM,OACzC;EAEF,MAAM,EAAE,6BAA6B,MAAM,OACzC;AASF,2BAAyB,EACvB,kBAPkC;GAClC,GAAG;GACH,GAAG,6BAA6B;GAChC,IAAI,0BAA0B;GAC/B,EAIA,CAAC;AAEF,4BAAM,wBAAwB,EAAE;AAChC,8BAAQ,wBAAwB,IAAI,0BAA0B,CAAC,QAAQ,CAAC;AAExE,SAAO;GAAE,SAAS;GAAM;GAAW;UAC5B,KAAK;AACZ,UAAM,8BAA8B,IAAI;AACxC,SAAO;GAAE,SAAS;GAAO,OAAO;GAAK;;;;;;;AAQzC,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,KAAI,CAAC,kBAAkB;AACrB,MAAI,cAAc,OAChB,SAAQ,KACN,2KACD;AAGH,SAAO,EAAE,SAAS,OAAO;;CAG3B,MAAM,YAAY,IAAIF,wCAAsB;AAG5C,KACE,sBAAsB,oBACtB,OAAO,iBAAiB,qBAAqB,YAC7C;AACA,mBAAiB,iBAAiB,UAAU;AAC5C,SAAO;GAAE,SAAS;GAAM;GAAW;;
|
|
1
|
+
{"version":3,"file":"util.cjs","names":["debug","debugPrefix","InngestSpanProcessor","BasicTracerProvider","trace"],"sources":["../../../../src/components/execution/otel/util.ts"],"sourcesContent":["import { context, trace } from \"@opentelemetry/api\";\nimport type { Instrumentation } from \"@opentelemetry/instrumentation\";\nimport { BasicTracerProvider } from \"@opentelemetry/sdk-trace-base\";\nimport Debug from \"debug\";\nimport { debugPrefix } from \"./consts.ts\";\nimport { InngestSpanProcessor } from \"./processor.ts\";\n\nconst debug = Debug(`${debugPrefix}:createProvider`);\n\nexport type Behaviour = \"createProvider\" | \"extendProvider\" | \"off\" | \"auto\";\nexport type Instrumentations = (Instrumentation | Instrumentation[])[];\n\nexport const createProvider = async (\n _behaviour: Behaviour,\n instrumentations: Instrumentations | undefined = [],\n): Promise<\n | { success: true; processor: InngestSpanProcessor }\n | { success: false; error?: unknown }\n> => {\n try {\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 // Dynamic imports to avoid loading the full auto-instrumentation suite at\n // module evaluation time. These are only needed when creating a new provider,\n // not when extending an existing one. Static imports here caused version\n // conflicts with host app OTel setups (e.g. Sentry) and silently broke\n // inngest.send(). See #1324.\n const { getNodeAutoInstrumentations } = await import(\n \"@opentelemetry/auto-instrumentations-node\"\n );\n const { registerInstrumentations } = await import(\n \"@opentelemetry/instrumentation\"\n );\n const { AnthropicInstrumentation } = await import(\n \"@traceloop/instrumentation-anthropic\"\n );\n const { AsyncHooksContextManager } = await import(\n \"@opentelemetry/context-async-hooks\"\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 } catch (err) {\n debug(\"failed to create provider:\", err);\n return { success: false, error: err };\n }\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 (!existingProvider) {\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\n // OTel SDK v1 exposes addSpanProcessor() on BasicTracerProvider.\n if (\n \"addSpanProcessor\" in existingProvider &&\n typeof existingProvider.addSpanProcessor === \"function\"\n ) {\n existingProvider.addSpanProcessor(processor);\n return { success: true, processor };\n }\n\n // OTel SDK v2 removed addSpanProcessor() — span processors are constructor-only.\n // No public API exists to add processors post-construction (OTel issue #5299),\n // so push into the internal _spanProcessors array.\n // These fields are TypeScript `private` (not #private), so accessible at runtime.\n // TODO: Replace this internal mutation with a SpanProcessor delegator that is\n // installed when creating the provider and can dynamically delegate to\n // processors added later.\n const spanProcessors = getInternalSpanProcessors(existingProvider);\n if (spanProcessors) {\n spanProcessors.push(processor);\n return { success: true, processor };\n }\n\n if (behaviour !== \"auto\") {\n console.warn(\n \"Unable to add InngestSpanProcessor to existing OTel provider. \" +\n \"The provider does not support addSpanProcessor() (OTel SDK v1) \" +\n \"or expose _activeSpanProcessor._spanProcessors (OTel SDK v2).\",\n );\n }\n\n return { success: false };\n};\n\n/**\n * Extract the internal span processors array from a BasicTracerProvider.\n * Returns the mutable array if accessible, undefined otherwise.\n *\n * BasicTracerProvider._activeSpanProcessor is a MultiSpanProcessor,\n * which holds a _spanProcessors: SpanProcessor[] array.\n * Both are TypeScript `private` (not ES #private), so accessible at runtime.\n *\n * Wrapped in try/catch because this accesses internal OTel fields that may\n * change — must never crash the host app.\n */\nfunction getInternalSpanProcessors(provider: unknown): unknown[] | undefined {\n try {\n const active = (provider as Record<string, unknown>)?._activeSpanProcessor;\n if (typeof active !== \"object\" || active === null) return undefined;\n\n const arr = (active as Record<string, unknown>)._spanProcessors;\n return Array.isArray(arr) ? arr : undefined;\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;AAOA,MAAMA,6BAAc,GAAGC,2BAAY,iBAAiB;AAKpD,MAAa,iBAAiB,OAC5B,YACA,mBAAiD,EAAE,KAIhD;AACH,KAAI;EAE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,6LAGD;AAGH,QAAO,EAAE,SAAS,OAAO;;;;;;;;;;;;;AAc3B,SAAS,0BAA0B,UAA0C;AAC3E,KAAI;EACF,MAAM,SAAU,UAAsC;AACtD,MAAI,OAAO,WAAW,YAAY,WAAW,KAAM,QAAO;EAE1D,MAAM,MAAO,OAAmC;AAChD,SAAO,MAAM,QAAQ,IAAI,GAAG,MAAM;SAC5B;AACN"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","names":[],"sources":["../../../../src/components/execution/otel/util.ts"],"sourcesContent":["import { context, trace } from \"@opentelemetry/api\";\nimport type { Instrumentation } from \"@opentelemetry/instrumentation\";\nimport { BasicTracerProvider } from \"@opentelemetry/sdk-trace-base\";\nimport Debug from \"debug\";\nimport { debugPrefix } from \"./consts.ts\";\nimport { InngestSpanProcessor } from \"./processor.ts\";\n\nconst debug = Debug(`${debugPrefix}:createProvider`);\n\nexport type Behaviour = \"createProvider\" | \"extendProvider\" | \"off\" | \"auto\";\nexport type Instrumentations = (Instrumentation | Instrumentation[])[];\n\nexport const createProvider = async (\n _behaviour: Behaviour,\n instrumentations: Instrumentations | undefined = [],\n): Promise<\n | { success: true; processor: InngestSpanProcessor }\n | { success: false; error?: unknown }\n> => {\n try {\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 // Dynamic imports to avoid loading the full auto-instrumentation suite at\n // module evaluation time. These are only needed when creating a new provider,\n // not when extending an existing one. Static imports here caused version\n // conflicts with host app OTel setups (e.g. Sentry) and silently broke\n // inngest.send(). See #1324.\n const { getNodeAutoInstrumentations } = await import(\n \"@opentelemetry/auto-instrumentations-node\"\n );\n const { registerInstrumentations } = await import(\n \"@opentelemetry/instrumentation\"\n );\n const { AnthropicInstrumentation } = await import(\n \"@traceloop/instrumentation-anthropic\"\n );\n const { AsyncHooksContextManager } = await import(\n \"@opentelemetry/context-async-hooks\"\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 } catch (err) {\n debug(\"failed to create provider:\", err);\n return { success: false, error: err };\n }\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 (!existingProvider) {\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\n // OTel SDK v1 exposes addSpanProcessor() on BasicTracerProvider.\n if (\n \"addSpanProcessor\" in existingProvider &&\n typeof existingProvider.addSpanProcessor === \"function\"\n ) {\n existingProvider.addSpanProcessor(processor);\n return { success: true, processor };\n }\n\n // OTel SDK v2 removed addSpanProcessor() — span processors are constructor-only.\n // No public API exists to add processors post-construction (OTel issue #5299),\n // so push into the internal _spanProcessors array.\n // These fields are TypeScript `private` (not #private), so accessible at runtime.\n const spanProcessors = getInternalSpanProcessors(existingProvider);\n if (spanProcessors) {\n spanProcessors.push(processor);\n return { success: true, processor };\n }\n\n if (behaviour !== \"auto\") {\n console.warn(\n \"Unable to add InngestSpanProcessor to existing OTel provider. \" +\n \"The provider does not support addSpanProcessor() (OTel SDK v1) \" +\n \"or expose _activeSpanProcessor._spanProcessors (OTel SDK v2).\",\n );\n }\n\n return { success: false };\n};\n\n/**\n * Extract the internal span processors array from a BasicTracerProvider.\n * Returns the mutable array if accessible, undefined otherwise.\n *\n * BasicTracerProvider._activeSpanProcessor is a MultiSpanProcessor,\n * which holds a _spanProcessors: SpanProcessor[] array.\n * Both are TypeScript `private` (not ES #private), so accessible at runtime.\n *\n * Wrapped in try/catch because this accesses internal OTel fields that may\n * change — must never crash the host app.\n */\nfunction getInternalSpanProcessors(provider: unknown): unknown[] | undefined {\n try {\n const active = (provider as Record<string, unknown>)?._activeSpanProcessor;\n if (typeof active !== \"object\" || active === null) return undefined;\n\n const arr = (active as Record<string, unknown>)._spanProcessors;\n return Array.isArray(arr) ? arr : undefined;\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;;;;;AAOA,MAAM,QAAQ,MAAM,GAAG,YAAY,iBAAiB;AAKpD,MAAa,iBAAiB,OAC5B,YACA,mBAAiD,EAAE,KAIhD;AACH,KAAI;EAEF,MAAM,YAAY,IAAI,sBAAsB;EAE5C,MAAM,IAAI,IAAI,oBAAoB,EAChC,gBAAgB,CAAC,UAAU,EAC5B,CAAC;EAOF,MAAM,EAAE,gCAAgC,MAAM,OAC5C;EAEF,MAAM,EAAE,6BAA6B,MAAM,OACzC;EAEF,MAAM,EAAE,6BAA6B,MAAM,OACzC;EAEF,MAAM,EAAE,6BAA6B,MAAM,OACzC;AASF,2BAAyB,EACvB,kBAPkC;GAClC,GAAG;GACH,GAAG,6BAA6B;GAChC,IAAI,0BAA0B;GAC/B,EAIA,CAAC;AAEF,QAAM,wBAAwB,EAAE;AAChC,UAAQ,wBAAwB,IAAI,0BAA0B,CAAC,QAAQ,CAAC;AAExE,SAAO;GAAE,SAAS;GAAM;GAAW;UAC5B,KAAK;AACZ,QAAM,8BAA8B,IAAI;AACxC,SAAO;GAAE,SAAS;GAAO,OAAO;GAAK;;;;;;;AAQzC,MAAa,kBACX,cAC4E;CAE5E,MAAM,iBAAiB,MAAM,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,KAAI,CAAC,kBAAkB;AACrB,MAAI,cAAc,OAChB,SAAQ,KACN,2KACD;AAGH,SAAO,EAAE,SAAS,OAAO;;CAG3B,MAAM,YAAY,IAAI,sBAAsB;AAG5C,KACE,sBAAsB,oBACtB,OAAO,iBAAiB,qBAAqB,YAC7C;AACA,mBAAiB,iBAAiB,UAAU;AAC5C,SAAO;GAAE,SAAS;GAAM;GAAW;;
|
|
1
|
+
{"version":3,"file":"util.js","names":[],"sources":["../../../../src/components/execution/otel/util.ts"],"sourcesContent":["import { context, trace } from \"@opentelemetry/api\";\nimport type { Instrumentation } from \"@opentelemetry/instrumentation\";\nimport { BasicTracerProvider } from \"@opentelemetry/sdk-trace-base\";\nimport Debug from \"debug\";\nimport { debugPrefix } from \"./consts.ts\";\nimport { InngestSpanProcessor } from \"./processor.ts\";\n\nconst debug = Debug(`${debugPrefix}:createProvider`);\n\nexport type Behaviour = \"createProvider\" | \"extendProvider\" | \"off\" | \"auto\";\nexport type Instrumentations = (Instrumentation | Instrumentation[])[];\n\nexport const createProvider = async (\n _behaviour: Behaviour,\n instrumentations: Instrumentations | undefined = [],\n): Promise<\n | { success: true; processor: InngestSpanProcessor }\n | { success: false; error?: unknown }\n> => {\n try {\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 // Dynamic imports to avoid loading the full auto-instrumentation suite at\n // module evaluation time. These are only needed when creating a new provider,\n // not when extending an existing one. Static imports here caused version\n // conflicts with host app OTel setups (e.g. Sentry) and silently broke\n // inngest.send(). See #1324.\n const { getNodeAutoInstrumentations } = await import(\n \"@opentelemetry/auto-instrumentations-node\"\n );\n const { registerInstrumentations } = await import(\n \"@opentelemetry/instrumentation\"\n );\n const { AnthropicInstrumentation } = await import(\n \"@traceloop/instrumentation-anthropic\"\n );\n const { AsyncHooksContextManager } = await import(\n \"@opentelemetry/context-async-hooks\"\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 } catch (err) {\n debug(\"failed to create provider:\", err);\n return { success: false, error: err };\n }\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 (!existingProvider) {\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\n // OTel SDK v1 exposes addSpanProcessor() on BasicTracerProvider.\n if (\n \"addSpanProcessor\" in existingProvider &&\n typeof existingProvider.addSpanProcessor === \"function\"\n ) {\n existingProvider.addSpanProcessor(processor);\n return { success: true, processor };\n }\n\n // OTel SDK v2 removed addSpanProcessor() — span processors are constructor-only.\n // No public API exists to add processors post-construction (OTel issue #5299),\n // so push into the internal _spanProcessors array.\n // These fields are TypeScript `private` (not #private), so accessible at runtime.\n // TODO: Replace this internal mutation with a SpanProcessor delegator that is\n // installed when creating the provider and can dynamically delegate to\n // processors added later.\n const spanProcessors = getInternalSpanProcessors(existingProvider);\n if (spanProcessors) {\n spanProcessors.push(processor);\n return { success: true, processor };\n }\n\n if (behaviour !== \"auto\") {\n console.warn(\n \"Unable to add InngestSpanProcessor to existing OTel provider. \" +\n \"The provider does not support addSpanProcessor() (OTel SDK v1) \" +\n \"or expose _activeSpanProcessor._spanProcessors (OTel SDK v2).\",\n );\n }\n\n return { success: false };\n};\n\n/**\n * Extract the internal span processors array from a BasicTracerProvider.\n * Returns the mutable array if accessible, undefined otherwise.\n *\n * BasicTracerProvider._activeSpanProcessor is a MultiSpanProcessor,\n * which holds a _spanProcessors: SpanProcessor[] array.\n * Both are TypeScript `private` (not ES #private), so accessible at runtime.\n *\n * Wrapped in try/catch because this accesses internal OTel fields that may\n * change — must never crash the host app.\n */\nfunction getInternalSpanProcessors(provider: unknown): unknown[] | undefined {\n try {\n const active = (provider as Record<string, unknown>)?._activeSpanProcessor;\n if (typeof active !== \"object\" || active === null) return undefined;\n\n const arr = (active as Record<string, unknown>)._spanProcessors;\n return Array.isArray(arr) ? arr : undefined;\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;;;;;AAOA,MAAM,QAAQ,MAAM,GAAG,YAAY,iBAAiB;AAKpD,MAAa,iBAAiB,OAC5B,YACA,mBAAiD,EAAE,KAIhD;AAC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KACN,6LAGD;AAGH,QAAO,EAAE,SAAS,OAAO;;;;;;;;;;;;;AAc3B,SAAS,0BAA0B,UAA0C;AAC3E,KAAI;EACF,MAAM,SAAU,UAAsC;AACtD,MAAI,OAAO,WAAW,YAAY,WAAW,KAAM,QAAO;EAE1D,MAAM,MAAO,OAAmC;AAChD,SAAO,MAAM,QAAQ,IAAI,GAAG,MAAM;SAC5B;AACN"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inngest",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0",
|
|
4
4
|
"description": "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.",
|
|
5
5
|
"main": "./index.cjs",
|
|
6
6
|
"module": "./index.js",
|