Skip to content

@trigger.dev/sdk@4.0.0

Compare
Choose a tag to compare
@github-actions github-actions released this 18 Aug 11:39
· 26 commits to main since this release
0b35cc3

Major Changes

Patch Changes

  • fix: importing from runEngine/index.js breaks non-node runtimes (#2328)

  • Run Engine 2.0 (alpha) (#1575)

  • fix: Logging large objects is now much more performant and uses less memory (#2263)

  • New internal idempotency implementation for trigger and batch trigger to prevent request retries from duplicating work (#2256)

  • When you create a Waitpoint token using wait.createToken() you get a URL back that can be used to complete it by making an HTTP POST request. (#2025)

  • feat: Support AI SDK 5.0. ai.tool now accepts either a schemaTask or a task with a provided jsonSchema (#2396)

  • External Trace Correlation & OpenTelemetry Package Updates. (#2334)

    Package Previous Version New Version Change Type
    @opentelemetry/api 1.9.0 1.9.0 No change (stable API)
    @opentelemetry/api-logs 0.52.1 0.203.0 Major update
    @opentelemetry/core - 2.0.1 New dependency
    @opentelemetry/exporter-logs-otlp-http 0.52.1 0.203.0 Major update
    @opentelemetry/exporter-trace-otlp-http 0.52.1 0.203.0 Major update
    @opentelemetry/instrumentation 0.52.1 0.203.0 Major update
    @opentelemetry/instrumentation-fetch 0.52.1 0.203.0 Major update
    @opentelemetry/resources 1.25.1 2.0.1 Major update
    @opentelemetry/sdk-logs 0.52.1 0.203.0 Major update
    @opentelemetry/sdk-node 0.52.1 - Removed (functionality consolidated)
    @opentelemetry/sdk-trace-base 1.25.1 2.0.1 Major update
    @opentelemetry/sdk-trace-node 1.25.1 2.0.1 Major update
    @opentelemetry/semantic-conventions 1.25.1 1.36.0 Minor update

    External trace correlation and propagation

    We will now correlate your external traces with trigger.dev traces and logs when using our external exporters:

    import { defineConfig } from "@trigger.dev/sdk";
    import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
    import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
    
    export default defineConfig({
      project: process.env.TRIGGER_PROJECT_REF,
      dirs: ["./src/trigger"],
      telemetry: {
        logExporters: [
          new OTLPLogExporter({
            url: "https://api.axiom.co/v1/logs",
            headers: {
              Authorization: `Bearer ${process.env.AXIOM_TOKEN}`,
              "X-Axiom-Dataset": "test",
            },
          }),
        ],
        exporters: [
          new OTLPTraceExporter({
            url: "https://api.axiom.co/v1/traces",
            headers: {
              Authorization: `Bearer ${process.env.AXIOM_TOKEN}`,
              "X-Axiom-Dataset": "test",
            },
          }),
        ],
      },
      maxDuration: 3600,
    });

    You can also now propagate your external trace context when calling back into your own backend infra from inside a trigger.dev task:

    import { otel, task } from "@trigger.dev/sdk";
    import { context, propagation } from "@opentelemetry/api";
    
    async function callNextjsApp() {
      return await otel.withExternalTrace(async () => {
        const headersObject = {};
    
        // Now context.active() refers to your external trace context
        propagation.inject(context.active(), headersObject);
    
        const result = await fetch("http://localhost:3000/api/demo-call-from-trigger", {
          headers: new Headers(headersObject),
          method: "POST",
          body: JSON.stringify({
            message: "Hello from Trigger.dev",
          }),
        });
    
        return result.json();
      });
    }
    
    export const myTask = task({
      id: "my-task",
      run: async (payload: any) => {
        await callNextjsApp();
      },
    });
  • Add jsonSchema support when indexing tasks (#2353)

  • Fixed an issue with realtime streams that timeout and resume streaming dropping chunks (#1993)

  • Added and cleaned up the run ctx param: (#2322)

    • New optional properties ctx.run.parentTaskRunId and ctx.run.rootTaskRunId reference the current run's root/parent ID.
    • Removed deprecated properties from ctx
    • Added a new ctx.deployment object that contains information about the deployment associated with the run.

    We also update metadata.root and metadata.parent to work even when the run is a "root" run (meaning it doesn't have a parent or a root associated run). This now works:

    metadata.root.set("foo", "bar");
    metadata.parent.set("baz", 1);
    metadata.current().foo; // "bar"
    metadata.current().baz; // 1
  • The envvars.list() and retrieve() functions receive isSecret for each value. Secret values are always redacted. (#1942)

  • Fix issue where realtime streams would cut off after 5 minutes (#1952)

  • Deprecate toolTask and replace with ai.tool(mySchemaTask) (#1863)

  • Display clickable links in Cursor terminal (#1998)

  • Removes the releaseConcurrencyOnWaitpoint option on queues and the releaseConcurrency option on various wait functions. Replaced with the following default behavior: (#2284)

    • Concurrency is never released when a run is first blocked via a waitpoint, at either the env or queue level.
    • Concurrency is always released when a run is checkpointed and shutdown, at both the env and queue level.

    Additionally, environment concurrency limits now have a new "Burst Factor", defaulting to 2.0x. The "Burst Factor" allows the environment-wide concurrency limit to be higher than any individual queue's concurrency limit. For example, if you have an environment concurrency limit of 100, and a Burst Factor of 2.0x, then you can execute up to 200 runs concurrently, but any one task/queue can still only execute 100 runs concurrently.

    We've done some work cleaning up the run statuses. The new statuses are:

    • PENDING_VERSION: Task is waiting for a version update because it cannot execute without additional information (task, queue, etc.)
    • QUEUED: Task is waiting to be executed by a worker
    • DEQUEUED: Task has been dequeued and is being sent to a worker to start executing.
    • EXECUTING: Task is currently being executed by a worker
    • WAITING: Task has been paused by the system, and will be resumed by the system
    • COMPLETED: Task has been completed successfully
    • CANCELED: Task has been canceled by the user
    • FAILED: Task has failed to complete, due to an error in the system
    • CRASHED: Task has crashed and won't be retried, most likely the worker ran out of resources, e.g. memory or storage
    • SYSTEM_FAILURE: Task has failed to complete, due to an error in the system
    • DELAYED: Task has been scheduled to run at a specific time
    • EXPIRED: Task has expired and won't be executed
    • TIMED_OUT: Task has reached it's maxDuration and has been stopped

    We've removed the following statuses:

    • WAITING_FOR_DEPLOY: This is no longer used, and is replaced by PENDING_VERSION
    • FROZEN: This is no longer used, and is replaced by WAITING
    • INTERRUPTED: This is no longer used
    • REATTEMPTING: This is no longer used, and is replaced by EXECUTING

    We've also added "boolean" helpers to runs returned via the API and from Realtime:

    • isQueued: Returns true when the status is QUEUED, PENDING_VERSION, or DELAYED
    • isExecuting: Returns true when the status is EXECUTING, DEQUEUED. These count against your concurrency limits.
    • isWaiting: Returns true when the status is WAITING. These do not count against your concurrency limits.
    • isCompleted: Returns true when the status is any of the completed statuses.
    • isCanceled: Returns true when the status is CANCELED
    • isFailed: Returns true when the status is any of the failed statuses.
    • isSuccess: Returns true when the status is COMPLETED

    This change adds the ability to easily detect which runs are being counted against your concurrency limit by filtering for both EXECUTING or DEQUEUED.

  • Add onCancel lifecycle hook (#2022)

  • Provide realtime skipColumns option via untamperable public access tokens (#2201)

  • Removed triggerAndPoll. It was never recommended so it's been removed. (#2379)

  • Improve metadata flushing efficiency by collapsing operations (#2106)

  • Upgrade to zod 3.25.76 (#2352)

  • Specify a region override when triggering a run (#2366)

  • Added runs.list filtering for queue and machine (#2277)

  • maintain proper context in metadata.root and parent getters (#1917)

  • v4: New lifecycle hooks (#1817)

  • Updated dependencies:

    • @trigger.dev/core@4.0.0