inngest 3.47.0 → 3.48.1
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/README.md +0 -7
- package/components/InngestFunction.cjs +1 -1
- package/components/InngestFunction.cjs.map +1 -1
- package/components/InngestFunction.d.cts +17 -0
- package/components/InngestFunction.d.cts.map +1 -1
- package/components/InngestFunction.d.ts +17 -0
- package/components/InngestFunction.d.ts.map +1 -1
- package/components/InngestFunction.js +1 -1
- package/components/InngestFunction.js.map +1 -1
- package/components/execution/otel/processor.cjs +4 -1
- package/components/execution/otel/processor.cjs.map +1 -1
- package/components/execution/otel/processor.d.cts.map +1 -1
- package/components/execution/otel/processor.d.ts.map +1 -1
- package/components/execution/otel/processor.js +4 -1
- package/components/execution/otel/processor.js.map +1 -1
- package/package.json +2 -3
- package/types.cjs.map +1 -1
- package/types.d.cts +22 -4
- package/types.d.cts.map +1 -1
- package/types.d.ts +22 -4
- 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
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# inngest
|
|
2
2
|
|
|
3
|
+
## 3.48.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1205](https://github.com/inngest/inngest-js/pull/1205) [`8ca992e9`](https://github.com/inngest/inngest-js/commit/8ca992e913d1d41c5704dfd7b0d262848b9fb84f) Thanks [@Linell](https://github.com/Linell)! - Include client headers, such as `x-inngest-env` in trace exports.
|
|
8
|
+
|
|
9
|
+
## 3.48.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#1189](https://github.com/inngest/inngest-js/pull/1189) [`28ffbc89`](https://github.com/inngest/inngest-js/commit/28ffbc8962602bbc1a14a10cee724fd5f8747930) Thanks [@jpwilliams](https://github.com/jpwilliams)! - Bring checkpointing out of experimental
|
|
14
|
+
|
|
3
15
|
## 3.47.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -21,7 +21,6 @@ Read the <a href="https://www.inngest.com/docs?ref=github-inngest-js-readme">doc
|
|
|
21
21
|
<p>
|
|
22
22
|
|
|
23
23
|
<a href="https://www.npmjs.com/package/inngest"><img src="https://img.shields.io/npm/v/inngest" /></a>
|
|
24
|
-
<a href="https://jsr.io/@inngest/sdk"><img src="https://jsr.io/badges/@inngest/sdk" /></a>
|
|
25
24
|
<br/>
|
|
26
25
|
<a href="https://www.inngest.com/discord"><img src="https://img.shields.io/discord/842170679536517141?label=discord" /></a>
|
|
27
26
|
<a href="https://twitter.com/inngest"><img src="https://img.shields.io/twitter/follow/inngest?style=social" /></a>
|
|
@@ -64,12 +63,6 @@ Install Inngest:
|
|
|
64
63
|
npm install inngest
|
|
65
64
|
```
|
|
66
65
|
|
|
67
|
-
Or get it from [JSR](https://jsr.io/@inngest/sdk):
|
|
68
|
-
|
|
69
|
-
```bash
|
|
70
|
-
deno add jsr:@inngest/sdk
|
|
71
|
-
```
|
|
72
|
-
|
|
73
66
|
### Writing functions
|
|
74
67
|
|
|
75
68
|
Write serverless functions and background jobs right in your own code:
|
|
@@ -159,7 +159,7 @@ var InngestFunction = class InngestFunction {
|
|
|
159
159
|
}
|
|
160
160
|
shouldAsyncCheckpoint(requestedRunStep, internalFnId, disableImmediateExecution) {
|
|
161
161
|
if (requestedRunStep || !internalFnId || disableImmediateExecution) return;
|
|
162
|
-
return this.opts.experimentalCheckpointing ?? this.client["options"].experimentalCheckpointing;
|
|
162
|
+
return this.opts.checkpointing ?? this.client["options"].checkpointing ?? this.opts.experimentalCheckpointing ?? this.client["options"].experimentalCheckpointing;
|
|
163
163
|
}
|
|
164
164
|
};
|
|
165
165
|
(function(_InngestFunction) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InngestFunction.cjs","names":["queryKeys","fn: FunctionConfig","ret: NonNullable<FunctionConfig[\"cancel\"]>[number]","timeStr","config: FunctionConfig[]","internalEvents","options: InngestExecutionOptions","ExecutionVersion","createV2InngestExecution","createV1InngestExecution","createV0InngestExecution"],"sources":["../../src/components/InngestFunction.ts"],"sourcesContent":["import {\n ExecutionVersion,\n internalEvents,\n queryKeys,\n} from \"../helpers/consts.ts\";\nimport { timeStr } from \"../helpers/strings.ts\";\nimport type { RecursiveTuple, StrictUnion } from \"../helpers/types.ts\";\nimport type {\n Cancellation,\n CheckpointingOptions,\n ConcurrencyOption,\n FunctionConfig,\n Handler,\n TimeStr,\n TimeStrBatch,\n TriggersFromClient,\n} from \"../types.ts\";\nimport type {\n IInngestExecution,\n InngestExecutionOptions,\n} from \"./execution/InngestExecution.ts\";\nimport { createV0InngestExecution } from \"./execution/v0.ts\";\nimport { createV1InngestExecution } from \"./execution/v1.ts\";\nimport { createV2InngestExecution } from \"./execution/v2.ts\";\nimport type { GetEvents, Inngest } from \"./Inngest.ts\";\nimport type {\n InngestMiddleware,\n MiddlewareRegisterReturn,\n} from \"./InngestMiddleware.ts\";\n\n/**\n * A stateless Inngest function, wrapping up function configuration and any\n * in-memory steps to run when triggered.\n *\n * This function can be \"registered\" to create a handler that Inngest can\n * trigger remotely.\n *\n * @public\n */\nexport class InngestFunction<\n TFnOpts extends InngestFunction.Options<\n TClient,\n TMiddleware,\n TTriggers,\n TFailureHandler\n >,\n THandler extends Handler.Any,\n TFailureHandler extends Handler.Any,\n TClient extends Inngest.Any = Inngest.Any,\n TMiddleware extends InngestMiddleware.Stack = InngestMiddleware.Stack,\n TTriggers extends InngestFunction.Trigger<\n TriggersFromClient<TClient>\n >[] = InngestFunction.Trigger<TriggersFromClient<TClient>>[],\n> implements InngestFunction.Like\n{\n static stepId = \"step\";\n static failureSuffix = \"-failure\";\n\n get [Symbol.toStringTag](): typeof InngestFunction.Tag {\n return InngestFunction.Tag;\n }\n\n public readonly opts: TFnOpts;\n // biome-ignore lint/correctness/noUnusedPrivateClassMembers: used internally\n private readonly fn: THandler;\n private readonly onFailureFn?: TFailureHandler;\n protected readonly client: TClient;\n private readonly middleware: Promise<MiddlewareRegisterReturn[]>;\n\n /**\n * A stateless Inngest function, wrapping up function configuration and any\n * in-memory steps to run when triggered.\n *\n * This function can be \"registered\" to create a handler that Inngest can\n * trigger remotely.\n */\n constructor(\n client: TClient,\n\n /**\n * Options\n */\n opts: TFnOpts,\n fn: THandler,\n ) {\n this.client = client;\n this.opts = opts;\n this.fn = fn;\n this.onFailureFn = this.opts.onFailure;\n\n this.middleware = this.client[\"initializeMiddleware\"](\n this.opts.middleware,\n { registerInput: { fn: this }, prefixStack: this.client[\"middleware\"] },\n );\n }\n\n /**\n * The generated or given ID for this function.\n */\n public id(prefix?: string): string {\n return [prefix, this.opts.id].filter(Boolean).join(\"-\");\n }\n\n /**\n * The generated or given ID for this function, prefixed with the app ID. This\n * is used for routing invokes and identifying the function across apps.\n */\n protected get absoluteId(): string {\n return this.id(this.client.id);\n }\n\n /**\n * The name of this function as it will appear in the Inngest Cloud UI.\n */\n public get name(): string {\n return this.opts.name || this.id();\n }\n\n /**\n * The description of this function.\n */\n public get description(): string | undefined {\n return this.opts.description;\n }\n\n /**\n * Retrieve the Inngest config for this function.\n */\n\n // biome-ignore lint/correctness/noUnusedPrivateClassMembers: used within the SDK\n private getConfig({\n baseUrl,\n appPrefix,\n isConnect,\n }: {\n /**\n * Must be provided a URL that will be used to access the function and step.\n * This function can't be expected to know how it will be accessed, so\n * relies on an outside method providing context.\n */\n baseUrl: URL;\n\n /**\n * The prefix for the app that this function is part of.\n */\n appPrefix: string;\n\n /**\n * Whether this function is being used in a Connect handler.\n */\n isConnect?: boolean;\n }): FunctionConfig[] {\n const fnId = this.id(appPrefix);\n const stepUrl = new URL(baseUrl.href);\n stepUrl.searchParams.set(queryKeys.FnId, fnId);\n stepUrl.searchParams.set(queryKeys.StepId, InngestFunction.stepId);\n\n const {\n retries: attempts,\n cancelOn,\n idempotency,\n batchEvents,\n rateLimit,\n throttle,\n concurrency,\n debounce,\n timeouts,\n priority,\n singleton,\n } = this.opts;\n\n /**\n * Convert retries into the format required when defining function\n * configuration.\n */\n const retries = typeof attempts === \"undefined\" ? undefined : { attempts };\n\n const fn: FunctionConfig = {\n id: fnId,\n name: this.name,\n triggers: (this.opts.triggers ?? []).map((trigger) => {\n if (\"event\" in trigger) {\n return {\n event: trigger.event as string,\n expression: trigger.if,\n };\n }\n\n return {\n cron: trigger.cron,\n };\n }),\n steps: {\n [InngestFunction.stepId]: {\n id: InngestFunction.stepId,\n name: InngestFunction.stepId,\n runtime: {\n type: isConnect ? \"ws\" : \"http\",\n url: stepUrl.href,\n },\n retries,\n },\n },\n idempotency,\n batchEvents,\n rateLimit,\n throttle,\n concurrency,\n debounce,\n priority,\n timeouts,\n singleton,\n };\n\n if (cancelOn) {\n fn.cancel = cancelOn.map(({ event, timeout, if: ifStr, match }) => {\n const ret: NonNullable<FunctionConfig[\"cancel\"]>[number] = {\n event,\n };\n\n if (timeout) {\n ret.timeout = timeStr(timeout);\n }\n\n if (match) {\n ret.if = `event.${match} == async.${match}`;\n } else if (ifStr) {\n ret.if = ifStr;\n }\n\n return ret;\n }, []);\n }\n\n const config: FunctionConfig[] = [fn];\n\n if (this.onFailureFn) {\n const id = `${fn.id}${InngestFunction.failureSuffix}`;\n const name = `${fn.name ?? fn.id} (failure)`;\n\n const failureStepUrl = new URL(stepUrl.href);\n failureStepUrl.searchParams.set(queryKeys.FnId, id);\n\n config.push({\n id,\n name,\n triggers: [\n {\n event: internalEvents.FunctionFailed,\n expression: `event.data.function_id == '${fnId}'`,\n },\n ],\n steps: {\n [InngestFunction.stepId]: {\n id: InngestFunction.stepId,\n name: InngestFunction.stepId,\n runtime: {\n type: \"http\",\n url: failureStepUrl.href,\n },\n retries: { attempts: 1 },\n },\n },\n });\n }\n\n return config;\n }\n\n protected createExecution(opts: CreateExecutionOptions): IInngestExecution {\n const options: InngestExecutionOptions = {\n fn: this,\n ...opts.partialOptions,\n };\n\n const versionHandlers = {\n [ExecutionVersion.V2]: () => createV2InngestExecution(options),\n [ExecutionVersion.V1]: () => createV1InngestExecution(options),\n [ExecutionVersion.V0]: () => createV0InngestExecution(options),\n } satisfies Record<ExecutionVersion, () => IInngestExecution>;\n\n return versionHandlers[opts.version]();\n }\n\n // biome-ignore lint/correctness/noUnusedPrivateClassMembers: used within the SDK\n private shouldOptimizeParallelism(): boolean {\n // TODO We should check the commhandler's client instead of this one?\n return (\n this.opts.optimizeParallelism ??\n this.client[\"options\"].optimizeParallelism ??\n false\n );\n }\n\n // biome-ignore lint/correctness/noUnusedPrivateClassMembers: used within the SDK\n private shouldAsyncCheckpoint(\n requestedRunStep: string | undefined,\n internalFnId: string | undefined,\n disableImmediateExecution: boolean,\n ): CheckpointingOptions | undefined {\n if (requestedRunStep || !internalFnId || disableImmediateExecution) {\n return;\n }\n\n // TODO We should check the commhandler's client instead of this one?\n return (\n this.opts.experimentalCheckpointing ??\n this.client[\"options\"].experimentalCheckpointing\n );\n }\n}\n\n/**\n * A stateless Inngest function, wrapping up function configuration and any\n * in-memory steps to run when triggered.\n *\n * This function can be \"registered\" to create a handler that Inngest can\n * trigger remotely.\n *\n * @public\n */\nexport namespace InngestFunction {\n export const Tag = \"Inngest.Function\" as const;\n\n /**\n * Represents any `InngestFunction` instance, regardless of generics and\n * inference.\n */\n export type Any = InngestFunction<\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n any,\n Handler.Any,\n Handler.Any,\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n any,\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n any,\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n any\n >;\n\n export interface Like {\n readonly [Symbol.toStringTag]: typeof InngestFunction.Tag;\n }\n\n /**\n * A user-friendly method of specifying a trigger for an Inngest function.\n *\n * @public\n */\n export type Trigger<T extends string> = StrictUnion<\n | {\n event: T;\n if?: string;\n }\n | {\n cron: string;\n }\n >;\n\n export type GetOptions<T extends InngestFunction.Any> =\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n T extends InngestFunction<infer O, any, any, any, any, any> ? O : never;\n\n /**\n * A set of options for configuring an Inngest function.\n *\n * @public\n */\n export interface Options<\n TClient extends Inngest.Any = Inngest.Any,\n TMiddleware extends InngestMiddleware.Stack = InngestMiddleware.Stack,\n TTriggers extends InngestFunction.Trigger<\n TriggersFromClient<TClient>\n >[] = InngestFunction.Trigger<TriggersFromClient<TClient>>[],\n TFailureHandler extends Handler.Any = Handler.Any,\n > {\n triggers?: TTriggers;\n\n /**\n * An unique ID used to identify the function. This is used internally for\n * versioning and referring to your function, so should not change between\n * deployments.\n *\n * If you'd like to set a prettier name for your function, use the `name`\n * option.\n */\n id: string;\n\n /**\n * A name for the function as it will appear in the Inngest Cloud UI.\n */\n name?: string;\n\n /**\n * A description of the function.\n */\n description?: string;\n\n /**\n * Concurrency specifies a limit on the total number of concurrent steps that\n * can occur across all runs of the function. A value of 0 (or undefined) means\n * use the maximum available concurrency.\n *\n * Specifying just a number means specifying only the concurrency limit. A\n * maximum of two concurrency options can be specified.\n */\n concurrency?:\n | number\n | ConcurrencyOption\n | RecursiveTuple<ConcurrencyOption, 2>;\n\n /**\n * batchEvents specifies the batch configuration on when this function\n * should be invoked when one of the requirements are fulfilled.\n */\n batchEvents?: {\n /**\n * The maximum number of events to be consumed in one batch.\n * Check the pricing page to verify the limit for each plan.\n */\n maxSize: number;\n\n /**\n * How long to wait before invoking the function with a list of events.\n * If timeout is reached, the function will be invoked with a batch\n * even if it's not filled up to `maxSize`.\n *\n * Expects a time string such as 1s, 60s or 15m15s.\n */\n timeout: TimeStrBatch;\n\n /**\n * An optional key to use for batching.\n *\n * See [batch documentation](https://innge.st/batching) for more\n * information on how to use `key` expressions.\n */\n key?: string;\n\n /**\n * An optional boolean expression to determine an event's eligibility for batching\n *\n * See [batch documentation](https://innge.st/batching) for more\n * information on how to use `if` expressions.\n */\n if?: string;\n };\n\n /**\n * Allow the specification of an idempotency key using event data. If\n * specified, this overrides the `rateLimit` object.\n */\n idempotency?: string;\n\n /**\n * Rate limit function runs, only running them a given number of times (limit) per\n * period. Note that rate limit is a lossy, hard limit. Once the limit is hit,\n * new runs will be skipped. To enqueue work when a rate limit is hit, use the\n * {@link throttle} parameter.\n */\n rateLimit?: {\n /**\n * An optional key to use for rate limiting, similar to idempotency.\n */\n key?: string;\n\n /**\n * The number of times to allow the function to run per the given `period`.\n */\n limit: number;\n\n /**\n * The period of time to allow the function to run `limit` times.\n */\n period: TimeStr;\n };\n\n /**\n * Throttles function runs, only running them a given number of times (limit) per\n * period. Once the limit is hit, new runs will be enqueued and will start when there's\n * capacity. This may lead to a large backlog. For hard rate limiting, use the\n * {@link rateLimit} parameter.\n */\n throttle?: {\n /**\n * An optional expression which returns a throttling key for controlling throttling.\n * Every unique key is its own throttle limit. Event data may be used within this\n * expression, eg \"event.data.user_id\".\n */\n key?: string;\n\n /**\n * The total number of runs allowed to start within the given `period`. The limit is\n * applied evenly over the period.\n */\n limit: number;\n\n /**\n * The period of time for the rate limit. Run starts are evenly spaced through\n * the given period. The minimum granularity is 1 second.\n */\n period: TimeStr;\n\n /**\n * The number of runs allowed to start in the given window in a single burst.\n * A burst > 1 bypasses smoothing for the burst and allows many runs to start\n * at once, if desired. Defaults to 1, which disables bursting.\n */\n burst?: number;\n };\n\n /**\n * Debounce delays functions for the `period` specified. If an event is sent,\n * the function will not run until at least `period` has elapsed.\n *\n * If any new events are received that match the same debounce `key`, the\n * function is rescheduled for another `period` delay, and the triggering\n * event is replaced with the latest event received.\n *\n * See the [Debounce documentation](https://innge.st/debounce) for more\n * information.\n */\n debounce?: {\n /**\n * An optional key to use for debouncing.\n *\n * See [Debounce documentation](https://innge.st/debounce) for more\n * information on how to use `key` expressions.\n */\n key?: string;\n\n /**\n * The period of time to delay after receiving the last trigger to run the\n * function.\n *\n * See [Debounce documentation](https://innge.st/debounce) for more\n * information.\n */\n period: TimeStr;\n\n /**\n * The maximum time that a debounce can be extended before running.\n * If events are continually received within the given period, a function\n * will always run after the given timeout period.\n *\n * See [Debounce documentation](https://innge.st/debounce) for more\n * information.\n */\n timeout?: TimeStr;\n };\n\n /**\n * Configure how the priority of a function run is decided when multiple\n * functions are triggered at the same time.\n *\n * See the [Priority documentation](https://innge.st/priority) for more\n * information.\n */\n priority?: {\n /**\n * An expression to use to determine the priority of a function run. The\n * expression can return a number between `-600` and `600`, where `600`\n * declares that this run should be executed before any others enqueued in\n * the last 600 seconds (10 minutes), and `-600` declares that this run\n * should be executed after any others enqueued in the last 600 seconds.\n *\n * See the [Priority documentation](https://innge.st/priority) for more\n * information.\n */\n run?: string;\n };\n\n /**\n * Configure timeouts for the function. If any of the timeouts are hit, the\n * function run will be cancelled.\n */\n timeouts?: {\n /**\n * Start represents the timeout for starting a function. If the time\n * between scheduling and starting a function exceeds this value, the\n * function will be cancelled.\n *\n * This is, essentially, the amount of time that a function sits in the\n * queue before starting.\n *\n * A function may exceed this duration because of concurrency limits,\n * throttling, etc.\n */\n start?: TimeStr;\n\n /**\n * Finish represents the time between a function starting and the function\n * finishing. If a function takes longer than this time to finish, the\n * function is marked as cancelled.\n *\n * The start time is taken from the time that the first successful\n * function request begins, and does not include the time spent in the\n * queue before the function starts.\n *\n * Note that if the final request to a function begins before this\n * timeout, and completes after this timeout, the function will succeed.\n */\n finish?: TimeStr;\n };\n\n /**\n * Ensures that only one run of the function is active at a time for a given key.\n * If a new run is triggered while another is still in progress with the same key,\n * the new run will either be skipped or replace the active one, depending on the mode.\n *\n * This is useful for deduplication or enforcing exclusive execution.\n */\n singleton?: {\n /**\n * An optional key expression used to scope singleton execution.\n * Each unique key has its own singleton lock. Event data can be referenced,\n * e.g. \"event.data.user_id\".\n */\n key?: string;\n\n /**\n * Determines how to handle new runs when one is already active for the same key.\n * - `\"skip\"` skips the new run.\n * - `\"cancel\"` cancels the existing run and starts the new one.\n */\n mode: \"skip\" | \"cancel\";\n };\n\n cancelOn?: Cancellation<GetEvents<TClient, true>>[];\n\n /**\n * Specifies the maximum number of retries for all steps across this function.\n *\n * Can be a number from `0` to `20`. Defaults to `3`.\n */\n retries?:\n | 0\n | 1\n | 2\n | 3\n | 4\n | 5\n | 6\n | 7\n | 8\n | 9\n | 10\n | 11\n | 12\n | 13\n | 14\n | 15\n | 16\n | 17\n | 18\n | 19\n | 20;\n\n /**\n * Provide a function to be called if your function fails, meaning\n * that it ran out of retries and was unable to complete successfully.\n *\n * This is useful for sending warning notifications or cleaning up\n * after a failure and supports all the same functionality as a\n * regular handler.\n */\n onFailure?: TFailureHandler;\n\n /**\n * Define a set of middleware that can be registered to hook into\n * various lifecycles of the SDK and affect input and output of\n * Inngest functionality.\n *\n * See {@link https://innge.st/middleware}\n *\n * @example\n *\n * ```ts\n * export const inngest = new Inngest({\n * middleware: [\n * new InngestMiddleware({\n * name: \"My Middleware\",\n * init: () => {\n * // ...\n * }\n * })\n * ]\n * });\n * ```\n */\n middleware?: TMiddleware;\n\n /**\n * If `true`, parallel steps within this function are optimized to reduce\n * traffic during `Promise` resolution, which can hugely reduce the time\n * taken and number of requests for each run.\n *\n * Note that this will be the default behaviour in v4 and in its current\n * form will cause `Promise.*()` to wait for all promises to settle before\n * resolving.\n *\n * Providing this value here will overwrite the same value given on the\n * client.\n *\n * @default false\n */\n optimizeParallelism?: boolean;\n\n /**\n * Whether or not to use checkpointing for this function's executions.\n *\n * If `true`, enables checkpointing with default settings, which is a safe,\n * blocking version of checkpointing, where we check in with Inngest after\n * every step is run.\n *\n * If an object, you can tweak the settings to batch, set a maximum runtime\n * before going async, and more. Note that if your server dies before the\n * checkpoint completes, step data will be lost and steps will be rerun.\n *\n * We recommend starting with the default `true` configuration and only tweak\n * the parameters directly if necessary.\n */\n experimentalCheckpointing?: CheckpointingOptions;\n }\n}\n\nexport type CreateExecutionOptions = {\n version: ExecutionVersion;\n partialOpt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AAWC,oCAAyB,QAAQ;IAC7DD,gCAAiB,WAAWE,oCAAyB,QAAQ;IAC7DF,gCAAiB,WAAWG,oCAAyB,QAAQ;GAC/D,CAEsB,KAAK,UAAU;;CAIxC,AAAQ,4BAAqC;AAE3C,SACE,KAAK,KAAK,uBACV,KAAK,OAAO,WAAW,uBACvB;;CAKJ,AAAQ,sBACN,kBACA,cACA,2BACkC;AAClC,MAAI,oBAAoB,CAAC,gBAAgB,0BACvC;AAIF,SACE,KAAK,KAAK,6BACV,KAAK,OAAO,WAAW;;;;wBAeR"}
|
|
1
|
+
{"version":3,"file":"InngestFunction.cjs","names":["queryKeys","fn: FunctionConfig","ret: NonNullable<FunctionConfig[\"cancel\"]>[number]","timeStr","config: FunctionConfig[]","internalEvents","options: InngestExecutionOptions","ExecutionVersion","createV2InngestExecution","createV1InngestExecution","createV0InngestExecution"],"sources":["../../src/components/InngestFunction.ts"],"sourcesContent":["import {\n ExecutionVersion,\n internalEvents,\n queryKeys,\n} from \"../helpers/consts.ts\";\nimport { timeStr } from \"../helpers/strings.ts\";\nimport type { RecursiveTuple, StrictUnion } from \"../helpers/types.ts\";\nimport type {\n Cancellation,\n CheckpointingOptions,\n ConcurrencyOption,\n FunctionConfig,\n Handler,\n TimeStr,\n TimeStrBatch,\n TriggersFromClient,\n} from \"../types.ts\";\nimport type {\n IInngestExecution,\n InngestExecutionOptions,\n} from \"./execution/InngestExecution.ts\";\nimport { createV0InngestExecution } from \"./execution/v0.ts\";\nimport { createV1InngestExecution } from \"./execution/v1.ts\";\nimport { createV2InngestExecution } from \"./execution/v2.ts\";\nimport type { GetEvents, Inngest } from \"./Inngest.ts\";\nimport type {\n InngestMiddleware,\n MiddlewareRegisterReturn,\n} from \"./InngestMiddleware.ts\";\n\n/**\n * A stateless Inngest function, wrapping up function configuration and any\n * in-memory steps to run when triggered.\n *\n * This function can be \"registered\" to create a handler that Inngest can\n * trigger remotely.\n *\n * @public\n */\nexport class InngestFunction<\n TFnOpts extends InngestFunction.Options<\n TClient,\n TMiddleware,\n TTriggers,\n TFailureHandler\n >,\n THandler extends Handler.Any,\n TFailureHandler extends Handler.Any,\n TClient extends Inngest.Any = Inngest.Any,\n TMiddleware extends InngestMiddleware.Stack = InngestMiddleware.Stack,\n TTriggers extends InngestFunction.Trigger<\n TriggersFromClient<TClient>\n >[] = InngestFunction.Trigger<TriggersFromClient<TClient>>[],\n> implements InngestFunction.Like\n{\n static stepId = \"step\";\n static failureSuffix = \"-failure\";\n\n get [Symbol.toStringTag](): typeof InngestFunction.Tag {\n return InngestFunction.Tag;\n }\n\n public readonly opts: TFnOpts;\n // biome-ignore lint/correctness/noUnusedPrivateClassMembers: used internally\n private readonly fn: THandler;\n private readonly onFailureFn?: TFailureHandler;\n protected readonly client: TClient;\n private readonly middleware: Promise<MiddlewareRegisterReturn[]>;\n\n /**\n * A stateless Inngest function, wrapping up function configuration and any\n * in-memory steps to run when triggered.\n *\n * This function can be \"registered\" to create a handler that Inngest can\n * trigger remotely.\n */\n constructor(\n client: TClient,\n\n /**\n * Options\n */\n opts: TFnOpts,\n fn: THandler,\n ) {\n this.client = client;\n this.opts = opts;\n this.fn = fn;\n this.onFailureFn = this.opts.onFailure;\n\n this.middleware = this.client[\"initializeMiddleware\"](\n this.opts.middleware,\n { registerInput: { fn: this }, prefixStack: this.client[\"middleware\"] },\n );\n }\n\n /**\n * The generated or given ID for this function.\n */\n public id(prefix?: string): string {\n return [prefix, this.opts.id].filter(Boolean).join(\"-\");\n }\n\n /**\n * The generated or given ID for this function, prefixed with the app ID. This\n * is used for routing invokes and identifying the function across apps.\n */\n protected get absoluteId(): string {\n return this.id(this.client.id);\n }\n\n /**\n * The name of this function as it will appear in the Inngest Cloud UI.\n */\n public get name(): string {\n return this.opts.name || this.id();\n }\n\n /**\n * The description of this function.\n */\n public get description(): string | undefined {\n return this.opts.description;\n }\n\n /**\n * Retrieve the Inngest config for this function.\n */\n\n // biome-ignore lint/correctness/noUnusedPrivateClassMembers: used within the SDK\n private getConfig({\n baseUrl,\n appPrefix,\n isConnect,\n }: {\n /**\n * Must be provided a URL that will be used to access the function and step.\n * This function can't be expected to know how it will be accessed, so\n * relies on an outside method providing context.\n */\n baseUrl: URL;\n\n /**\n * The prefix for the app that this function is part of.\n */\n appPrefix: string;\n\n /**\n * Whether this function is being used in a Connect handler.\n */\n isConnect?: boolean;\n }): FunctionConfig[] {\n const fnId = this.id(appPrefix);\n const stepUrl = new URL(baseUrl.href);\n stepUrl.searchParams.set(queryKeys.FnId, fnId);\n stepUrl.searchParams.set(queryKeys.StepId, InngestFunction.stepId);\n\n const {\n retries: attempts,\n cancelOn,\n idempotency,\n batchEvents,\n rateLimit,\n throttle,\n concurrency,\n debounce,\n timeouts,\n priority,\n singleton,\n } = this.opts;\n\n /**\n * Convert retries into the format required when defining function\n * configuration.\n */\n const retries = typeof attempts === \"undefined\" ? undefined : { attempts };\n\n const fn: FunctionConfig = {\n id: fnId,\n name: this.name,\n triggers: (this.opts.triggers ?? []).map((trigger) => {\n if (\"event\" in trigger) {\n return {\n event: trigger.event as string,\n expression: trigger.if,\n };\n }\n\n return {\n cron: trigger.cron,\n };\n }),\n steps: {\n [InngestFunction.stepId]: {\n id: InngestFunction.stepId,\n name: InngestFunction.stepId,\n runtime: {\n type: isConnect ? \"ws\" : \"http\",\n url: stepUrl.href,\n },\n retries,\n },\n },\n idempotency,\n batchEvents,\n rateLimit,\n throttle,\n concurrency,\n debounce,\n priority,\n timeouts,\n singleton,\n };\n\n if (cancelOn) {\n fn.cancel = cancelOn.map(({ event, timeout, if: ifStr, match }) => {\n const ret: NonNullable<FunctionConfig[\"cancel\"]>[number] = {\n event,\n };\n\n if (timeout) {\n ret.timeout = timeStr(timeout);\n }\n\n if (match) {\n ret.if = `event.${match} == async.${match}`;\n } else if (ifStr) {\n ret.if = ifStr;\n }\n\n return ret;\n }, []);\n }\n\n const config: FunctionConfig[] = [fn];\n\n if (this.onFailureFn) {\n const id = `${fn.id}${InngestFunction.failureSuffix}`;\n const name = `${fn.name ?? fn.id} (failure)`;\n\n const failureStepUrl = new URL(stepUrl.href);\n failureStepUrl.searchParams.set(queryKeys.FnId, id);\n\n config.push({\n id,\n name,\n triggers: [\n {\n event: internalEvents.FunctionFailed,\n expression: `event.data.function_id == '${fnId}'`,\n },\n ],\n steps: {\n [InngestFunction.stepId]: {\n id: InngestFunction.stepId,\n name: InngestFunction.stepId,\n runtime: {\n type: \"http\",\n url: failureStepUrl.href,\n },\n retries: { attempts: 1 },\n },\n },\n });\n }\n\n return config;\n }\n\n protected createExecution(opts: CreateExecutionOptions): IInngestExecution {\n const options: InngestExecutionOptions = {\n fn: this,\n ...opts.partialOptions,\n };\n\n const versionHandlers = {\n [ExecutionVersion.V2]: () => createV2InngestExecution(options),\n [ExecutionVersion.V1]: () => createV1InngestExecution(options),\n [ExecutionVersion.V0]: () => createV0InngestExecution(options),\n } satisfies Record<ExecutionVersion, () => IInngestExecution>;\n\n return versionHandlers[opts.version]();\n }\n\n // biome-ignore lint/correctness/noUnusedPrivateClassMembers: used within the SDK\n private shouldOptimizeParallelism(): boolean {\n // TODO We should check the commhandler's client instead of this one?\n return (\n this.opts.optimizeParallelism ??\n this.client[\"options\"].optimizeParallelism ??\n false\n );\n }\n\n // biome-ignore lint/correctness/noUnusedPrivateClassMembers: used within the SDK\n private shouldAsyncCheckpoint(\n requestedRunStep: string | undefined,\n internalFnId: string | undefined,\n disableImmediateExecution: boolean,\n ): CheckpointingOptions | undefined {\n if (requestedRunStep || !internalFnId || disableImmediateExecution) {\n return;\n }\n\n // TODO We should check the commhandler's client instead of this one?\n return (\n this.opts.checkpointing ??\n this.client[\"options\"].checkpointing ??\n this.opts.experimentalCheckpointing ??\n this.client[\"options\"].experimentalCheckpointing\n );\n }\n}\n\n/**\n * A stateless Inngest function, wrapping up function configuration and any\n * in-memory steps to run when triggered.\n *\n * This function can be \"registered\" to create a handler that Inngest can\n * trigger remotely.\n *\n * @public\n */\nexport namespace InngestFunction {\n export const Tag = \"Inngest.Function\" as const;\n\n /**\n * Represents any `InngestFunction` instance, regardless of generics and\n * inference.\n */\n export type Any = InngestFunction<\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n any,\n Handler.Any,\n Handler.Any,\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n any,\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n any,\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n any\n >;\n\n export interface Like {\n readonly [Symbol.toStringTag]: typeof InngestFunction.Tag;\n }\n\n /**\n * A user-friendly method of specifying a trigger for an Inngest function.\n *\n * @public\n */\n export type Trigger<T extends string> = StrictUnion<\n | {\n event: T;\n if?: string;\n }\n | {\n cron: string;\n }\n >;\n\n export type GetOptions<T extends InngestFunction.Any> =\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n T extends InngestFunction<infer O, any, any, any, any, any> ? O : never;\n\n /**\n * A set of options for configuring an Inngest function.\n *\n * @public\n */\n export interface Options<\n TClient extends Inngest.Any = Inngest.Any,\n TMiddleware extends InngestMiddleware.Stack = InngestMiddleware.Stack,\n TTriggers extends InngestFunction.Trigger<\n TriggersFromClient<TClient>\n >[] = InngestFunction.Trigger<TriggersFromClient<TClient>>[],\n TFailureHandler extends Handler.Any = Handler.Any,\n > {\n triggers?: TTriggers;\n\n /**\n * An unique ID used to identify the function. This is used internally for\n * versioning and referring to your function, so should not change between\n * deployments.\n *\n * If you'd like to set a prettier name for your function, use the `name`\n * option.\n */\n id: string;\n\n /**\n * A name for the function as it will appear in the Inngest Cloud UI.\n */\n name?: string;\n\n /**\n * A description of the function.\n */\n description?: string;\n\n /**\n * Concurrency specifies a limit on the total number of concurrent steps that\n * can occur across all runs of the function. A value of 0 (or undefined) means\n * use the maximum available concurrency.\n *\n * Specifying just a number means specifying only the concurrency limit. A\n * maximum of two concurrency options can be specified.\n */\n concurrency?:\n | number\n | ConcurrencyOption\n | RecursiveTuple<ConcurrencyOption, 2>;\n\n /**\n * batchEvents specifies the batch configuration on when this function\n * should be invoked when one of the requirements are fulfilled.\n */\n batchEvents?: {\n /**\n * The maximum number of events to be consumed in one batch.\n * Check the pricing page to verify the limit for each plan.\n */\n maxSize: number;\n\n /**\n * How long to wait before invoking the function with a list of events.\n * If timeout is reached, the function will be invoked with a batch\n * even if it's not filled up to `maxSize`.\n *\n * Expects a time string such as 1s, 60s or 15m15s.\n */\n timeout: TimeStrBatch;\n\n /**\n * An optional key to use for batching.\n *\n * See [batch documentation](https://innge.st/batching) for more\n * information on how to use `key` expressions.\n */\n key?: string;\n\n /**\n * An optional boolean expression to determine an event's eligibility for batching\n *\n * See [batch documentation](https://innge.st/batching) for more\n * information on how to use `if` expressions.\n */\n if?: string;\n };\n\n /**\n * Allow the specification of an idempotency key using event data. If\n * specified, this overrides the `rateLimit` object.\n */\n idempotency?: string;\n\n /**\n * Rate limit function runs, only running them a given number of times (limit) per\n * period. Note that rate limit is a lossy, hard limit. Once the limit is hit,\n * new runs will be skipped. To enqueue work when a rate limit is hit, use the\n * {@link throttle} parameter.\n */\n rateLimit?: {\n /**\n * An optional key to use for rate limiting, similar to idempotency.\n */\n key?: string;\n\n /**\n * The number of times to allow the function to run per the given `period`.\n */\n limit: number;\n\n /**\n * The period of time to allow the function to run `limit` times.\n */\n period: TimeStr;\n };\n\n /**\n * Throttles function runs, only running them a given number of times (limit) per\n * period. Once the limit is hit, new runs will be enqueued and will start when there's\n * capacity. This may lead to a large backlog. For hard rate limiting, use the\n * {@link rateLimit} parameter.\n */\n throttle?: {\n /**\n * An optional expression which returns a throttling key for controlling throttling.\n * Every unique key is its own throttle limit. Event data may be used within this\n * expression, eg \"event.data.user_id\".\n */\n key?: string;\n\n /**\n * The total number of runs allowed to start within the given `period`. The limit is\n * applied evenly over the period.\n */\n limit: number;\n\n /**\n * The period of time for the rate limit. Run starts are evenly spaced through\n * the given period. The minimum granularity is 1 second.\n */\n period: TimeStr;\n\n /**\n * The number of runs allowed to start in the given window in a single burst.\n * A burst > 1 bypasses smoothing for the burst and allows many runs to start\n * at once, if desired. Defaults to 1, which disables bursting.\n */\n burst?: number;\n };\n\n /**\n * Debounce delays functions for the `period` specified. If an event is sent,\n * the function will not run until at least `period` has elapsed.\n *\n * If any new events are received that match the same debounce `key`, the\n * function is rescheduled for another `period` delay, and the triggering\n * event is replaced with the latest event received.\n *\n * See the [Debounce documentation](https://innge.st/debounce) for more\n * information.\n */\n debounce?: {\n /**\n * An optional key to use for debouncing.\n *\n * See [Debounce documentation](https://innge.st/debounce) for more\n * information on how to use `key` expressions.\n */\n key?: string;\n\n /**\n * The period of time to delay after receiving the last trigger to run the\n * function.\n *\n * See [Debounce documentation](https://innge.st/debounce) for more\n * information.\n */\n period: TimeStr;\n\n /**\n * The maximum time that a debounce can be extended before running.\n * If events are continually received within the given period, a function\n * will always run after the given timeout period.\n *\n * See [Debounce documentation](https://innge.st/debounce) for more\n * information.\n */\n timeout?: TimeStr;\n };\n\n /**\n * Configure how the priority of a function run is decided when multiple\n * functions are triggered at the same time.\n *\n * See the [Priority documentation](https://innge.st/priority) for more\n * information.\n */\n priority?: {\n /**\n * An expression to use to determine the priority of a function run. The\n * expression can return a number between `-600` and `600`, where `600`\n * declares that this run should be executed before any others enqueued in\n * the last 600 seconds (10 minutes), and `-600` declares that this run\n * should be executed after any others enqueued in the last 600 seconds.\n *\n * See the [Priority documentation](https://innge.st/priority) for more\n * information.\n */\n run?: string;\n };\n\n /**\n * Configure timeouts for the function. If any of the timeouts are hit, the\n * function run will be cancelled.\n */\n timeouts?: {\n /**\n * Start represents the timeout for starting a function. If the time\n * between scheduling and starting a function exceeds this value, the\n * function will be cancelled.\n *\n * This is, essentially, the amount of time that a function sits in the\n * queue before starting.\n *\n * A function may exceed this duration because of concurrency limits,\n * throttling, etc.\n */\n start?: TimeStr;\n\n /**\n * Finish represents the time between a function starting and the function\n * finishing. If a function takes longer than this time to finish, the\n * function is marked as cancelled.\n *\n * The start time is taken from the time that the first successful\n * function request begins, and does not include the time spent in the\n * queue before the function starts.\n *\n * Note that if the final request to a function begins before this\n * timeout, and completes after this timeout, the function will succeed.\n */\n finish?: TimeStr;\n };\n\n /**\n * Ensures that only one run of the function is active at a time for a given key.\n * If a new run is triggered while another is still in progress with the same key,\n * the new run will either be skipped or replace the active one, depending on the mode.\n *\n * This is useful for deduplication or enforcing exclusive execution.\n */\n singleton?: {\n /**\n * An optional key expression used to scope singleton execution.\n * Each unique key has its own singleton lock. Event data can be referenced,\n * e.g. \"event.data.user_id\".\n */\n key?: string;\n\n /**\n * Determines how to handle new runs when one is already active for the same key.\n * - `\"skip\"` skips the new run.\n * - `\"cancel\"` cancels the existing run and starts the new one.\n */\n mode: \"skip\" | \"cancel\";\n };\n\n cancelOn?: Cancellation<GetEvents<TClient, true>>[];\n\n /**\n * Specifies the maximum number of retries for all steps across this function.\n *\n * Can be a number from `0` to `20`. Defaults to `3`.\n */\n retries?:\n | 0\n | 1\n | 2\n | 3\n | 4\n | 5\n | 6\n | 7\n | 8\n | 9\n | 10\n | 11\n | 12\n | 13\n | 14\n | 15\n | 16\n | 17\n | 18\n | 19\n | 20;\n\n /**\n * Provide a function to be called if your function fails, meaning\n * that it ran out of retries and was unable to complete successfully.\n *\n * This is useful for sending warning notifications or cleaning up\n * after a failure and supports all the same functionality as a\n * regular handler.\n */\n onFailure?: TFailureHandler;\n\n /**\n * Define a set of middleware that can be registered to hook into\n * various lifecycles of the SDK and affect input and output of\n * Inngest functionality.\n *\n * See {@link https://innge.st/middleware}\n *\n * @example\n *\n * ```ts\n * export const inngest = new Inngest({\n * middleware: [\n * new InngestMiddleware({\n * name: \"My Middleware\",\n * init: () => {\n * // ...\n * }\n * })\n * ]\n * });\n * ```\n */\n middleware?: TMiddleware;\n\n /**\n * If `true`, parallel steps within this function are optimized to reduce\n * traffic during `Promise` resolution, which can hugely reduce the time\n * taken and number of requests for each run.\n *\n * Note that this will be the default behaviour in v4 and in its current\n * form will cause `Promise.*()` to wait for all promises to settle before\n * resolving.\n *\n * Providing this value here will overwrite the same value given on the\n * client.\n *\n * @default false\n */\n optimizeParallelism?: boolean;\n\n /**\n * Whether or not to use checkpointing for this function's executions.\n *\n * If `true`, enables checkpointing with default settings, which is a safe,\n * blocking version of checkpointing, where we check in with Inngest after\n * every step is run.\n *\n * If an object, you can tweak the settings to batch, set a maximum runtime\n * before going async, and more. Note that if your server dies before the\n * checkpoint completes, step data will be lost and steps will be rerun.\n *\n * We recommend starting with the default `true` configuration and only tweak\n * the parameters directly if necessary.\n *\n * @deprecated Use `checkpointing` instead.\n */\n experimentalCheckpointing?: CheckpointingOptions;\n\n /**\n * Whether or not to use checkpointing for this function's executions.\n *\n * If `true`, enables checkpointing with default settings, which is a safe,\n * blocking version of checkpointing, where we check in with Inngest after\n * every step is run.\n *\n * If an object, you can tweak the settings to batch, set a maximum runtime\n * before going async, and more. Note that if your server dies before the\n * checkpoint completes, step data will be lost and steps will be rerun.\n *\n * We recommend starting with the default `true` configuration and only tweak\n * the parameters directly if necessary.\n */\n checkpointing?: CheckpointingOptions;\n }\n}\n\nexport type CreateExecutionOptions = {\n version: ExecutionVersion;\n partialOptions: Omit<InngestExecutionOptions, \"fn\">;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAuCA,IAAa,kBAAb,MAAa,gBAeb;CACE,OAAO,SAAS;CAChB,OAAO,gBAAgB;CAEvB,KAAK,OAAO,eAA2C;AACrD,SAAO,gBAAgB;;CAGzB,AAAgB;CAEhB,AAAiB;CACjB,AAAiB;CACjB,AAAmB;CACnB,AAAiB;;;;;;;;CASjB,YACE,QAKA,MACA,IACA;AACA,OAAK,SAAS;AACd,OAAK,OAAO;AACZ,OAAK,KAAK;AACV,OAAK,cAAc,KAAK,KAAK;AAE7B,OAAK,aAAa,KAAK,OAAO,wBAC5B,KAAK,KAAK,YACV;GAAE,eAAe,EAAE,IAAI,MAAM;GAAE,aAAa,KAAK,OAAO;GAAe,CACxE;;;;;CAMH,AAAO,GAAG,QAAyB;AACjC,SAAO,CAAC,QAAQ,KAAK,KAAK,G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AK;AAGX,UAAO;KACN,EAAE,CAAC;EAGR,MAAMC,SAA2B,CAAC,GAAG;AAErC,MAAI,KAAK,aAAa;GACpB,MAAM,KAAK,GAAG,GAAG,KAAK,gBAAgB;GACtC,MAAM,OAAO,GAAG,GAAG,QAAQ,GAAG,GAAG;GAEjC,MAAM,iBAAiB,IAAI,IAAI,QAAQ,KAAK;AAC5C,kBAAe,aAAa,IAAIJ,yBAAU,MAAM,GAAG;AAEnD,UAAO,KAAK;IACV;IACA;IACA,UAAU,CACR;KACE,OAAOK,8BAAe;KACtB,YAAY,8BAA8B,KAAK;KAChD,CACF;IACD,OAAO,GACJ,gBAAgB,SAAS;KACxB,IAAI,gBAAgB;KACpB,MAAM,gBAAgB;KACtB,SAAS;MACP,MAAM;MACN,KAAK,eAAe;MACrB;KACD,SAAS,EAAE,UAAU,GAAG;KACzB,EACF;IACF,CAAC;;AAGJ,SAAO;;CAGT,AAAU,gBAAgB,MAAiD;EACzE,MAAMC,UAAmC;GACvC,IAAI;GACJ,GAAG,KAAK;GACT;AAQD,SANwB;IACrBC,gCAAiB,WAAWC,oCAAyB,QAAQ;IAC7DD,gCAAiB,WAAWE,oCAAyB,QAAQ;IAC7DF,gCAAiB,WAAWG,oCAAyB,QAAQ;GAC/D,CAEsB,KAAK,UAAU;;CAIxC,AAAQ,4BAAqC;AAE3C,SACE,KAAK,KAAK,uBACV,KAAK,OAAO,WAAW,uBACvB;;CAKJ,AAAQ,sBACN,kBACA,cACA,2BACkC;AAClC,MAAI,oBAAoB,CAAC,gBAAgB,0BACvC;AAIF,SACE,KAAK,KAAK,iBACV,KAAK,OAAO,WAAW,iBACvB,KAAK,KAAK,6BACV,KAAK,OAAO,WAAW;;;;wBAeR"}
|
|
@@ -390,8 +390,25 @@ declare namespace InngestFunction {
|
|
|
390
390
|
*
|
|
391
391
|
* We recommend starting with the default `true` configuration and only tweak
|
|
392
392
|
* the parameters directly if necessary.
|
|
393
|
+
*
|
|
394
|
+
* @deprecated Use `checkpointing` instead.
|
|
393
395
|
*/
|
|
394
396
|
experimentalCheckpointing?: CheckpointingOptions;
|
|
397
|
+
/**
|
|
398
|
+
* Whether or not to use checkpointing for this function's executions.
|
|
399
|
+
*
|
|
400
|
+
* If `true`, enables checkpointing with default settings, which is a safe,
|
|
401
|
+
* blocking version of checkpointing, where we check in with Inngest after
|
|
402
|
+
* every step is run.
|
|
403
|
+
*
|
|
404
|
+
* If an object, you can tweak the settings to batch, set a maximum runtime
|
|
405
|
+
* before going async, and more. Note that if your server dies before the
|
|
406
|
+
* checkpoint completes, step data will be lost and steps will be rerun.
|
|
407
|
+
*
|
|
408
|
+
* We recommend starting with the default `true` configuration and only tweak
|
|
409
|
+
* the parameters directly if necessary.
|
|
410
|
+
*/
|
|
411
|
+
checkpointing?: CheckpointingOptions;
|
|
395
412
|
}
|
|
396
413
|
}
|
|
397
414
|
type CreateExecutionOptions = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InngestFunction.d.cts","names":[],"sources":["../../src/components/InngestFunction.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;AAuCA;;;;;;;AAOmB,cAPN,eAOc,CAAA,gBANT,eAAA,CAAgB,OAMP,CALvB,OAKuB,EAJvB,WAIuB,EAHvB,SAGuB,EAFvB,eAEuB,CAAA,EAAA,iBAAR,OAAA,CAAQ,GAAA,EAAA,wBACD,OAAA,CAAQ,GADP,EAAA,gBAET,OAAA,CAAQ,GAFC,GAEK,OAAA,CAAQ,GAFb,EAAA,oBAGL,iBAAA,CAAkB,KAHb,GAGqB,iBAAA,CAAkB,KAHvC,EAAA,kBAIP,eAAA,CAAgB,OAJT,CAKvB,kBALuB,CAKJ,OALI,CAAA,CAAA,EAAA,GAMnB,eAAA,CAAgB,OANG,CAMK,kBANL,CAMwB,OANxB,CAAA,CAAA,EAAA,CAAA,YAOd,eAAA,CAAgB,IAPF,CAAA;SACD,MAAQ,EAAA,MAAA;SAChB,aAAQ,EAAA,MAAA;OAUnB,MAAA,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AcC;;;;;;;;;;;;;;;;;;;;;;;eA0BA,aAAa,UAAU;;;;;;;;;;;;;;;gBAsCtB;;;;;;;;;;;;;;;;;;;;;;;iBAwBC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gCAkCe;;;;;;;;;;;;;;;oBAgBZ;;;KAIR,sBAAA;WACD;kBACO,KAAK"}
|
|
@@ -390,8 +390,25 @@ declare namespace InngestFunction {
|
|
|
390
390
|
*
|
|
391
391
|
* We recommend starting with the default `true` configuration and only tweak
|
|
392
392
|
* the parameters directly if necessary.
|
|
393
|
+
*
|
|
394
|
+
* @deprecated Use `checkpointing` instead.
|
|
393
395
|
*/
|
|
394
396
|
experimentalCheckpointing?: CheckpointingOptions;
|
|
397
|
+
/**
|
|
398
|
+
* Whether or not to use checkpointing for this function's executions.
|
|
399
|
+
*
|
|
400
|
+
* If `true`, enables checkpointing with default settings, which is a safe,
|
|
401
|
+
* blocking version of checkpointing, where we check in with Inngest after
|
|
402
|
+
* every step is run.
|
|
403
|
+
*
|
|
404
|
+
* If an object, you can tweak the settings to batch, set a maximum runtime
|
|
405
|
+
* before going async, and more. Note that if your server dies before the
|
|
406
|
+
* checkpoint completes, step data will be lost and steps will be rerun.
|
|
407
|
+
*
|
|
408
|
+
* We recommend starting with the default `true` configuration and only tweak
|
|
409
|
+
* the parameters directly if necessary.
|
|
410
|
+
*/
|
|
411
|
+
checkpointing?: CheckpointingOptions;
|
|
395
412
|
}
|
|
396
413
|
}
|
|
397
414
|
type CreateExecutionOptions = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InngestFunction.d.ts","names":[],"sources":["../../src/components/InngestFunction.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;AAuCA;;;;;;;AAOmB,cAPN,eAOc,CAAA,gBANT,eAAA,CAAgB,OAMP,CALvB,OAKuB,EAJvB,WAIuB,EAHvB,SAGuB,EAFvB,eAEuB,CAAA,EAAA,iBAAR,OAAA,CAAQ,GAAA,EAAA,wBACD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AAmB,cACf,eAAA,CAAgB,QAAQ,mBAAmB,qCACzB,OAAA,CAAQ,MAAM,OAAA,CAAQ;eAEnC;;;;;;;;;;;;;;;;;;;;;;;;;;2BAgCP,oBACA,eAAe;;;;;;;;;;;;;;;;;;eAoBR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA6CD;;;;;;;;;;;;;;;;;;;;;;;;cA2BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAqCA;;;;;;;;;gBAUE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAwCF;;;;;;;;;;;;;eAcC;;;;;;;;;;;;;;;;;;;;;;;eA0BA,aAAa,UAAU;;;;;;;;;;;;;;;gBAsCtB;;;;;;;;;;;;;;;;;;;;;;;iBAwBC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gCAkCe;;;;;;;;;;;;;;;oBAgBZ;;;KAIR,sBAAA;WACD;kBACO,KAAK"}
|
|
@@ -159,7 +159,7 @@ var InngestFunction = class InngestFunction {
|
|
|
159
159
|
}
|
|
160
160
|
shouldAsyncCheckpoint(requestedRunStep, internalFnId, disableImmediateExecution) {
|
|
161
161
|
if (requestedRunStep || !internalFnId || disableImmediateExecution) return;
|
|
162
|
-
return this.opts.experimentalCheckpointing ?? this.client["options"].experimentalCheckpointing;
|
|
162
|
+
return this.opts.checkpointing ?? this.client["options"].checkpointing ?? this.opts.experimentalCheckpointing ?? this.client["options"].experimentalCheckpointing;
|
|
163
163
|
}
|
|
164
164
|
};
|
|
165
165
|
(function(_InngestFunction) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InngestFunction.js","names":["fn: FunctionConfig","ret: NonNullable<FunctionConfig[\"cancel\"]>[number]","config: FunctionConfig[]","options: InngestExecutionOptions"],"sources":["../../src/components/InngestFunction.ts"],"sourcesContent":["import {\n ExecutionVersion,\n internalEvents,\n queryKeys,\n} from \"../helpers/consts.ts\";\nimport { timeStr } from \"../helpers/strings.ts\";\nimport type { RecursiveTuple, StrictUnion } from \"../helpers/types.ts\";\nimport type {\n Cancellation,\n CheckpointingOptions,\n ConcurrencyOption,\n FunctionConfig,\n Handler,\n TimeStr,\n TimeStrBatch,\n TriggersFromClient,\n} from \"../types.ts\";\nimport type {\n IInngestExecution,\n InngestExecutionOptions,\n} from \"./execution/InngestExecution.ts\";\nimport { createV0InngestExecution } from \"./execution/v0.ts\";\nimport { createV1InngestExecution } from \"./execution/v1.ts\";\nimport { createV2InngestExecution } from \"./execution/v2.ts\";\nimport type { GetEvents, Inngest } from \"./Inngest.ts\";\nimport type {\n InngestMiddleware,\n MiddlewareRegisterReturn,\n} from \"./InngestMiddleware.ts\";\n\n/**\n * A stateless Inngest function, wrapping up function configuration and any\n * in-memory steps to run when triggered.\n *\n * This function can be \"registered\" to create a handler that Inngest can\n * trigger remotely.\n *\n * @public\n */\nexport class InngestFunction<\n TFnOpts extends InngestFunction.Options<\n TClient,\n TMiddleware,\n TTriggers,\n TFailureHandler\n >,\n THandler extends Handler.Any,\n TFailureHandler extends Handler.Any,\n TClient extends Inngest.Any = Inngest.Any,\n TMiddleware extends InngestMiddleware.Stack = InngestMiddleware.Stack,\n TTriggers extends InngestFunction.Trigger<\n TriggersFromClient<TClient>\n >[] = InngestFunction.Trigger<TriggersFromClient<TClient>>[],\n> implements InngestFunction.Like\n{\n static stepId = \"step\";\n static failureSuffix = \"-failure\";\n\n get [Symbol.toStringTag](): typeof InngestFunction.Tag {\n return InngestFunction.Tag;\n }\n\n public readonly opts: TFnOpts;\n // biome-ignore lint/correctness/noUnusedPrivateClassMembers: used internally\n private readonly fn: THandler;\n private readonly onFailureFn?: TFailureHandler;\n protected readonly client: TClient;\n private readonly middleware: Promise<MiddlewareRegisterReturn[]>;\n\n /**\n * A stateless Inngest function, wrapping up function configuration and any\n * in-memory steps to run when triggered.\n *\n * This function can be \"registered\" to create a handler that Inngest can\n * trigger remotely.\n */\n constructor(\n client: TClient,\n\n /**\n * Options\n */\n opts: TFnOpts,\n fn: THandler,\n ) {\n this.client = client;\n this.opts = opts;\n this.fn = fn;\n this.onFailureFn = this.opts.onFailure;\n\n this.middleware = this.client[\"initializeMiddleware\"](\n this.opts.middleware,\n { registerInput: { fn: this }, prefixStack: this.client[\"middleware\"] },\n );\n }\n\n /**\n * The generated or given ID for this function.\n */\n public id(prefix?: string): string {\n return [prefix, this.opts.id].filter(Boolean).join(\"-\");\n }\n\n /**\n * The generated or given ID for this function, prefixed with the app ID. This\n * is used for routing invokes and identifying the function across apps.\n */\n protected get absoluteId(): string {\n return this.id(this.client.id);\n }\n\n /**\n * The name of this function as it will appear in the Inngest Cloud UI.\n */\n public get name(): string {\n return this.opts.name || this.id();\n }\n\n /**\n * The description of this function.\n */\n public get description(): string | undefined {\n return this.opts.description;\n }\n\n /**\n * Retrieve the Inngest config for this function.\n */\n\n // biome-ignore lint/correctness/noUnusedPrivateClassMembers: used within the SDK\n private getConfig({\n baseUrl,\n appPrefix,\n isConnect,\n }: {\n /**\n * Must be provided a URL that will be used to access the function and step.\n * This function can't be expected to know how it will be accessed, so\n * relies on an outside method providing context.\n */\n baseUrl: URL;\n\n /**\n * The prefix for the app that this function is part of.\n */\n appPrefix: string;\n\n /**\n * Whether this function is being used in a Connect handler.\n */\n isConnect?: boolean;\n }): FunctionConfig[] {\n const fnId = this.id(appPrefix);\n const stepUrl = new URL(baseUrl.href);\n stepUrl.searchParams.set(queryKeys.FnId, fnId);\n stepUrl.searchParams.set(queryKeys.StepId, InngestFunction.stepId);\n\n const {\n retries: attempts,\n cancelOn,\n idempotency,\n batchEvents,\n rateLimit,\n throttle,\n concurrency,\n debounce,\n timeouts,\n priority,\n singleton,\n } = this.opts;\n\n /**\n * Convert retries into the format required when defining function\n * configuration.\n */\n const retries = typeof attempts === \"undefined\" ? undefined : { attempts };\n\n const fn: FunctionConfig = {\n id: fnId,\n name: this.name,\n triggers: (this.opts.triggers ?? []).map((trigger) => {\n if (\"event\" in trigger) {\n return {\n event: trigger.event as string,\n expression: trigger.if,\n };\n }\n\n return {\n cron: trigger.cron,\n };\n }),\n steps: {\n [InngestFunction.stepId]: {\n id: InngestFunction.stepId,\n name: InngestFunction.stepId,\n runtime: {\n type: isConnect ? \"ws\" : \"http\",\n url: stepUrl.href,\n },\n retries,\n },\n },\n idempotency,\n batchEvents,\n rateLimit,\n throttle,\n concurrency,\n debounce,\n priority,\n timeouts,\n singleton,\n };\n\n if (cancelOn) {\n fn.cancel = cancelOn.map(({ event, timeout, if: ifStr, match }) => {\n const ret: NonNullable<FunctionConfig[\"cancel\"]>[number] = {\n event,\n };\n\n if (timeout) {\n ret.timeout = timeStr(timeout);\n }\n\n if (match) {\n ret.if = `event.${match} == async.${match}`;\n } else if (ifStr) {\n ret.if = ifStr;\n }\n\n return ret;\n }, []);\n }\n\n const config: FunctionConfig[] = [fn];\n\n if (this.onFailureFn) {\n const id = `${fn.id}${InngestFunction.failureSuffix}`;\n const name = `${fn.name ?? fn.id} (failure)`;\n\n const failureStepUrl = new URL(stepUrl.href);\n failureStepUrl.searchParams.set(queryKeys.FnId, id);\n\n config.push({\n id,\n name,\n triggers: [\n {\n event: internalEvents.FunctionFailed,\n expression: `event.data.function_id == '${fnId}'`,\n },\n ],\n steps: {\n [InngestFunction.stepId]: {\n id: InngestFunction.stepId,\n name: InngestFunction.stepId,\n runtime: {\n type: \"http\",\n url: failureStepUrl.href,\n },\n retries: { attempts: 1 },\n },\n },\n });\n }\n\n return config;\n }\n\n protected createExecution(opts: CreateExecutionOptions): IInngestExecution {\n const options: InngestExecutionOptions = {\n fn: this,\n ...opts.partialOptions,\n };\n\n const versionHandlers = {\n [ExecutionVersion.V2]: () => createV2InngestExecution(options),\n [ExecutionVersion.V1]: () => createV1InngestExecution(options),\n [ExecutionVersion.V0]: () => createV0InngestExecution(options),\n } satisfies Record<ExecutionVersion, () => IInngestExecution>;\n\n return versionHandlers[opts.version]();\n }\n\n // biome-ignore lint/correctness/noUnusedPrivateClassMembers: used within the SDK\n private shouldOptimizeParallelism(): boolean {\n // TODO We should check the commhandler's client instead of this one?\n return (\n this.opts.optimizeParallelism ??\n this.client[\"options\"].optimizeParallelism ??\n false\n );\n }\n\n // biome-ignore lint/correctness/noUnusedPrivateClassMembers: used within the SDK\n private shouldAsyncCheckpoint(\n requestedRunStep: string | undefined,\n internalFnId: string | undefined,\n disableImmediateExecution: boolean,\n ): CheckpointingOptions | undefined {\n if (requestedRunStep || !internalFnId || disableImmediateExecution) {\n return;\n }\n\n // TODO We should check the commhandler's client instead of this one?\n return (\n this.opts.experimentalCheckpointing ??\n this.client[\"options\"].experimentalCheckpointing\n );\n }\n}\n\n/**\n * A stateless Inngest function, wrapping up function configuration and any\n * in-memory steps to run when triggered.\n *\n * This function can be \"registered\" to create a handler that Inngest can\n * trigger remotely.\n *\n * @public\n */\nexport namespace InngestFunction {\n export const Tag = \"Inngest.Function\" as const;\n\n /**\n * Represents any `InngestFunction` instance, regardless of generics and\n * inference.\n */\n export type Any = InngestFunction<\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n any,\n Handler.Any,\n Handler.Any,\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n any,\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n any,\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n any\n >;\n\n export interface Like {\n readonly [Symbol.toStringTag]: typeof InngestFunction.Tag;\n }\n\n /**\n * A user-friendly method of specifying a trigger for an Inngest function.\n *\n * @public\n */\n export type Trigger<T extends string> = StrictUnion<\n | {\n event: T;\n if?: string;\n }\n | {\n cron: string;\n }\n >;\n\n export type GetOptions<T extends InngestFunction.Any> =\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n T extends InngestFunction<infer O, any, any, any, any, any> ? O : never;\n\n /**\n * A set of options for configuring an Inngest function.\n *\n * @public\n */\n export interface Options<\n TClient extends Inngest.Any = Inngest.Any,\n TMiddleware extends InngestMiddleware.Stack = InngestMiddleware.Stack,\n TTriggers extends InngestFunction.Trigger<\n TriggersFromClient<TClient>\n >[] = InngestFunction.Trigger<TriggersFromClient<TClient>>[],\n TFailureHandler extends Handler.Any = Handler.Any,\n > {\n triggers?: TTriggers;\n\n /**\n * An unique ID used to identify the function. This is used internally for\n * versioning and referring to your function, so should not change between\n * deployments.\n *\n * If you'd like to set a prettier name for your function, use the `name`\n * option.\n */\n id: string;\n\n /**\n * A name for the function as it will appear in the Inngest Cloud UI.\n */\n name?: string;\n\n /**\n * A description of the function.\n */\n description?: string;\n\n /**\n * Concurrency specifies a limit on the total number of concurrent steps that\n * can occur across all runs of the function. A value of 0 (or undefined) means\n * use the maximum available concurrency.\n *\n * Specifying just a number means specifying only the concurrency limit. A\n * maximum of two concurrency options can be specified.\n */\n concurrency?:\n | number\n | ConcurrencyOption\n | RecursiveTuple<ConcurrencyOption, 2>;\n\n /**\n * batchEvents specifies the batch configuration on when this function\n * should be invoked when one of the requirements are fulfilled.\n */\n batchEvents?: {\n /**\n * The maximum number of events to be consumed in one batch.\n * Check the pricing page to verify the limit for each plan.\n */\n maxSize: number;\n\n /**\n * How long to wait before invoking the function with a list of events.\n * If timeout is reached, the function will be invoked with a batch\n * even if it's not filled up to `maxSize`.\n *\n * Expects a time string such as 1s, 60s or 15m15s.\n */\n timeout: TimeStrBatch;\n\n /**\n * An optional key to use for batching.\n *\n * See [batch documentation](https://innge.st/batching) for more\n * information on how to use `key` expressions.\n */\n key?: string;\n\n /**\n * An optional boolean expression to determine an event's eligibility for batching\n *\n * See [batch documentation](https://innge.st/batching) for more\n * information on how to use `if` expressions.\n */\n if?: string;\n };\n\n /**\n * Allow the specification of an idempotency key using event data. If\n * specified, this overrides the `rateLimit` object.\n */\n idempotency?: string;\n\n /**\n * Rate limit function runs, only running them a given number of times (limit) per\n * period. Note that rate limit is a lossy, hard limit. Once the limit is hit,\n * new runs will be skipped. To enqueue work when a rate limit is hit, use the\n * {@link throttle} parameter.\n */\n rateLimit?: {\n /**\n * An optional key to use for rate limiting, similar to idempotency.\n */\n key?: string;\n\n /**\n * The number of times to allow the function to run per the given `period`.\n */\n limit: number;\n\n /**\n * The period of time to allow the function to run `limit` times.\n */\n period: TimeStr;\n };\n\n /**\n * Throttles function runs, only running them a given number of times (limit) per\n * period. Once the limit is hit, new runs will be enqueued and will start when there's\n * capacity. This may lead to a large backlog. For hard rate limiting, use the\n * {@link rateLimit} parameter.\n */\n throttle?: {\n /**\n * An optional expression which returns a throttling key for controlling throttling.\n * Every unique key is its own throttle limit. Event data may be used within this\n * expression, eg \"event.data.user_id\".\n */\n key?: string;\n\n /**\n * The total number of runs allowed to start within the given `period`. The limit is\n * applied evenly over the period.\n */\n limit: number;\n\n /**\n * The period of time for the rate limit. Run starts are evenly spaced through\n * the given period. The minimum granularity is 1 second.\n */\n period: TimeStr;\n\n /**\n * The number of runs allowed to start in the given window in a single burst.\n * A burst > 1 bypasses smoothing for the burst and allows many runs to start\n * at once, if desired. Defaults to 1, which disables bursting.\n */\n burst?: number;\n };\n\n /**\n * Debounce delays functions for the `period` specified. If an event is sent,\n * the function will not run until at least `period` has elapsed.\n *\n * If any new events are received that match the same debounce `key`, the\n * function is rescheduled for another `period` delay, and the triggering\n * event is replaced with the latest event received.\n *\n * See the [Debounce documentation](https://innge.st/debounce) for more\n * information.\n */\n debounce?: {\n /**\n * An optional key to use for debouncing.\n *\n * See [Debounce documentation](https://innge.st/debounce) for more\n * information on how to use `key` expressions.\n */\n key?: string;\n\n /**\n * The period of time to delay after receiving the last trigger to run the\n * function.\n *\n * See [Debounce documentation](https://innge.st/debounce) for more\n * information.\n */\n period: TimeStr;\n\n /**\n * The maximum time that a debounce can be extended before running.\n * If events are continually received within the given period, a function\n * will always run after the given timeout period.\n *\n * See [Debounce documentation](https://innge.st/debounce) for more\n * information.\n */\n timeout?: TimeStr;\n };\n\n /**\n * Configure how the priority of a function run is decided when multiple\n * functions are triggered at the same time.\n *\n * See the [Priority documentation](https://innge.st/priority) for more\n * information.\n */\n priority?: {\n /**\n * An expression to use to determine the priority of a function run. The\n * expression can return a number between `-600` and `600`, where `600`\n * declares that this run should be executed before any others enqueued in\n * the last 600 seconds (10 minutes), and `-600` declares that this run\n * should be executed after any others enqueued in the last 600 seconds.\n *\n * See the [Priority documentation](https://innge.st/priority) for more\n * information.\n */\n run?: string;\n };\n\n /**\n * Configure timeouts for the function. If any of the timeouts are hit, the\n * function run will be cancelled.\n */\n timeouts?: {\n /**\n * Start represents the timeout for starting a function. If the time\n * between scheduling and starting a function exceeds this value, the\n * function will be cancelled.\n *\n * This is, essentially, the amount of time that a function sits in the\n * queue before starting.\n *\n * A function may exceed this duration because of concurrency limits,\n * throttling, etc.\n */\n start?: TimeStr;\n\n /**\n * Finish represents the time between a function starting and the function\n * finishing. If a function takes longer than this time to finish, the\n * function is marked as cancelled.\n *\n * The start time is taken from the time that the first successful\n * function request begins, and does not include the time spent in the\n * queue before the function starts.\n *\n * Note that if the final request to a function begins before this\n * timeout, and completes after this timeout, the function will succeed.\n */\n finish?: TimeStr;\n };\n\n /**\n * Ensures that only one run of the function is active at a time for a given key.\n * If a new run is triggered while another is still in progress with the same key,\n * the new run will either be skipped or replace the active one, depending on the mode.\n *\n * This is useful for deduplication or enforcing exclusive execution.\n */\n singleton?: {\n /**\n * An optional key expression used to scope singleton execution.\n * Each unique key has its own singleton lock. Event data can be referenced,\n * e.g. \"event.data.user_id\".\n */\n key?: string;\n\n /**\n * Determines how to handle new runs when one is already active for the same key.\n * - `\"skip\"` skips the new run.\n * - `\"cancel\"` cancels the existing run and starts the new one.\n */\n mode: \"skip\" | \"cancel\";\n };\n\n cancelOn?: Cancellation<GetEvents<TClient, true>>[];\n\n /**\n * Specifies the maximum number of retries for all steps across this function.\n *\n * Can be a number from `0` to `20`. Defaults to `3`.\n */\n retries?:\n | 0\n | 1\n | 2\n | 3\n | 4\n | 5\n | 6\n | 7\n | 8\n | 9\n | 10\n | 11\n | 12\n | 13\n | 14\n | 15\n | 16\n | 17\n | 18\n | 19\n | 20;\n\n /**\n * Provide a function to be called if your function fails, meaning\n * that it ran out of retries and was unable to complete successfully.\n *\n * This is useful for sending warning notifications or cleaning up\n * after a failure and supports all the same functionality as a\n * regular handler.\n */\n onFailure?: TFailureHandler;\n\n /**\n * Define a set of middleware that can be registered to hook into\n * various lifecycles of the SDK and affect input and output of\n * Inngest functionality.\n *\n * See {@link https://innge.st/middleware}\n *\n * @example\n *\n * ```ts\n * export const inngest = new Inngest({\n * middleware: [\n * new InngestMiddleware({\n * name: \"My Middleware\",\n * init: () => {\n * // ...\n * }\n * })\n * ]\n * });\n * ```\n */\n middleware?: TMiddleware;\n\n /**\n * If `true`, parallel steps within this function are optimized to reduce\n * traffic during `Promise` resolution, which can hugely reduce the time\n * taken and number of requests for each run.\n *\n * Note that this will be the default behaviour in v4 and in its current\n * form will cause `Promise.*()` to wait for all promises to settle before\n * resolving.\n *\n * Providing this value here will overwrite the same value given on the\n * client.\n *\n * @default false\n */\n optimizeParallelism?: boolean;\n\n /**\n * Whether or not to use checkpointing for this function's executions.\n *\n * If `true`, enables checkpointing with default settings, which is a safe,\n * blocking version of checkpointing, where we check in with Inngest after\n * every step is run.\n *\n * If an object, you can tweak the settings to batch, set a maximum runtime\n * before going async, and more. Note that if your server dies before the\n * checkpoint completes, step data will be lost and steps will be rerun.\n *\n * We recommend starting with the default `true` configuration and only tweak\n * the parameters directly if necessary.\n */\n experimentalCheckpointing?: CheckpointingOptions;\n }\n}\n\nexport type CreateExecutionOptions = {\n version: ExecutionVersion;\n partialOptions: Omit<InngestExecutionOptions, \"fn\">;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAuCA,IAAa,kBAAb,MAAa,gBAeb;CACE,OAAO,SAAS;CAChB,OAAO,gBAAgB;CAEvB,KAAK,OAAO,eAA2C;AACrD,SAAO,gBAAgB;;CAGzB,AAAgB;CAEhB,AAAiB;CACjB,AAAiB;CACjB,AAAmB;CACnB,AAAiB;;;;;;;;CASjB,YACE,QAKA,MACA,IACA;AACA,OAAK,SAAS;AACd,OAAK,OAA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;;wBAeR"}
|
|
1
|
+
{"version":3,"file":"InngestFunction.js","names":["fn: FunctionConfig","ret: NonNullable<FunctionConfig[\"cancel\"]>[number]","config: FunctionConfig[]","options: InngestExecutionOptions"],"sources":["../../src/components/InngestFunction.ts"],"sourcesContent":["import {\n ExecutionVersion,\n internalEvents,\n queryKeys,\n} from \"../helpers/consts.ts\";\nimport { timeStr } from \"../helpers/strings.ts\";\nimport type { RecursiveTuple, StrictUnion } from \"../helpers/types.ts\";\nimport type {\n Cancellation,\n CheckpointingOptions,\n ConcurrencyOption,\n FunctionConfig,\n Handler,\n TimeStr,\n TimeStrBatch,\n TriggersFromClient,\n} from \"../types.ts\";\nimport type {\n IInngestExecution,\n InngestExecutionOptions,\n} from \"./execution/InngestExecution.ts\";\nimport { createV0InngestExecution } from \"./execution/v0.ts\";\nimport { createV1InngestExecution } from \"./execution/v1.ts\";\nimport { createV2InngestExecution } from \"./execution/v2.ts\";\nimport type { GetEvents, Inngest } from \"./Inngest.ts\";\nimport type {\n InngestMiddleware,\n MiddlewareRegisterReturn,\n} from \"./InngestMiddleware.ts\";\n\n/**\n * A stateless Inngest function, wrapping up function configuration and any\n * in-memory steps to run when triggered.\n *\n * This function can be \"registered\" to create a handler that Inngest can\n * trigger remotely.\n *\n * @public\n */\nexport class InngestFunction<\n TFnOpts extends InngestFunction.Options<\n TClient,\n TMiddleware,\n TTriggers,\n TFailureHandler\n >,\n THandler extends Handler.Any,\n TFailureHandler extends Handler.Any,\n TClient extends Inngest.Any = Inngest.Any,\n TMiddleware extends InngestMiddleware.Stack = InngestMiddleware.Stack,\n TTriggers extends InngestFunction.Trigger<\n TriggersFromClient<TClient>\n >[] = InngestFunction.Trigger<TriggersFromClient<TClient>>[],\n> implements InngestFunction.Like\n{\n static stepId = \"step\";\n static failureSuffix = \"-failure\";\n\n get [Symbol.toStringTag](): typeof InngestFunction.Tag {\n return InngestFunction.Tag;\n }\n\n public readonly opts: TFnOpts;\n // biome-ignore lint/correctness/noUnusedPrivateClassMembers: used internally\n private readonly fn: THandler;\n private readonly onFailureFn?: TFailureHandler;\n protected readonly client: TClient;\n private readonly middleware: Promise<MiddlewareRegisterReturn[]>;\n\n /**\n * A stateless Inngest function, wrapping up function configuration and any\n * in-memory steps to run when triggered.\n *\n * This function can be \"registered\" to create a handler that Inngest can\n * trigger remotely.\n */\n constructor(\n client: TClient,\n\n /**\n * Options\n */\n opts: TFnOpts,\n fn: THandler,\n ) {\n this.client = client;\n this.opts = opts;\n this.fn = fn;\n this.onFailureFn = this.opts.onFailure;\n\n this.middleware = this.client[\"initializeMiddleware\"](\n this.opts.middleware,\n { registerInput: { fn: this }, prefixStack: this.client[\"middleware\"] },\n );\n }\n\n /**\n * The generated or given ID for this function.\n */\n public id(prefix?: string): string {\n return [prefix, this.opts.id].filter(Boolean).join(\"-\");\n }\n\n /**\n * The generated or given ID for this function, prefixed with the app ID. This\n * is used for routing invokes and identifying the function across apps.\n */\n protected get absoluteId(): string {\n return this.id(this.client.id);\n }\n\n /**\n * The name of this function as it will appear in the Inngest Cloud UI.\n */\n public get name(): string {\n return this.opts.name || this.id();\n }\n\n /**\n * The description of this function.\n */\n public get description(): string | undefined {\n return this.opts.description;\n }\n\n /**\n * Retrieve the Inngest config for this function.\n */\n\n // biome-ignore lint/correctness/noUnusedPrivateClassMembers: used within the SDK\n private getConfig({\n baseUrl,\n appPrefix,\n isConnect,\n }: {\n /**\n * Must be provided a URL that will be used to access the function and step.\n * This function can't be expected to know how it will be accessed, so\n * relies on an outside method providing context.\n */\n baseUrl: URL;\n\n /**\n * The prefix for the app that this function is part of.\n */\n appPrefix: string;\n\n /**\n * Whether this function is being used in a Connect handler.\n */\n isConnect?: boolean;\n }): FunctionConfig[] {\n const fnId = this.id(appPrefix);\n const stepUrl = new URL(baseUrl.href);\n stepUrl.searchParams.set(queryKeys.FnId, fnId);\n stepUrl.searchParams.set(queryKeys.StepId, InngestFunction.stepId);\n\n const {\n retries: attempts,\n cancelOn,\n idempotency,\n batchEvents,\n rateLimit,\n throttle,\n concurrency,\n debounce,\n timeouts,\n priority,\n singleton,\n } = this.opts;\n\n /**\n * Convert retries into the format required when defining function\n * configuration.\n */\n const retries = typeof attempts === \"undefined\" ? undefined : { attempts };\n\n const fn: FunctionConfig = {\n id: fnId,\n name: this.name,\n triggers: (this.opts.triggers ?? []).map((trigger) => {\n if (\"event\" in trigger) {\n return {\n event: trigger.event as string,\n expression: trigger.if,\n };\n }\n\n return {\n cron: trigger.cron,\n };\n }),\n steps: {\n [InngestFunction.stepId]: {\n id: InngestFunction.stepId,\n name: InngestFunction.stepId,\n runtime: {\n type: isConnect ? \"ws\" : \"http\",\n url: stepUrl.href,\n },\n retries,\n },\n },\n idempotency,\n batchEvents,\n rateLimit,\n throttle,\n concurrency,\n debounce,\n priority,\n timeouts,\n singleton,\n };\n\n if (cancelOn) {\n fn.cancel = cancelOn.map(({ event, timeout, if: ifStr, match }) => {\n const ret: NonNullable<FunctionConfig[\"cancel\"]>[number] = {\n event,\n };\n\n if (timeout) {\n ret.timeout = timeStr(timeout);\n }\n\n if (match) {\n ret.if = `event.${match} == async.${match}`;\n } else if (ifStr) {\n ret.if = ifStr;\n }\n\n return ret;\n }, []);\n }\n\n const config: FunctionConfig[] = [fn];\n\n if (this.onFailureFn) {\n const id = `${fn.id}${InngestFunction.failureSuffix}`;\n const name = `${fn.name ?? fn.id} (failure)`;\n\n const failureStepUrl = new URL(stepUrl.href);\n failureStepUrl.searchParams.set(queryKeys.FnId, id);\n\n config.push({\n id,\n name,\n triggers: [\n {\n event: internalEvents.FunctionFailed,\n expression: `event.data.function_id == '${fnId}'`,\n },\n ],\n steps: {\n [InngestFunction.stepId]: {\n id: InngestFunction.stepId,\n name: InngestFunction.stepId,\n runtime: {\n type: \"http\",\n url: failureStepUrl.href,\n },\n retries: { attempts: 1 },\n },\n },\n });\n }\n\n return config;\n }\n\n protected createExecution(opts: CreateExecutionOptions): IInngestExecution {\n const options: InngestExecutionOptions = {\n fn: this,\n ...opts.partialOptions,\n };\n\n const versionHandlers = {\n [ExecutionVersion.V2]: () => createV2InngestExecution(options),\n [ExecutionVersion.V1]: () => createV1InngestExecution(options),\n [ExecutionVersion.V0]: () => createV0InngestExecution(options),\n } satisfies Record<ExecutionVersion, () => IInngestExecution>;\n\n return versionHandlers[opts.version]();\n }\n\n // biome-ignore lint/correctness/noUnusedPrivateClassMembers: used within the SDK\n private shouldOptimizeParallelism(): boolean {\n // TODO We should check the commhandler's client instead of this one?\n return (\n this.opts.optimizeParallelism ??\n this.client[\"options\"].optimizeParallelism ??\n false\n );\n }\n\n // biome-ignore lint/correctness/noUnusedPrivateClassMembers: used within the SDK\n private shouldAsyncCheckpoint(\n requestedRunStep: string | undefined,\n internalFnId: string | undefined,\n disableImmediateExecution: boolean,\n ): CheckpointingOptions | undefined {\n if (requestedRunStep || !internalFnId || disableImmediateExecution) {\n return;\n }\n\n // TODO We should check the commhandler's client instead of this one?\n return (\n this.opts.checkpointing ??\n this.client[\"options\"].checkpointing ??\n this.opts.experimentalCheckpointing ??\n this.client[\"options\"].experimentalCheckpointing\n );\n }\n}\n\n/**\n * A stateless Inngest function, wrapping up function configuration and any\n * in-memory steps to run when triggered.\n *\n * This function can be \"registered\" to create a handler that Inngest can\n * trigger remotely.\n *\n * @public\n */\nexport namespace InngestFunction {\n export const Tag = \"Inngest.Function\" as const;\n\n /**\n * Represents any `InngestFunction` instance, regardless of generics and\n * inference.\n */\n export type Any = InngestFunction<\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n any,\n Handler.Any,\n Handler.Any,\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n any,\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n any,\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n any\n >;\n\n export interface Like {\n readonly [Symbol.toStringTag]: typeof InngestFunction.Tag;\n }\n\n /**\n * A user-friendly method of specifying a trigger for an Inngest function.\n *\n * @public\n */\n export type Trigger<T extends string> = StrictUnion<\n | {\n event: T;\n if?: string;\n }\n | {\n cron: string;\n }\n >;\n\n export type GetOptions<T extends InngestFunction.Any> =\n // biome-ignore lint/suspicious/noExplicitAny: <explanation>\n T extends InngestFunction<infer O, any, any, any, any, any> ? O : never;\n\n /**\n * A set of options for configuring an Inngest function.\n *\n * @public\n */\n export interface Options<\n TClient extends Inngest.Any = Inngest.Any,\n TMiddleware extends InngestMiddleware.Stack = InngestMiddleware.Stack,\n TTriggers extends InngestFunction.Trigger<\n TriggersFromClient<TClient>\n >[] = InngestFunction.Trigger<TriggersFromClient<TClient>>[],\n TFailureHandler extends Handler.Any = Handler.Any,\n > {\n triggers?: TTriggers;\n\n /**\n * An unique ID used to identify the function. This is used internally for\n * versioning and referring to your function, so should not change between\n * deployments.\n *\n * If you'd like to set a prettier name for your function, use the `name`\n * option.\n */\n id: string;\n\n /**\n * A name for the function as it will appear in the Inngest Cloud UI.\n */\n name?: string;\n\n /**\n * A description of the function.\n */\n description?: string;\n\n /**\n * Concurrency specifies a limit on the total number of concurrent steps that\n * can occur across all runs of the function. A value of 0 (or undefined) means\n * use the maximum available concurrency.\n *\n * Specifying just a number means specifying only the concurrency limit. A\n * maximum of two concurrency options can be specified.\n */\n concurrency?:\n | number\n | ConcurrencyOption\n | RecursiveTuple<ConcurrencyOption, 2>;\n\n /**\n * batchEvents specifies the batch configuration on when this function\n * should be invoked when one of the requirements are fulfilled.\n */\n batchEvents?: {\n /**\n * The maximum number of events to be consumed in one batch.\n * Check the pricing page to verify the limit for each plan.\n */\n maxSize: number;\n\n /**\n * How long to wait before invoking the function with a list of events.\n * If timeout is reached, the function will be invoked with a batch\n * even if it's not filled up to `maxSize`.\n *\n * Expects a time string such as 1s, 60s or 15m15s.\n */\n timeout: TimeStrBatch;\n\n /**\n * An optional key to use for batching.\n *\n * See [batch documentation](https://innge.st/batching) for more\n * information on how to use `key` expressions.\n */\n key?: string;\n\n /**\n * An optional boolean expression to determine an event's eligibility for batching\n *\n * See [batch documentation](https://innge.st/batching) for more\n * information on how to use `if` expressions.\n */\n if?: string;\n };\n\n /**\n * Allow the specification of an idempotency key using event data. If\n * specified, this overrides the `rateLimit` object.\n */\n idempotency?: string;\n\n /**\n * Rate limit function runs, only running them a given number of times (limit) per\n * period. Note that rate limit is a lossy, hard limit. Once the limit is hit,\n * new runs will be skipped. To enqueue work when a rate limit is hit, use the\n * {@link throttle} parameter.\n */\n rateLimit?: {\n /**\n * An optional key to use for rate limiting, similar to idempotency.\n */\n key?: string;\n\n /**\n * The number of times to allow the function to run per the given `period`.\n */\n limit: number;\n\n /**\n * The period of time to allow the function to run `limit` times.\n */\n period: TimeStr;\n };\n\n /**\n * Throttles function runs, only running them a given number of times (limit) per\n * period. Once the limit is hit, new runs will be enqueued and will start when there's\n * capacity. This may lead to a large backlog. For hard rate limiting, use the\n * {@link rateLimit} parameter.\n */\n throttle?: {\n /**\n * An optional expression which returns a throttling key for controlling throttling.\n * Every unique key is its own throttle limit. Event data may be used within this\n * expression, eg \"event.data.user_id\".\n */\n key?: string;\n\n /**\n * The total number of runs allowed to start within the given `period`. The limit is\n * applied evenly over the period.\n */\n limit: number;\n\n /**\n * The period of time for the rate limit. Run starts are evenly spaced through\n * the given period. The minimum granularity is 1 second.\n */\n period: TimeStr;\n\n /**\n * The number of runs allowed to start in the given window in a single burst.\n * A burst > 1 bypasses smoothing for the burst and allows many runs to start\n * at once, if desired. Defaults to 1, which disables bursting.\n */\n burst?: number;\n };\n\n /**\n * Debounce delays functions for the `period` specified. If an event is sent,\n * the function will not run until at least `period` has elapsed.\n *\n * If any new events are received that match the same debounce `key`, the\n * function is rescheduled for another `period` delay, and the triggering\n * event is replaced with the latest event received.\n *\n * See the [Debounce documentation](https://innge.st/debounce) for more\n * information.\n */\n debounce?: {\n /**\n * An optional key to use for debouncing.\n *\n * See [Debounce documentation](https://innge.st/debounce) for more\n * information on how to use `key` expressions.\n */\n key?: string;\n\n /**\n * The period of time to delay after receiving the last trigger to run the\n * function.\n *\n * See [Debounce documentation](https://innge.st/debounce) for more\n * information.\n */\n period: TimeStr;\n\n /**\n * The maximum time that a debounce can be extended before running.\n * If events are continually received within the given period, a function\n * will always run after the given timeout period.\n *\n * See [Debounce documentation](https://innge.st/debounce) for more\n * information.\n */\n timeout?: TimeStr;\n };\n\n /**\n * Configure how the priority of a function run is decided when multiple\n * functions are triggered at the same time.\n *\n * See the [Priority documentation](https://innge.st/priority) for more\n * information.\n */\n priority?: {\n /**\n * An expression to use to determine the priority of a function run. The\n * expression can return a number between `-600` and `600`, where `600`\n * declares that this run should be executed before any others enqueued in\n * the last 600 seconds (10 minutes), and `-600` declares that this run\n * should be executed after any others enqueued in the last 600 seconds.\n *\n * See the [Priority documentation](https://innge.st/priority) for more\n * information.\n */\n run?: string;\n };\n\n /**\n * Configure timeouts for the function. If any of the timeouts are hit, the\n * function run will be cancelled.\n */\n timeouts?: {\n /**\n * Start represents the timeout for starting a function. If the time\n * between scheduling and starting a function exceeds this value, the\n * function will be cancelled.\n *\n * This is, essentially, the amount of time that a function sits in the\n * queue before starting.\n *\n * A function may exceed this duration because of concurrency limits,\n * throttling, etc.\n */\n start?: TimeStr;\n\n /**\n * Finish represents the time between a function starting and the function\n * finishing. If a function takes longer than this time to finish, the\n * function is marked as cancelled.\n *\n * The start time is taken from the time that the first successful\n * function request begins, and does not include the time spent in the\n * queue before the function starts.\n *\n * Note that if the final request to a function begins before this\n * timeout, and completes after this timeout, the function will succeed.\n */\n finish?: TimeStr;\n };\n\n /**\n * Ensures that only one run of the function is active at a time for a given key.\n * If a new run is triggered while another is still in progress with the same key,\n * the new run will either be skipped or replace the active one, depending on the mode.\n *\n * This is useful for deduplication or enforcing exclusive execution.\n */\n singleton?: {\n /**\n * An optional key expression used to scope singleton execution.\n * Each unique key has its own singleton lock. Event data can be referenced,\n * e.g. \"event.data.user_id\".\n */\n key?: string;\n\n /**\n * Determines how to handle new runs when one is already active for the same key.\n * - `\"skip\"` skips the new run.\n * - `\"cancel\"` cancels the existing run and starts the new one.\n */\n mode: \"skip\" | \"cancel\";\n };\n\n cancelOn?: Cancellation<GetEvents<TClient, true>>[];\n\n /**\n * Specifies the maximum number of retries for all steps across this function.\n *\n * Can be a number from `0` to `20`. Defaults to `3`.\n */\n retries?:\n | 0\n | 1\n | 2\n | 3\n | 4\n | 5\n | 6\n | 7\n | 8\n | 9\n | 10\n | 11\n | 12\n | 13\n | 14\n | 15\n | 16\n | 17\n | 18\n | 19\n | 20;\n\n /**\n * Provide a function to be called if your function fails, meaning\n * that it ran out of retries and was unable to complete successfully.\n *\n * This is useful for sending warning notifications or cleaning up\n * after a failure and supports all the same functionality as a\n * regular handler.\n */\n onFailure?: TFailureHandler;\n\n /**\n * Define a set of middleware that can be registered to hook into\n * various lifecycles of the SDK and affect input and output of\n * Inngest functionality.\n *\n * See {@link https://innge.st/middleware}\n *\n * @example\n *\n * ```ts\n * export const inngest = new Inngest({\n * middleware: [\n * new InngestMiddleware({\n * name: \"My Middleware\",\n * init: () => {\n * // ...\n * }\n * })\n * ]\n * });\n * ```\n */\n middleware?: TMiddleware;\n\n /**\n * If `true`, parallel steps within this function are optimized to reduce\n * traffic during `Promise` resolution, which can hugely reduce the time\n * taken and number of requests for each run.\n *\n * Note that this will be the default behaviour in v4 and in its current\n * form will cause `Promise.*()` to wait for all promises to settle before\n * resolving.\n *\n * Providing this value here will overwrite the same value given on the\n * client.\n *\n * @default false\n */\n optimizeParallelism?: boolean;\n\n /**\n * Whether or not to use checkpointing for this function's executions.\n *\n * If `true`, enables checkpointing with default settings, which is a safe,\n * blocking version of checkpointing, where we check in with Inngest after\n * every step is run.\n *\n * If an object, you can tweak the settings to batch, set a maximum runtime\n * before going async, and more. Note that if your server dies before the\n * checkpoint completes, step data will be lost and steps will be rerun.\n *\n * We recommend starting with the default `true` configuration and only tweak\n * the parameters directly if necessary.\n *\n * @deprecated Use `checkpointing` instead.\n */\n experimentalCheckpointing?: CheckpointingOptions;\n\n /**\n * Whether or not to use checkpointing for this function's executions.\n *\n * If `true`, enables checkpointing with default settings, which is a safe,\n * blocking version of checkpointing, where we check in with Inngest after\n * every step is run.\n *\n * If an object, you can tweak the settings to batch, set a maximum runtime\n * before going async, and more. Note that if your server dies before the\n * checkpoint completes, step data will be lost and steps will be rerun.\n *\n * We recommend starting with the default `true` configuration and only tweak\n * the parameters directly if necessary.\n */\n checkpointing?: CheckpointingOptions;\n }\n}\n\nexport type CreateExecutionOptions = {\n version: ExecutionVersion;\n partialOptions: Omit<InngestExecutionOptions, \"fn\">;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAuCA,IAAa,kBAAb,MAAa,gBAeb;CACE,OAAO,SAAS;CAChB,OAAO,gBAAgB;CAEvB,KAAK,OAAO,eAA2C;AACrD,SAAO,gBAAgB;;CAGzB,AAAgB;CAEhB,AAAiB;CACjB,AAAiB;CACjB,AAAmB;CACnB,AAAiB;;;;;;;;CASjB,YACE,QAKA,MACA,IACA;AACA,OAAK,SAAS;AACd,OAAK,OAAO;AACZ,OAAK,KAAK;AACV,OAAK,cAAc,KAAK,KAAK;AAE7B,OAAK,aAAa,KAAK,OAAO,wBAC5B,KAAK,KAAK,YACV;GAAE,eAAe,EAAE,IAAI,MAAM;GAAE,aAAa,KAAK,OAAO;GAAe,CACxE;;;;;CAMH,AAAO,GAAG,QAAyB;AACjC,SAAO,CAAC,QAAQ,KAAK,KAAK,GAAG,CAAC,OAAO,QAAQ,CAAC,KAAK,IAAI;;;;;;CAOzD,IAAc,aAAqB;AACjC,SAAO,KAAK,GAAG,KAAK,OAAO,GAAG;;;;;CAMhC,IAAW,OAAe;AACxB,SAAO,KAAK,KAAK,QAAQ,KAAK,IAAI;;;;;CAMpC,IAAW,cAAkC;AAC3C,SAAO,KAAK,KAAK;;;;;CAQnB,AAAQ,UAAU,EAChB,SACA,WACA,aAkBmB;EACnB,MAAM,OAAO,KAAK,GAAG,UAAU;EAC/B,MAAM,UAAU,IAAI,IAAI,QAAQ,KAAK;AACrC,UAAQ,aAAa,IAAI,UAAU,MAAM,KAAK;AAC9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I,gBAAgB;KACpB,MAAM,gBAAgB;KACtB,SAAS;MACP,MAAM;MACN,KAAK,eAAe;MACrB;KACD,SAAS,EAAE,UAAU,GAAG;KACzB,EACF;IACF,CAAC;;AAGJ,SAAO;;CAGT,AAAU,gBAAgB,MAAiD;EACzE,MAAMC,UAAmC;GACvC,IAAI;GACJ,GAAG,KAAK;GACT;AAQD,SANwB;IACrB,iBAAiB,WAAW,yBAAyB,QAAQ;IAC7D,iBAAiB,WAAW,yBAAyB,QAAQ;IAC7D,iBAAiB,WAAW,yBAAyB,QAAQ;GAC/D,CAEsB,KAAK,UAAU;;CAIxC,AAAQ,4BAAqC;AAE3C,SACE,KAAK,KAAK,uBACV,KAAK,OAAO,WAAW,uBACvB;;CAKJ,AAAQ,sBACN,kBACA,cACA,2BACkC;AAClC,MAAI,oBAAoB,CAAC,gBAAgB,0BACvC;AAIF,SACE,KAAK,KAAK,iBACV,KAAK,OAAO,WAAW,iBACvB,KAAK,KAAK,6BACV,KAAK,OAAO,WAAW;;;;wBAeR"}
|
|
@@ -149,7 +149,10 @@ var InngestSpanProcessor = class InngestSpanProcessor {
|
|
|
149
149
|
processorDebug("batcher lazily accessed; creating new batcher with URL", url);
|
|
150
150
|
resolve(new __opentelemetry_sdk_trace_base.BatchSpanProcessor(new __opentelemetry_exporter_trace_otlp_http.OTLPTraceExporter({
|
|
151
151
|
url: url.href,
|
|
152
|
-
headers: {
|
|
152
|
+
headers: {
|
|
153
|
+
...app["headers"],
|
|
154
|
+
Authorization: `Bearer ${app["inngestApi"]["signingKey"]}`
|
|
155
|
+
}
|
|
153
156
|
})));
|
|
154
157
|
} catch (err) {
|
|
155
158
|
reject(err);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processor.cjs","names":["debugPrefix","_resourceAttributes: Resource | undefined","#traceParents","appId: string | undefined","functionId: string | undefined","traceRef: string | undefined","TraceStateKey","osDetector","envDetector","hostDetector","processDetector","serviceInstanceIdDetector","#batcher","getAsyncCtx","url: URL","defaultInngestApiBaseUrl","devServerHost","defaultDevServerHost","devServerAvailable","BatchSpanProcessor","OTLPTraceExporter","#spanCleanup","#spansToExport","Attribute","debug"],"sources":["../../../../src/components/execution/otel/processor.ts"],"sourcesContent":["import type { Span } from \"@opentelemetry/api\";\nimport { OTLPTraceExporter } from \"@opentelemetry/exporter-trace-otlp-http\";\nimport {\n detectResources,\n envDetector,\n hostDetector,\n osDetector,\n processDetector,\n type Resource,\n serviceInstanceIdDetector,\n} from \"@opentelemetry/resources\";\nimport {\n BatchSpanProcessor,\n type ReadableSpan,\n type SpanProcessor,\n} from \"@opentelemetry/sdk-trace-base\";\nimport Debug from \"debug\";\nimport {\n defaultDevServerHost,\n defaultInngestApiBaseUrl,\n} from \"../../../helpers/consts.ts\";\nimport { devServerAvailable } from \"../../../helpers/devserver.ts\";\nimport { devServerHost } from \"../../../helpers/env.ts\";\nimport type { Inngest } from \"../../Inngest.ts\";\nimport { getAsyncCtx } from \"../als.ts\";\nimport { clientProcessorMap } from \"./access.ts\";\nimport { Attribute, debugPrefix, TraceStateKey } from \"./consts.ts\";\n\nconst processorDebug = Debug(`${debugPrefix}:InngestSpanProcessor`);\n\n/**\n * A set of resource attributes that are used to identify the Inngest app and\n * the function that is being executed. This is used to store the resource\n * attributes for the spans that are exported to the Inngest endpoint, and cache\n * them for later use.\n */\nlet _resourceAttributes: Resource | undefined;\n\n/**\n * A set of information about an execution that's used to set attributes on\n * userland spans sent to Inngest for proper indexing.\n */\nexport type ParentState = {\n traceparent: string;\n runId: string;\n appId: string | undefined;\n functionId: string | undefined;\n traceRef: string | undefined;\n};\n\n/**\n * An OTel span processor that is used to export spans to the Inngest endpoint.\n * This is used to track spans that are created within an Inngest run and export\n * them to the Inngest endpoint for tracing.\n *\n * It's careful to only pick relevant spans to export and will not send any\n * irrelevant spans to the Inngest endpoint.\n *\n * THIS IS THE INTERNAL IMPLEMENTATION OF THE SPAN PROCESSOR AND SHOULD NOT BE\n * USED BY USERS DIRECTLY. USE THE {@link PublicInngestSpanProcessor} CLASS\n * INSTEAD.\n */\nexport class InngestSpanProcessor implements SpanProcessor {\n /**\n * An OTel span processor that is used to export spans to the Inngest endpoint.\n * This is used to track spans that are created within an Inngest run and export\n * them to the Inngest endpoint for tracing.\n *\n * It's careful to only pick relevant spans to export and will not send any\n * irrelevant spans to the Inngest endpoint.\n */\n constructor(\n /**\n * The app that this span processor is associated with. This is used to\n * determine the Inngest endpoint to export spans to.\n *\n * It is optional here as this is the private constructor and only used\n * internally; we set `app` elsewhere as when we create the processor (as\n * early as possible when the process starts) we don't necessarily have the\n * app available yet.\n *\n * So, internally we can delay setting ths until later.\n */\n app?: Inngest.Like,\n ) {\n if (app) {\n clientProcessorMap.set(app as Inngest.Any, this);\n }\n }\n\n /**\n * A `BatchSpanProcessor` that is used to export spans to the Inngest\n * endpoint. This is created lazily to avoid creating it until the Inngest App\n * has been initialized and has had a chance to receive environment variables,\n * which may be from an incoming request.\n */\n #batcher: Promise<BatchSpanProcessor> | undefined;\n\n /**\n * A set of spans used to track spans that we care about, so that we can\n * export them to the OTel endpoint.\n *\n * If a span falls out of reference, it will be removed from this set as we'll\n * never get a chance to export it or remove it anyway.\n */\n #spansToExport = new WeakSet<Span>();\n\n /**\n * A map of span IDs to their parent state, which includes a block of\n * information that can be used and pushed back to the Inngest endpoint to\n * ingest spans.\n */\n #traceParents = new Map<string, ParentState>();\n\n /**\n * A registry used to clean up items from the `traceParents` map when spans\n * fall out of reference. This is used to avoid memory leaks in the case where\n * a span is not exported, remains unended, and is left in memory before being\n * GC'd.\n */\n #spanCleanup = new FinalizationRegistry<string>((spanId) => {\n if (spanId) {\n this.#traceParents.delete(spanId);\n }\n });\n\n /**\n * In order to only capture a subset of spans, we need to declare the initial\n * span that we care about and then export its children.\n *\n * Call this method (ideally just before execution starts) with that initial\n * span to trigger capturing all following children as well as initialize the\n * batcher.\n */\n public declareStartingSpan({\n span,\n runId,\n traceparent,\n tracestate,\n }: {\n span: Span;\n runId: string;\n traceparent: string | undefined;\n tracestate: string | undefined;\n }): void {\n // Upsert the batcher ready for later. We do this here to bootstrap it with\n // the correct async context as soon as we can. As this method is only\n // called just before execution, we know we're all set up.\n //\n // Waiting to call this until we actually need the batcher would mean that\n // we might not have the correct async context set up, as we'd likely be in\n // some span lifecycle method that doesn't have the same chain of execution.\n void this.ensureBatcherInitialized();\n\n // If we don't have a traceparent, then we can't track this span. This is\n // likely a span that we don't care about, so we can ignore it.\n if (!traceparent) {\n return processorDebug(\n \"no traceparent found for span\",\n span.spanContext().spanId,\n \"so skipping it\",\n );\n }\n\n // We also attempt to use `tracestate`. The values we fetch from these\n // should be optional, as it's likely the Executor won't need us to parrot\n // them back in later versions.\n let appId: string | undefined;\n let functionId: string | undefined;\n let traceRef: string | undefined;\n\n if (tracestate) {\n try {\n const entries = Object.fromEntries(\n tracestate.split(\",\").map((kv) => kv.split(\"=\") as [string, string]),\n );\n\n appId = entries[TraceStateKey.AppId];\n functionId = entries[TraceStateKey.FunctionId];\n traceRef = entries[TraceStateKey.TraceRef];\n } catch (err) {\n processorDebug(\n \"failed to parse tracestate\",\n tracestate,\n \"so skipping it;\",\n err,\n );\n }\n }\n\n // This is a span that we care about, so let's make sure it and its\n // children are exported.\n processorDebug.extend(\"declareStartingSpan\")(\n \"declaring:\",\n span.spanContext().spanId,\n \"for traceparent\",\n traceparent,\n );\n\n // Set a load of attributes on this span so that we can nicely identify\n // runtime, paths, etc. Only this span will have these attributes.\n span.setAttributes(InngestSpanProcessor.resourceAttributes.attributes);\n\n this.trackSpan(\n {\n appId,\n functionId,\n runId,\n traceparent,\n traceRef,\n },\n span,\n );\n }\n\n /**\n * A getter for retrieving resource attributes for the current process. This\n * is used to set the resource attributes for the spans that are exported to\n * the Inngest endpoint, and cache them for later use.\n */\n static get resourceAttributes(): Resource {\n if (!_resourceAttributes) {\n _resourceAttributes = detectResources({\n detectors: [\n osDetector,\n envDetector,\n hostDetector,\n processDetector,\n serviceInstanceIdDetector,\n ],\n });\n }\n\n return _resourceAttributes;\n }\n\n /**\n * The batcher is a singleton that is used to export spans to the OTel\n * endpoint. It is created lazily to avoid creating it until the Inngest App\n * has been initialized and has had a chance to receive environment variables,\n * which may be from an incoming request.\n *\n * The batcher is only referenced once we've found a span we're interested in,\n * so this should always have everything it needs on the app by then.\n */\n private ensureBatcherInitialized(): Promise<BatchSpanProcessor> {\n if (!this.#batcher) {\n this.#batcher = new Promise(async (resolve, reject) => {\n try {\n // We retrieve the app from the async context, so we must make sure\n // that this function is called from the correct chain.\n const store = await getAsyncCtx();\n if (!store) {\n throw new Error(\n \"No async context found; cannot create batcher to export traces\",\n );\n }\n\n const app = store.app as Inngest.Any;\n\n // Fetch the URL for the Inngest endpoint using the app's config.\n let url: URL;\n const path = \"/v1/traces/userland\";\n if (app.apiBaseUrl) {\n url = new URL(path, app.apiBaseUrl);\n } else {\n url = new URL(path, defaultInngestApiBaseUrl);\n\n if (app[\"mode\"] && app[\"mode\"].isDev && app[\"mode\"].isInferred) {\n const devHost = devServerHost() || defaultDevServerHost;\n const hasDevServer = await devServerAvailable(\n devHost,\n app[\"fetch\"],\n );\n if (hasDevServer) {\n url = new URL(path, devHost);\n }\n } else if (app[\"mode\"]?.explicitDevUrl) {\n url = new URL(path, app[\"mode\"].explicitDevUrl.href);\n }\n }\n\n processorDebug(\n \"batcher lazily accessed; creating new batcher with URL\",\n url,\n );\n\n const exporter = new OTLPTraceExporter({\n url: url.href,\n\n headers: {\n Authorization: `Bearer ${app[\"inngestApi\"][\"signingKey\"]}`,\n },\n });\n\n resolve(new BatchSpanProcessor(exporter));\n } catch (err) {\n reject(err);\n }\n });\n }\n\n return this.#batcher;\n }\n\n /**\n * Mark a span as being tracked by this processor, meaning it will be exported\n * to the Inggest endpoint when it ends.\n */\n private trackSpan(parentState: ParentState, span: Span): void {\n const spanId = span.spanContext().spanId;\n\n this.#spanCleanup.register(span, spanId, span);\n this.#spansToExport.add(span);\n this.#traceParents.set(spanId, parentState);\n\n span.setAttribute(Attribute.InngestTraceparent, parentState.traceparent);\n span.setAttribute(Attribute.InngestRunId, parentState.runId);\n\n // Setting app ID is optional; it's likely in future versions of the\n // Executor that we don't need to parrot this back.\n if (parentState.appId) {\n span.setAttribute(Attribute.InngestAppId1, parentState.appId);\n span.setAttribute(Attribute.InngestAppId2, parentState.appId);\n }\n\n // Setting function ID is optional; it's likely in future versions of the\n // Executor that we don't need to parrot this back.\n if (parentState.functionId) {\n span.setAttribute(Attribute.InngestFunctionId, parentState.functionId);\n }\n\n if (parentState.traceRef) {\n span.setAttribute(Attribute.InngestTraceRef, parentState.traceRef);\n }\n }\n\n /**\n * Clean up any references to a span that has ended. This is used to avoid\n * memory leaks in the case where a span is not exported, remains unended, and\n * is left in memory before being GC'd.\n */\n private cleanupSpan(span: Span): void {\n const spanId = span.spanContext().spanId;\n\n // This span is no longer in use, so we can remove it from the cleanup\n // registry.\n this.#spanCleanup.unregister(span);\n this.#spansToExport.delete(span);\n this.#traceParents.delete(spanId);\n }\n\n /**\n * An implementation of the `onStart` method from the `SpanProcessor`\n * interface. This is called when a span is started, and is used to track\n * spans that are children of spans we care about.\n */\n onStart(span: Span): void {\n const debug = processorDebug.extend(\"onStart\");\n const spanId = span.spanContext().spanId;\n // 🤫 It seems to work\n const parentSpanId = (span as unknown as ReadableSpan).parentSpanContext\n ?.spanId;\n\n // The root span isn't captured here, but we can capture children of it\n // here.\n\n if (!parentSpanId) {\n // All spans that Inngest cares about will have a parent, so ignore this\n debug(\"no parent span ID for\", spanId, \"so skipping it\");\n\n return;\n }\n\n const parentState = this.#traceParents.get(parentSpanId);\n if (parentState) {\n // This span is a child of a span we care about, so add it to the list of\n // tracked spans so that we also capture its children\n debug(\n \"found traceparent\",\n parentState,\n \"in span ID\",\n parentSpanId,\n \"so adding\",\n spanId,\n );\n\n this.trackSpan(parentState, span);\n }\n }\n\n /**\n * An implementation of the `onEnd` method from the `SpanProcessor` interface.\n * This is called when a span ends, and is used to export spans to the Inngest\n * endpoint.\n */\n onEnd(span: ReadableSpan): void {\n const debug = processorDebug.extend(\"onEnd\");\n const spanId = span.spanContext().spanId;\n\n try {\n if (this.#spansToExport.has(span as unknown as Span)) {\n if (!this.#batcher) {\n return debug(\n \"batcher not initialized, so failed exporting span\",\n spanId,\n );\n }\n\n debug(\"exporting span\", spanId);\n return void this.#batcher.then((batcher) => batcher.onEnd(span));\n }\n\n debug(\"not exporting span\", spanId, \"as we don't care about it\");\n } finally {\n this.cleanupSpan(span as unknown as Span);\n }\n }\n\n /**\n * An implementation of the `forceFlush` method from the `SpanProcessor`\n * interface. This is called to force the processor to flush any spans that\n * are currently in the batcher. This is used to ensure that spans are\n * exported to the Inngest endpoint before the process exits.\n *\n * Notably, we call this in the `beforeResponse` middleware hook to ensure\n * that spans for a run as exported as soon as possible and before the\n * serverless process is killed.\n */\n async forceFlush(): Promise<void> {\n const flushDebug = processorDebug.extend(\"forceFlush\");\n flushDebug(\"force flushing batcher\");\n\n return this.#batcher\n ?.then((batcher) => batcher.forceFlush())\n .catch((err) => {\n flushDebug(\"error flushing batcher\", err, \"ignoring\");\n });\n }\n\n async shutdown(): Promise<void> {\n processorDebug.extend(\"shutdown\")(\"shutting down batcher\");\n\n return this.#batcher?.then((batcher) => batcher.shutdown());\n }\n}\n\n/**\n * An OTel span processor that is used to export spans to the Inngest endpoint.\n * This is used to track spans that are created within an Inngest run and export\n * them to the Inngest endpoint for tracing.\n *\n * It's careful to only pick relevant spans to export and will not send any\n * irrelevant spans to the Inngest endpoint.\n */\nexport class PublicInngestSpanProcessor extends InngestSpanProcessor {\n constructor(\n /**\n * The app that this span processor is associated with. This is used to\n * determine the Inngest endpoint to export spans to.\n */\n app: Inngest.Like,\n ) {\n super(app);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AA4BA,MAAM,oCAAuB,GAAGA,6BAAY,uBAAuB;;;;;;;AAQnE,IAAIC;;;;;;;;;;;;;AA0BJ,IAAa,uBAAb,MAAa,qBAA8C;;;;;;;;;CASzD,YAYE,K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#traceParents","appId: string | undefined","functionId: string | undefined","traceRef: string | undefined","TraceStateKey","osDetector","envDetector","hostDetector","processDetector","serviceInstanceIdDetector","#batcher","getAsyncCtx","url: URL","defaultInngestApiBaseUrl","devServerHost","defaultDevServerHost","devServerAvailable","BatchSpanProcessor","OTLPTraceExporter","#spanCleanup","#spansToExport","Attribute","debug"],"sources":["../../../../src/components/execution/otel/processor.ts"],"sourcesContent":["import type { Span } from \"@opentelemetry/api\";\nimport { OTLPTraceExporter } from \"@opentelemetry/exporter-trace-otlp-http\";\nimport {\n detectResources,\n envDetector,\n hostDetector,\n osDetector,\n processDetector,\n type Resource,\n serviceInstanceIdDetector,\n} from \"@opentelemetry/resources\";\nimport {\n BatchSpanProcessor,\n type ReadableSpan,\n type SpanProcessor,\n} from \"@opentelemetry/sdk-trace-base\";\nimport Debug from \"debug\";\nimport {\n defaultDevServerHost,\n defaultInngestApiBaseUrl,\n} from \"../../../helpers/consts.ts\";\nimport { devServerAvailable } from \"../../../helpers/devserver.ts\";\nimport { devServerHost } from \"../../../helpers/env.ts\";\nimport type { Inngest } from \"../../Inngest.ts\";\nimport { getAsyncCtx } from \"../als.ts\";\nimport { clientProcessorMap } from \"./access.ts\";\nimport { Attribute, debugPrefix, TraceStateKey } from \"./consts.ts\";\n\nconst processorDebug = Debug(`${debugPrefix}:InngestSpanProcessor`);\n\n/**\n * A set of resource attributes that are used to identify the Inngest app and\n * the function that is being executed. This is used to store the resource\n * attributes for the spans that are exported to the Inngest endpoint, and cache\n * them for later use.\n */\nlet _resourceAttributes: Resource | undefined;\n\n/**\n * A set of information about an execution that's used to set attributes on\n * userland spans sent to Inngest for proper indexing.\n */\nexport type ParentState = {\n traceparent: string;\n runId: string;\n appId: string | undefined;\n functionId: string | undefined;\n traceRef: string | undefined;\n};\n\n/**\n * An OTel span processor that is used to export spans to the Inngest endpoint.\n * This is used to track spans that are created within an Inngest run and export\n * them to the Inngest endpoint for tracing.\n *\n * It's careful to only pick relevant spans to export and will not send any\n * irrelevant spans to the Inngest endpoint.\n *\n * THIS IS THE INTERNAL IMPLEMENTATION OF THE SPAN PROCESSOR AND SHOULD NOT BE\n * USED BY USERS DIRECTLY. USE THE {@link PublicInngestSpanProcessor} CLASS\n * INSTEAD.\n */\nexport class InngestSpanProcessor implements SpanProcessor {\n /**\n * An OTel span processor that is used to export spans to the Inngest endpoint.\n * This is used to track spans that are created within an Inngest run and export\n * them to the Inngest endpoint for tracing.\n *\n * It's careful to only pick relevant spans to export and will not send any\n * irrelevant spans to the Inngest endpoint.\n */\n constructor(\n /**\n * The app that this span processor is associated with. This is used to\n * determine the Inngest endpoint to export spans to.\n *\n * It is optional here as this is the private constructor and only used\n * internally; we set `app` elsewhere as when we create the processor (as\n * early as possible when the process starts) we don't necessarily have the\n * app available yet.\n *\n * So, internally we can delay setting ths until later.\n */\n app?: Inngest.Like,\n ) {\n if (app) {\n clientProcessorMap.set(app as Inngest.Any, this);\n }\n }\n\n /**\n * A `BatchSpanProcessor` that is used to export spans to the Inngest\n * endpoint. This is created lazily to avoid creating it until the Inngest App\n * has been initialized and has had a chance to receive environment variables,\n * which may be from an incoming request.\n */\n #batcher: Promise<BatchSpanProcessor> | undefined;\n\n /**\n * A set of spans used to track spans that we care about, so that we can\n * export them to the OTel endpoint.\n *\n * If a span falls out of reference, it will be removed from this set as we'll\n * never get a chance to export it or remove it anyway.\n */\n #spansToExport = new WeakSet<Span>();\n\n /**\n * A map of span IDs to their parent state, which includes a block of\n * information that can be used and pushed back to the Inngest endpoint to\n * ingest spans.\n */\n #traceParents = new Map<string, ParentState>();\n\n /**\n * A registry used to clean up items from the `traceParents` map when spans\n * fall out of reference. This is used to avoid memory leaks in the case where\n * a span is not exported, remains unended, and is left in memory before being\n * GC'd.\n */\n #spanCleanup = new FinalizationRegistry<string>((spanId) => {\n if (spanId) {\n this.#traceParents.delete(spanId);\n }\n });\n\n /**\n * In order to only capture a subset of spans, we need to declare the initial\n * span that we care about and then export its children.\n *\n * Call this method (ideally just before execution starts) with that initial\n * span to trigger capturing all following children as well as initialize the\n * batcher.\n */\n public declareStartingSpan({\n span,\n runId,\n traceparent,\n tracestate,\n }: {\n span: Span;\n runId: string;\n traceparent: string | undefined;\n tracestate: string | undefined;\n }): void {\n // Upsert the batcher ready for later. We do this here to bootstrap it with\n // the correct async context as soon as we can. As this method is only\n // called just before execution, we know we're all set up.\n //\n // Waiting to call this until we actually need the batcher would mean that\n // we might not have the correct async context set up, as we'd likely be in\n // some span lifecycle method that doesn't have the same chain of execution.\n void this.ensureBatcherInitialized();\n\n // If we don't have a traceparent, then we can't track this span. This is\n // likely a span that we don't care about, so we can ignore it.\n if (!traceparent) {\n return processorDebug(\n \"no traceparent found for span\",\n span.spanContext().spanId,\n \"so skipping it\",\n );\n }\n\n // We also attempt to use `tracestate`. The values we fetch from these\n // should be optional, as it's likely the Executor won't need us to parrot\n // them back in later versions.\n let appId: string | undefined;\n let functionId: string | undefined;\n let traceRef: string | undefined;\n\n if (tracestate) {\n try {\n const entries = Object.fromEntries(\n tracestate.split(\",\").map((kv) => kv.split(\"=\") as [string, string]),\n );\n\n appId = entries[TraceStateKey.AppId];\n functionId = entries[TraceStateKey.FunctionId];\n traceRef = entries[TraceStateKey.TraceRef];\n } catch (err) {\n processorDebug(\n \"failed to parse tracestate\",\n tracestate,\n \"so skipping it;\",\n err,\n );\n }\n }\n\n // This is a span that we care about, so let's make sure it and its\n // children are exported.\n processorDebug.extend(\"declareStartingSpan\")(\n \"declaring:\",\n span.spanContext().spanId,\n \"for traceparent\",\n traceparent,\n );\n\n // Set a load of attributes on this span so that we can nicely identify\n // runtime, paths, etc. Only this span will have these attributes.\n span.setAttributes(InngestSpanProcessor.resourceAttributes.attributes);\n\n this.trackSpan(\n {\n appId,\n functionId,\n runId,\n traceparent,\n traceRef,\n },\n span,\n );\n }\n\n /**\n * A getter for retrieving resource attributes for the current process. This\n * is used to set the resource attributes for the spans that are exported to\n * the Inngest endpoint, and cache them for later use.\n */\n static get resourceAttributes(): Resource {\n if (!_resourceAttributes) {\n _resourceAttributes = detectResources({\n detectors: [\n osDetector,\n envDetector,\n hostDetector,\n processDetector,\n serviceInstanceIdDetector,\n ],\n });\n }\n\n return _resourceAttributes;\n }\n\n /**\n * The batcher is a singleton that is used to export spans to the OTel\n * endpoint. It is created lazily to avoid creating it until the Inngest App\n * has been initialized and has had a chance to receive environment variables,\n * which may be from an incoming request.\n *\n * The batcher is only referenced once we've found a span we're interested in,\n * so this should always have everything it needs on the app by then.\n */\n private ensureBatcherInitialized(): Promise<BatchSpanProcessor> {\n if (!this.#batcher) {\n this.#batcher = new Promise(async (resolve, reject) => {\n try {\n // We retrieve the app from the async context, so we must make sure\n // that this function is called from the correct chain.\n const store = await getAsyncCtx();\n if (!store) {\n throw new Error(\n \"No async context found; cannot create batcher to export traces\",\n );\n }\n\n const app = store.app as Inngest.Any;\n\n // Fetch the URL for the Inngest endpoint using the app's config.\n let url: URL;\n const path = \"/v1/traces/userland\";\n if (app.apiBaseUrl) {\n url = new URL(path, app.apiBaseUrl);\n } else {\n url = new URL(path, defaultInngestApiBaseUrl);\n\n if (app[\"mode\"] && app[\"mode\"].isDev && app[\"mode\"].isInferred) {\n const devHost = devServerHost() || defaultDevServerHost;\n const hasDevServer = await devServerAvailable(\n devHost,\n app[\"fetch\"],\n );\n if (hasDevServer) {\n url = new URL(path, devHost);\n }\n } else if (app[\"mode\"]?.explicitDevUrl) {\n url = new URL(path, app[\"mode\"].explicitDevUrl.href);\n }\n }\n\n processorDebug(\n \"batcher lazily accessed; creating new batcher with URL\",\n url,\n );\n\n const exporter = new OTLPTraceExporter({\n url: url.href,\n\n headers: {\n ...app[\"headers\"],\n Authorization: `Bearer ${app[\"inngestApi\"][\"signingKey\"]}`,\n },\n });\n\n resolve(new BatchSpanProcessor(exporter));\n } catch (err) {\n reject(err);\n }\n });\n }\n\n return this.#batcher;\n }\n\n /**\n * Mark a span as being tracked by this processor, meaning it will be exported\n * to the Inggest endpoint when it ends.\n */\n private trackSpan(parentState: ParentState, span: Span): void {\n const spanId = span.spanContext().spanId;\n\n this.#spanCleanup.register(span, spanId, span);\n this.#spansToExport.add(span);\n this.#traceParents.set(spanId, parentState);\n\n span.setAttribute(Attribute.InngestTraceparent, parentState.traceparent);\n span.setAttribute(Attribute.InngestRunId, parentState.runId);\n\n // Setting app ID is optional; it's likely in future versions of the\n // Executor that we don't need to parrot this back.\n if (parentState.appId) {\n span.setAttribute(Attribute.InngestAppId1, parentState.appId);\n span.setAttribute(Attribute.InngestAppId2, parentState.appId);\n }\n\n // Setting function ID is optional; it's likely in future versions of the\n // Executor that we don't need to parrot this back.\n if (parentState.functionId) {\n span.setAttribute(Attribute.InngestFunctionId, parentState.functionId);\n }\n\n if (parentState.traceRef) {\n span.setAttribute(Attribute.InngestTraceRef, parentState.traceRef);\n }\n }\n\n /**\n * Clean up any references to a span that has ended. This is used to avoid\n * memory leaks in the case where a span is not exported, remains unended, and\n * is left in memory before being GC'd.\n */\n private cleanupSpan(span: Span): void {\n const spanId = span.spanContext().spanId;\n\n // This span is no longer in use, so we can remove it from the cleanup\n // registry.\n this.#spanCleanup.unregister(span);\n this.#spansToExport.delete(span);\n this.#traceParents.delete(spanId);\n }\n\n /**\n * An implementation of the `onStart` method from the `SpanProcessor`\n * interface. This is called when a span is started, and is used to track\n * spans that are children of spans we care about.\n */\n onStart(span: Span): void {\n const debug = processorDebug.extend(\"onStart\");\n const spanId = span.spanContext().spanId;\n // 🤫 It seems to work\n const parentSpanId = (span as unknown as ReadableSpan).parentSpanContext\n ?.spanId;\n\n // The root span isn't captured here, but we can capture children of it\n // here.\n\n if (!parentSpanId) {\n // All spans that Inngest cares about will have a parent, so ignore this\n debug(\"no parent span ID for\", spanId, \"so skipping it\");\n\n return;\n }\n\n const parentState = this.#traceParents.get(parentSpanId);\n if (parentState) {\n // This span is a child of a span we care about, so add it to the list of\n // tracked spans so that we also capture its children\n debug(\n \"found traceparent\",\n parentState,\n \"in span ID\",\n parentSpanId,\n \"so adding\",\n spanId,\n );\n\n this.trackSpan(parentState, span);\n }\n }\n\n /**\n * An implementation of the `onEnd` method from the `SpanProcessor` interface.\n * This is called when a span ends, and is used to export spans to the Inngest\n * endpoint.\n */\n onEnd(span: ReadableSpan): void {\n const debug = processorDebug.extend(\"onEnd\");\n const spanId = span.spanContext().spanId;\n\n try {\n if (this.#spansToExport.has(span as unknown as Span)) {\n if (!this.#batcher) {\n return debug(\n \"batcher not initialized, so failed exporting span\",\n spanId,\n );\n }\n\n debug(\"exporting span\", spanId);\n return void this.#batcher.then((batcher) => batcher.onEnd(span));\n }\n\n debug(\"not exporting span\", spanId, \"as we don't care about it\");\n } finally {\n this.cleanupSpan(span as unknown as Span);\n }\n }\n\n /**\n * An implementation of the `forceFlush` method from the `SpanProcessor`\n * interface. This is called to force the processor to flush any spans that\n * are currently in the batcher. This is used to ensure that spans are\n * exported to the Inngest endpoint before the process exits.\n *\n * Notably, we call this in the `beforeResponse` middleware hook to ensure\n * that spans for a run as exported as soon as possible and before the\n * serverless process is killed.\n */\n async forceFlush(): Promise<void> {\n const flushDebug = processorDebug.extend(\"forceFlush\");\n flushDebug(\"force flushing batcher\");\n\n return this.#batcher\n ?.then((batcher) => batcher.forceFlush())\n .catch((err) => {\n flushDebug(\"error flushing batcher\", err, \"ignoring\");\n });\n }\n\n async shutdown(): Promise<void> {\n processorDebug.extend(\"shutdown\")(\"shutting down batcher\");\n\n return this.#batcher?.then((batcher) => batcher.shutdown());\n }\n}\n\n/**\n * An OTel span processor that is used to export spans to the Inngest endpoint.\n * This is used to track spans that are created within an Inngest run and export\n * them to the Inngest endpoint for tracing.\n *\n * It's careful to only pick relevant spans to export and will not send any\n * irrelevant spans to the Inngest endpoint.\n */\nexport class PublicInngestSpanProcessor extends InngestSpanProcessor {\n constructor(\n /**\n * The app that this span processor is associated with. This is used to\n * determine the Inngest endpoint to export spans to.\n */\n app: Inngest.Like,\n ) {\n super(app);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AA4BA,MAAM,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;;;;AAY/D,IAAa,6BAAb,cAAgD,qBAAqB;CACnE,YAKE,KACA;AACA,QAAM,IAAI"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processor.d.cts","names":[],"sources":["../../../../src/components/execution/otel/processor.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"processor.d.cts","names":[],"sources":["../../../../src/components/execution/otel/processor.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;AAwcA;;;;;;cA1Ya,oBAAA,YAAgC;;;;;;;;;;;;;;;;;;;;;;QAqBnC,OAAA,CAAQ;;;;;;;;;;;;;;;UAyDR;;;;;;;;;;mCAgFyB;;;;;;;;;;;;;;;;;;;;;;;;;;;gBA0InB;;;;;;cAuCF;;;;;;;;;;;gBAiCQ;cAWF;;;;;;;;;;cAeP,0BAAA,SAAmC,oBAAA;;;;;;OAMvC,OAAA,CAAQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processor.d.ts","names":[],"sources":["../../../../src/components/execution/otel/processor.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"processor.d.ts","names":[],"sources":["../../../../src/components/execution/otel/processor.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;AAwcA;;;;;;cA1Ya,oBAAA,YAAgC;;;;;;;;;;;;;;;;;;;;;;QAqBnC,OAAA,CAAQ;;;;;;;;;;;;;;;UAyDR;;;;;;;;;;mCAgFyB;;;;;;;;;;;;;;;;;;;;;;;;;;;gBA0InB;;;;;;cAuCF;;;;;;;;;;;gBAiCQ;cAWF;;;;;;;;;;cAeP,0BAAA,SAAmC,oBAAA;;;;;;OAMvC,OAAA,CAAQ"}
|
|
@@ -147,7 +147,10 @@ var InngestSpanProcessor = class InngestSpanProcessor {
|
|
|
147
147
|
processorDebug("batcher lazily accessed; creating new batcher with URL", url);
|
|
148
148
|
resolve(new BatchSpanProcessor(new OTLPTraceExporter({
|
|
149
149
|
url: url.href,
|
|
150
|
-
headers: {
|
|
150
|
+
headers: {
|
|
151
|
+
...app["headers"],
|
|
152
|
+
Authorization: `Bearer ${app["inngestApi"]["signingKey"]}`
|
|
153
|
+
}
|
|
151
154
|
})));
|
|
152
155
|
} catch (err) {
|
|
153
156
|
reject(err);
|