Skip to content

latest @opentelemetry packages and correlate external traces #2334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

ericallam
Copy link
Member

@ericallam ericallam commented Aug 1, 2025

CleanShot 2025-08-01 at 15 27 14

External Trace Correlation & OpenTelemetry Package Updates

Overview

This PR introduces external trace correlation capabilities to Trigger.dev, enabling seamless distributed tracing across system boundaries. Additionally, we've updated all OpenTelemetry packages to their latest stable versions, bringing significant performance improvements and new features.

Key Changes

1. External Trace Correlation

We've implemented a comprehensive trace context management system that allows Trigger.dev to:

  • Receive external traces: Accept and propagate trace context from external systems (e.g., Next.js, Express, or any OpenTelemetry-instrumented application)
  • Pass-through trace context: Maintain trace continuity when Trigger.dev acts as an intermediary between services
  • Bi-directional correlation: Support both incoming and outgoing trace propagation

Architecture

The implementation introduces a new TraceContextManager that:

  • Manages trace context extraction and injection
  • Provides a global API for trace context operations
  • Supports W3C Trace Context propagation standard
  • Maintains backward compatibility with existing tracing infrastructure

2. OpenTelemetry Package Updates

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

3. Environment Variable Improvements

  • Introduced TRIGGER_ prefix for all Trigger.dev-specific OpenTelemetry environment variables
  • This allows users to override OpenTelemetry configuration without conflicts
  • Maintains backward compatibility while providing better isolation

Technical Implementation Details

Trace Context 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";

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()
  }
})

Key Files Modified

  • Core Changes:

    • packages/core/src/v3/traceContext/*: New trace context management system
    • packages/core/src/v3/otel/tracingSDK.ts: Updated SDK initialization with new packages
    • apps/webapp/app/runEngine/services/triggerTask.server.ts: External trace propagation logic
  • API Endpoints:

    • apps/webapp/app/routes/api.v1.tasks.$taskId.trigger.ts: Accept external trace headers
    • apps/webapp/app/routes/api.v2.tasks.batch.ts: Batch trigger trace propagation

Benefits

  1. Enhanced Observability: Complete end-to-end tracing across microservices and external systems
  2. Performance Improvements: Latest OpenTelemetry packages include significant performance optimizations
  3. Standards Compliance: Full W3C Trace Context support for better interoperability
  4. Developer Experience: Automatic trace correlation reduces manual instrumentation needs

Migration Notes

  • No breaking changes for existing users
  • External trace correlation is opt-in via trace headers
  • Environment variable prefixing is backward compatible

Testing

  • Updated E2E tests for OpenTelemetry compatibility
  • Added integration tests for external trace propagation
  • Verified backward compatibility with existing traces

Future Considerations

This foundation enables future enhancements such as:

  • Baggage propagation for custom context
  • Trace sampling configuration per external source
  • Enhanced trace visualization in the Trigger.dev dashboard

Copy link

changeset-bot bot commented Aug 1, 2025

🦋 Changeset detected

Latest commit: 54a3f2a

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

coderabbitai bot commented Aug 1, 2025

Walkthrough

This set of changes introduces a comprehensive overhaul of trace context management and OpenTelemetry (OTEL) integration across the codebase. A new trace context API is implemented, featuring a TraceContextManager interface, a standard manager, and a singleton API for global access and propagation. The trace context structure is formalized via the TriggerTraceContext schema, supporting nested and external traceparent/tracestate fields. Numerous type signatures are updated to use the new schema or more flexible types. Core logic for extracting, serializing, and propagating trace context is refactored in both backend and worker code, including propagation of external trace IDs for correlation with external telemetry. OTEL resource detection and exporter logic are updated, with environment variable names standardized to a TRIGGER_OTEL_ prefix. OpenTelemetry dependencies are upgraded to major new versions, and related code is modernized accordingly. CLI and SDK code is refactored to remove custom tracing logic, centralizing trace context handling via the new API. UI and repository layers are adjusted to surface and utilize external trace IDs and context.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Complexity label: Complex

  • The review requires understanding significant architectural changes in trace context management, including new APIs, types, and propagation logic.
  • Type changes and refactoring span multiple packages (core, SDK, CLI, webapp, internal engine), affecting both backend and frontend.
  • OpenTelemetry upgrades necessitate careful review of compatibility and correctness in resource detection, exporter wrapping, and environment variable handling.
  • The introduction of new modules and removal of legacy tracing logic increases the scope.
  • Reviewers must verify correct integration and propagation of external trace context, especially for distributed tracing scenarios.
  • Estimated time reflects the need to trace changes across dozens of files and ensure correct usage patterns throughout the stack.

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 328996a and a720f37.

⛔ Files ignored due to path filters (7)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • references/d3-chat/package.json is excluded by !references/**
  • references/d3-chat/src/app/api/demo-batch-trigger/route.ts is excluded by !references/**
  • references/d3-chat/src/app/api/demo-call-from-trigger/route.ts is excluded by !references/**
  • references/d3-chat/src/app/api/demo-trigger/route.ts is excluded by !references/**
  • references/d3-chat/src/instrumentation.ts is excluded by !references/**
  • references/d3-chat/src/trigger/chat.ts is excluded by !references/**
📒 Files selected for processing (40)
  • .changeset/five-nails-whisper.md (1 hunks)
  • apps/webapp/app/presenters/v3/SpanPresenter.server.ts (5 hunks)
  • apps/webapp/app/routes/api.v1.tasks.$taskId.trigger.ts (2 hunks)
  • apps/webapp/app/routes/api.v2.tasks.batch.ts (1 hunks)
  • apps/webapp/app/routes/resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.runs.$runParam.spans.$spanParam/route.tsx (1 hunks)
  • apps/webapp/app/runEngine/services/batchTrigger.server.ts (1 hunks)
  • apps/webapp/app/runEngine/services/triggerTask.server.ts (3 hunks)
  • apps/webapp/app/runEngine/types.ts (2 hunks)
  • apps/webapp/app/v3/environmentVariableRules.server.ts (0 hunks)
  • apps/webapp/app/v3/environmentVariables/environmentVariablesRepository.server.ts (6 hunks)
  • apps/webapp/app/v3/eventRepository.server.ts (8 hunks)
  • apps/webapp/app/v3/services/triggerTask.server.ts (1 hunks)
  • apps/webapp/test/environmentVariableRules.test.ts (1 hunks)
  • internal-packages/run-engine/src/engine/types.ts (2 hunks)
  • packages/cli-v3/package.json (1 hunks)
  • packages/cli-v3/src/cli/common.ts (2 hunks)
  • packages/cli-v3/src/entryPoints/dev-run-worker.ts (9 hunks)
  • packages/cli-v3/src/entryPoints/managed-run-worker.ts (9 hunks)
  • packages/cli-v3/src/telemetry/tracing.ts (0 hunks)
  • packages/cli-v3/src/utilities/session.ts (1 hunks)
  • packages/core/package.json (1 hunks)
  • packages/core/src/v3/apiClient/core.ts (1 hunks)
  • packages/core/src/v3/index.ts (1 hunks)
  • packages/core/src/v3/isomorphic/index.ts (1 hunks)
  • packages/core/src/v3/isomorphic/traceContext.ts (1 hunks)
  • packages/core/src/v3/otel/tracingSDK.ts (8 hunks)
  • packages/core/src/v3/schemas/schemas.ts (1 hunks)
  • packages/core/src/v3/taskContext/otelProcessors.ts (2 hunks)
  • packages/core/src/v3/trace-context-api.ts (1 hunks)
  • packages/core/src/v3/traceContext/api.ts (1 hunks)
  • packages/core/src/v3/traceContext/manager.ts (1 hunks)
  • packages/core/src/v3/traceContext/types.ts (1 hunks)
  • packages/core/src/v3/tracer.ts (0 hunks)
  • packages/core/src/v3/utils/globals.ts (2 hunks)
  • packages/core/src/v3/workers/index.ts (1 hunks)
  • packages/core/src/v3/workers/taskExecutor.ts (4 hunks)
  • packages/core/test/taskExecutor.test.ts (1 hunks)
  • packages/trigger-sdk/package.json (1 hunks)
  • packages/trigger-sdk/src/v3/index.ts (1 hunks)
  • packages/trigger-sdk/src/v3/otel.ts (1 hunks)
💤 Files with no reviewable changes (3)
  • packages/core/src/v3/tracer.ts
  • apps/webapp/app/v3/environmentVariableRules.server.ts
  • packages/cli-v3/src/telemetry/tracing.ts
✅ Files skipped from review due to trivial changes (5)
  • packages/core/src/v3/workers/index.ts
  • apps/webapp/app/routes/resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.runs.$runParam.spans.$spanParam/route.tsx
  • packages/core/src/v3/index.ts
  • apps/webapp/app/runEngine/services/batchTrigger.server.ts
  • packages/core/src/v3/taskContext/otelProcessors.ts
🚧 Files skipped from review as they are similar to previous changes (31)
  • packages/core/src/v3/utils/globals.ts
  • internal-packages/run-engine/src/engine/types.ts
  • packages/core/src/v3/isomorphic/index.ts
  • packages/trigger-sdk/package.json
  • apps/webapp/app/routes/api.v2.tasks.batch.ts
  • apps/webapp/test/environmentVariableRules.test.ts
  • packages/trigger-sdk/src/v3/index.ts
  • packages/core/src/v3/trace-context-api.ts
  • apps/webapp/app/v3/services/triggerTask.server.ts
  • packages/core/src/v3/apiClient/core.ts
  • apps/webapp/app/routes/api.v1.tasks.$taskId.trigger.ts
  • .changeset/five-nails-whisper.md
  • packages/cli-v3/src/entryPoints/managed-run-worker.ts
  • packages/core/src/v3/schemas/schemas.ts
  • apps/webapp/app/runEngine/types.ts
  • packages/trigger-sdk/src/v3/otel.ts
  • packages/core/test/taskExecutor.test.ts
  • packages/core/package.json
  • packages/cli-v3/package.json
  • packages/core/src/v3/isomorphic/traceContext.ts
  • packages/cli-v3/src/entryPoints/dev-run-worker.ts
  • apps/webapp/app/presenters/v3/SpanPresenter.server.ts
  • packages/cli-v3/src/utilities/session.ts
  • packages/core/src/v3/traceContext/types.ts
  • packages/core/src/v3/workers/taskExecutor.ts
  • apps/webapp/app/runEngine/services/triggerTask.server.ts
  • packages/core/src/v3/traceContext/api.ts
  • packages/core/src/v3/traceContext/manager.ts
  • apps/webapp/app/v3/eventRepository.server.ts
  • packages/cli-v3/src/cli/common.ts
  • apps/webapp/app/v3/environmentVariables/environmentVariablesRepository.server.ts
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)

**/*.{ts,tsx}: Always prefer using isomorphic code like fetch, ReadableStream, etc. instead of Node.js specific code
For TypeScript, we usually use types over interfaces
Avoid enums
No default exports, use function declarations

Files:

  • packages/core/src/v3/otel/tracingSDK.ts
{packages/core,apps/webapp}/**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)

We use zod a lot in packages/core and in the webapp

Files:

  • packages/core/src/v3/otel/tracingSDK.ts
🧠 Learnings (14)
📓 Common learnings
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to trigger.config.ts : Global lifecycle hooks, telemetry, runtime, machine settings, log level, max duration, and build configuration must be set in `trigger.config.ts` as shown.
📚 Learning: applies to **/trigger/**/*.{ts,tsx,js,jsx} : always generate trigger.dev tasks using the `task` func...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : ALWAYS generate Trigger.dev tasks using the `task` function from `@trigger.dev/sdk/v3` and export them as shown in the correct pattern.

Applied to files:

  • packages/core/src/v3/otel/tracingSDK.ts
📚 Learning: applies to **/trigger/**/*.{ts,tsx,js,jsx} : you must use `@trigger.dev/sdk/v3` when writing trigger...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : You MUST use `@trigger.dev/sdk/v3` when writing Trigger.dev tasks.

Applied to files:

  • packages/core/src/v3/otel/tracingSDK.ts
📚 Learning: applies to trigger.config.ts : global lifecycle hooks, telemetry, runtime, machine settings, log lev...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to trigger.config.ts : Global lifecycle hooks, telemetry, runtime, machine settings, log level, max duration, and build configuration must be set in `trigger.config.ts` as shown.

Applied to files:

  • packages/core/src/v3/otel/tracingSDK.ts
📚 Learning: before generating any code for trigger.dev tasks, verify: (1) are you importing from `@trigger.dev/s...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Before generating any code for Trigger.dev tasks, verify: (1) Are you importing from `@trigger.dev/sdk/v3`? (2) Have you exported every task? (3) Have you generated any deprecated code patterns?

Applied to files:

  • packages/core/src/v3/otel/tracingSDK.ts
📚 Learning: applies to apps/webapp/**/*.{ts,tsx} : in the webapp, all environment variables must be accessed thr...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/webapp.mdc:0-0
Timestamp: 2025-07-18T17:49:47.180Z
Learning: Applies to apps/webapp/**/*.{ts,tsx} : In the webapp, all environment variables must be accessed through the `env` export of `env.server.ts`, instead of directly accessing `process.env`.

Applied to files:

  • packages/core/src/v3/otel/tracingSDK.ts
📚 Learning: applies to **/trigger/**/*.{ts,tsx,js,jsx} : when implementing scheduled (cron) tasks, use `schedule...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : When implementing scheduled (cron) tasks, use `schedules.task` from `@trigger.dev/sdk/v3` and follow the shown patterns.

Applied to files:

  • packages/core/src/v3/otel/tracingSDK.ts
📚 Learning: applies to **/trigger/**/*.{ts,tsx,js,jsx} : never generate deprecated code patterns using `client.d...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : NEVER generate deprecated code patterns using `client.defineJob` and related deprecated APIs, as shown in the prohibited code block.

Applied to files:

  • packages/core/src/v3/otel/tracingSDK.ts
📚 Learning: applies to **/trigger/**/*.{ts,tsx,js,jsx} : when triggering a task from backend code, use `tasks.tr...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : When triggering a task from backend code, use `tasks.trigger`, `tasks.batchTrigger`, or `tasks.triggerAndPoll` as shown in the examples.

Applied to files:

  • packages/core/src/v3/otel/tracingSDK.ts
📚 Learning: applies to **/trigger/**/*.{ts,tsx,js,jsx} : when logging in tasks, use the `logger` api (`logger.de...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : When logging in tasks, use the `logger` API (`logger.debug`, `logger.log`, `logger.info`, `logger.warn`, `logger.error`) as shown.

Applied to files:

  • packages/core/src/v3/otel/tracingSDK.ts
📚 Learning: in the trigger.dev codebase, the supervisor component uses docker_enforce_machine_presets while the ...
Learnt from: nicktrn
PR: triggerdotdev/trigger.dev#2150
File: apps/supervisor/src/workloadManager/docker.ts:115-115
Timestamp: 2025-06-04T16:02:22.957Z
Learning: In the Trigger.dev codebase, the supervisor component uses DOCKER_ENFORCE_MACHINE_PRESETS while the docker provider component uses ENFORCE_MACHINE_PRESETS. These are separate components with separate environment variable configurations for the same logical concept of enforcing machine presets.

Applied to files:

  • packages/core/src/v3/otel/tracingSDK.ts
📚 Learning: in the trigger.dev project, .env.example files should contain actual example secret values rather th...
Learnt from: nicktrn
PR: triggerdotdev/trigger.dev#2155
File: hosting/docker/.env.example:4-7
Timestamp: 2025-06-06T23:55:01.933Z
Learning: In the trigger.dev project, .env.example files should contain actual example secret values rather than placeholders, as these help users understand the expected format. The files include clear warnings about not using these defaults in production and instructions for generating proper secrets.

Applied to files:

  • packages/core/src/v3/otel/tracingSDK.ts
📚 Learning: applies to trigger.config.ts : the `trigger.config.ts` file must use `defineconfig` from `@trigger.d...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to trigger.config.ts : The `trigger.config.ts` file must use `defineConfig` from `@trigger.dev/sdk/v3` and follow the configuration structure shown.

Applied to files:

  • packages/core/src/v3/otel/tracingSDK.ts
📚 Learning: applies to trigger.config.ts : build extensions such as `additionalfiles`, `additionalpackages`, `ap...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to trigger.config.ts : Build extensions such as `additionalFiles`, `additionalPackages`, `aptGet`, `emitDecoratorMetadata`, `prismaExtension`, `syncEnvVars`, `puppeteer`, `ffmpeg`, and `esbuildPlugin` must be configured in `trigger.config.ts` as shown.

Applied to files:

  • packages/core/src/v3/otel/tracingSDK.ts
🧬 Code Graph Analysis (1)
packages/core/src/v3/otel/tracingSDK.ts (6)
packages/core/src/v3/utils/getEnv.ts (1)
  • getEnvVar (11-13)
packages/core/src/v3/semanticInternalAttributes.ts (1)
  • SemanticInternalAttributes (1-64)
packages/core/src/v3/task-context-api.ts (1)
  • taskContext (5-5)
packages/core/src/v3/taskContext/otelProcessors.ts (2)
  • TaskContextSpanProcessor (8-46)
  • TaskContextLogProcessor (84-106)
packages/core/src/v3/trace-context-api.ts (1)
  • traceContext (5-5)
packages/core/src/v3/limits.ts (8)
  • OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT (14-17)
  • OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT (22-25)
  • OTEL_SPAN_EVENT_COUNT_LIMIT (30-33)
  • OTEL_ATTRIBUTE_PER_EVENT_COUNT_LIMIT (39-42)
  • OTEL_LINK_COUNT_LIMIT (34-34)
  • OTEL_ATTRIBUTE_PER_LINK_COUNT_LIMIT (35-38)
  • OTEL_LOG_ATTRIBUTE_COUNT_LIMIT (18-21)
  • OTEL_LOG_ATTRIBUTE_VALUE_LENGTH_LIMIT (26-29)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (23)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (1, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (8, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (3, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (7, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (6, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (4, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (2, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (1, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (2, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (5, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (3, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (8, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (6, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (7, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (4, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (5, 8)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: units / packages / 🧪 Unit Tests: Packages (1, 1)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - pnpm)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (6)
packages/core/src/v3/otel/tracingSDK.ts (6)

3-3: LGTM! Import changes support the architectural improvements.

The new imports correctly support the unified resource detection, external trace context features, and integration with the new trace context API.

Also applies to: 7-7, 11-12, 16-16, 37-37, 42-42


76-76: LGTM! Environment variable naming is now consistent.

All OpenTelemetry environment variables now consistently use the TRIGGER_OTEL_ prefix, providing proper namespace isolation. The systematic renaming has been applied correctly throughout the file.

Also applies to: 88-88, 108-119, 130-143, 179-190, 198-215


103-164: Excellent architectural improvement with processor arrays.

The refactoring to collect processors into arrays before passing them to provider constructors is much cleaner than the previous post-construction approach. The integration with external trace context through wrapper classes provides good separation of concerns.

Also applies to: 177-236


289-360: Well-designed external span exporter wrapper.

The implementation correctly handles trace ID correlation, partial span filtering, and special attempt span logic. The parent span context adjustment for attempt spans ensures proper trace hierarchy in external systems.


126-126: Excellent integration with trace context API.

The use of traceContext.getExternalTraceContext() properly connects the tracing SDK with the new trace context management system, enabling the external trace correlation capabilities that are central to this PR.


1-412: Strong architectural improvements with external trace correlation.

This refactoring successfully implements the key objectives of external trace correlation while modernizing the OpenTelemetry integration. The processor array approach, consistent environment variable naming, and wrapper-based trace correlation provide a solid foundation for the enhanced observability features.

Two critical issues from previous reviews still need resolution:

  1. Async resource detection not being awaited (line 81-96)
  2. Inconsistent null handling in log wrapper (line 383-390)

Once these are addressed, this will be an excellent enhancement to the tracing capabilities.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch opentelemetry-deps-update

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 9

🧹 Nitpick comments (4)
packages/trigger-sdk/package.json (1)

53-53: Consider loosening the sem-ver pin on @opentelemetry/semantic-conventions.

Pinning to the exact version 1.36.0 means we won’t receive patch-level fixes (including potential security fixes) unless we bump manually. Unless you have a reproducibility requirement, prefer a caret range:

-    "@opentelemetry/semantic-conventions": "1.36.0",
+    "@opentelemetry/semantic-conventions": "^1.36.0",

This stays within the same major line while allowing non-breaking updates.

apps/webapp/app/routes/resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.runs.$runParam.spans.$spanParam/route.tsx (1)

741-746: UI addition LGTM – one UX micro-nit.

Displaying the external trace ID is valuable. The ID can be long; consider wrapping with break-all (as done for other long strings above) to avoid horizontal scroll on narrow viewports:

-                    <Property.Value>{run.externalTraceId}</Property.Value>
+                    <Property.Value className="break-all">
+                      {run.externalTraceId}
+                    </Property.Value>
apps/webapp/app/routes/api.v1.tasks.$taskId.trigger.ts (1)

113-119: Consider consolidating debug logs.

This debug log duplicates most of the information from the log immediately above (lines 102-111). Consider either:

  1. Removing this duplicate log
  2. Consolidating both into a single log entry
  3. Adding a comment explaining why separate logging is needed for OpenTelemetry context
-      logger.debug("Triggering task", {
-        taskId: params.taskId,
-        idempotencyKey,
-        idempotencyKeyTTL,
-        triggerVersion,
-        headers,
-        options: body.options,
-        isFromWorker,
-        traceContext,
-      });
-
-      logger.debug("[otelContext]", {
-        taskId: params.taskId,
-        headers,
-        options: body.options,
-        isFromWorker,
-        traceContext,
-      });
+      logger.debug("Triggering task", {
+        taskId: params.taskId,
+        idempotencyKey,
+        idempotencyKeyTTL,
+        triggerVersion,
+        headers,
+        options: body.options,
+        isFromWorker,
+        traceContext,
+        otelContext: true, // Flag for OpenTelemetry context debugging
+      });
packages/core/src/v3/traceContext/manager.ts (1)

20-20: Remove unnecessary null coalescing operator

Since traceContext is initialized to {} in the constructor, the null coalescing operator is redundant.

-    return propagation.extract(context.active(), this.traceContext ?? {});
+    return propagation.extract(context.active(), this.traceContext);

@ericallam ericallam force-pushed the opentelemetry-deps-update branch from de3d6ac to 54a3f2a Compare August 1, 2025 21:16
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between de3d6ac and 54a3f2a.

⛔ Files ignored due to path filters (7)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • references/d3-chat/package.json is excluded by !references/**
  • references/d3-chat/src/app/api/demo-batch-trigger/route.ts is excluded by !references/**
  • references/d3-chat/src/app/api/demo-call-from-trigger/route.ts is excluded by !references/**
  • references/d3-chat/src/app/api/demo-trigger/route.ts is excluded by !references/**
  • references/d3-chat/src/instrumentation.ts is excluded by !references/**
  • references/d3-chat/src/trigger/chat.ts is excluded by !references/**
📒 Files selected for processing (41)
  • .changeset/five-nails-whisper.md (1 hunks)
  • apps/webapp/app/presenters/v3/SpanPresenter.server.ts (5 hunks)
  • apps/webapp/app/routes/api.v1.tasks.$taskId.trigger.ts (2 hunks)
  • apps/webapp/app/routes/api.v2.tasks.batch.ts (1 hunks)
  • apps/webapp/app/routes/resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.runs.$runParam.spans.$spanParam/route.tsx (1 hunks)
  • apps/webapp/app/runEngine/services/batchTrigger.server.ts (1 hunks)
  • apps/webapp/app/runEngine/services/triggerTask.server.ts (3 hunks)
  • apps/webapp/app/runEngine/types.ts (2 hunks)
  • apps/webapp/app/v3/environmentVariableRules.server.ts (0 hunks)
  • apps/webapp/app/v3/environmentVariables/environmentVariablesRepository.server.ts (6 hunks)
  • apps/webapp/app/v3/eventRepository.server.ts (8 hunks)
  • apps/webapp/app/v3/services/triggerTask.server.ts (1 hunks)
  • apps/webapp/test/environmentVariableRules.test.ts (1 hunks)
  • internal-packages/run-engine/src/engine/index.ts (1 hunks)
  • internal-packages/run-engine/src/engine/types.ts (1 hunks)
  • packages/cli-v3/package.json (1 hunks)
  • packages/cli-v3/src/cli/common.ts (2 hunks)
  • packages/cli-v3/src/entryPoints/dev-run-worker.ts (9 hunks)
  • packages/cli-v3/src/entryPoints/managed-run-worker.ts (9 hunks)
  • packages/cli-v3/src/telemetry/tracing.ts (0 hunks)
  • packages/cli-v3/src/utilities/session.ts (1 hunks)
  • packages/core/package.json (1 hunks)
  • packages/core/src/v3/apiClient/core.ts (1 hunks)
  • packages/core/src/v3/index.ts (1 hunks)
  • packages/core/src/v3/isomorphic/index.ts (1 hunks)
  • packages/core/src/v3/isomorphic/traceContext.ts (1 hunks)
  • packages/core/src/v3/otel/tracingSDK.ts (10 hunks)
  • packages/core/src/v3/schemas/schemas.ts (1 hunks)
  • packages/core/src/v3/taskContext/otelProcessors.ts (2 hunks)
  • packages/core/src/v3/trace-context-api.ts (1 hunks)
  • packages/core/src/v3/traceContext/api.ts (1 hunks)
  • packages/core/src/v3/traceContext/manager.ts (1 hunks)
  • packages/core/src/v3/traceContext/types.ts (1 hunks)
  • packages/core/src/v3/tracer.ts (0 hunks)
  • packages/core/src/v3/utils/globals.ts (2 hunks)
  • packages/core/src/v3/workers/index.ts (1 hunks)
  • packages/core/src/v3/workers/taskExecutor.ts (4 hunks)
  • packages/core/test/taskExecutor.test.ts (1 hunks)
  • packages/trigger-sdk/package.json (1 hunks)
  • packages/trigger-sdk/src/v3/index.ts (1 hunks)
  • packages/trigger-sdk/src/v3/otel.ts (1 hunks)
💤 Files with no reviewable changes (3)
  • apps/webapp/app/v3/environmentVariableRules.server.ts
  • packages/core/src/v3/tracer.ts
  • packages/cli-v3/src/telemetry/tracing.ts
✅ Files skipped from review due to trivial changes (11)
  • apps/webapp/app/routes/resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.runs.$runParam.spans.$spanParam/route.tsx
  • internal-packages/run-engine/src/engine/types.ts
  • internal-packages/run-engine/src/engine/index.ts
  • packages/trigger-sdk/src/v3/otel.ts
  • packages/core/src/v3/index.ts
  • apps/webapp/app/runEngine/services/batchTrigger.server.ts
  • packages/core/src/v3/workers/index.ts
  • apps/webapp/test/environmentVariableRules.test.ts
  • packages/core/src/v3/schemas/schemas.ts
  • packages/core/package.json
  • packages/core/src/v3/workers/taskExecutor.ts
🚧 Files skipped from review as they are similar to previous changes (25)
  • packages/trigger-sdk/package.json
  • packages/core/src/v3/trace-context-api.ts
  • apps/webapp/app/v3/services/triggerTask.server.ts
  • apps/webapp/app/routes/api.v2.tasks.batch.ts
  • packages/core/src/v3/utils/globals.ts
  • apps/webapp/app/routes/api.v1.tasks.$taskId.trigger.ts
  • packages/trigger-sdk/src/v3/index.ts
  • packages/cli-v3/src/utilities/session.ts
  • apps/webapp/app/runEngine/types.ts
  • packages/core/src/v3/isomorphic/index.ts
  • packages/core/src/v3/apiClient/core.ts
  • packages/cli-v3/src/cli/common.ts
  • packages/cli-v3/src/entryPoints/dev-run-worker.ts
  • packages/cli-v3/src/entryPoints/managed-run-worker.ts
  • packages/core/test/taskExecutor.test.ts
  • apps/webapp/app/runEngine/services/triggerTask.server.ts
  • apps/webapp/app/v3/environmentVariables/environmentVariablesRepository.server.ts
  • packages/core/src/v3/traceContext/types.ts
  • packages/core/src/v3/isomorphic/traceContext.ts
  • packages/cli-v3/package.json
  • packages/core/src/v3/traceContext/manager.ts
  • packages/core/src/v3/traceContext/api.ts
  • packages/core/src/v3/taskContext/otelProcessors.ts
  • apps/webapp/app/v3/eventRepository.server.ts
  • apps/webapp/app/presenters/v3/SpanPresenter.server.ts
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)

**/*.{ts,tsx}: Always prefer using isomorphic code like fetch, ReadableStream, etc. instead of Node.js specific code
For TypeScript, we usually use types over interfaces
Avoid enums
No default exports, use function declarations

Files:

  • packages/core/src/v3/otel/tracingSDK.ts
{packages/core,apps/webapp}/**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)

We use zod a lot in packages/core and in the webapp

Files:

  • packages/core/src/v3/otel/tracingSDK.ts
🧠 Learnings (14)
📓 Common learnings
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to trigger.config.ts : Global lifecycle hooks, telemetry, runtime, machine settings, log level, max duration, and build configuration must be set in `trigger.config.ts` as shown.
📚 Learning: applies to **/trigger/**/*.{ts,tsx,js,jsx} : always generate trigger.dev tasks using the `task` func...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : ALWAYS generate Trigger.dev tasks using the `task` function from `@trigger.dev/sdk/v3` and export them as shown in the correct pattern.

Applied to files:

  • .changeset/five-nails-whisper.md
  • packages/core/src/v3/otel/tracingSDK.ts
📚 Learning: applies to **/trigger/**/*.{ts,tsx,js,jsx} : you must use `@trigger.dev/sdk/v3` when writing trigger...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : You MUST use `@trigger.dev/sdk/v3` when writing Trigger.dev tasks.

Applied to files:

  • .changeset/five-nails-whisper.md
  • packages/core/src/v3/otel/tracingSDK.ts
📚 Learning: applies to **/trigger/**/*.{ts,tsx,js,jsx} : when implementing schema tasks, use `schematask` from `...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : When implementing schema tasks, use `schemaTask` from `@trigger.dev/sdk/v3` and validate payloads as shown.

Applied to files:

  • .changeset/five-nails-whisper.md
📚 Learning: applies to **/trigger/**/*.{ts,tsx,js,jsx} : when implementing scheduled (cron) tasks, use `schedule...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : When implementing scheduled (cron) tasks, use `schedules.task` from `@trigger.dev/sdk/v3` and follow the shown patterns.

Applied to files:

  • .changeset/five-nails-whisper.md
📚 Learning: before generating any code for trigger.dev tasks, verify: (1) are you importing from `@trigger.dev/s...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Before generating any code for Trigger.dev tasks, verify: (1) Are you importing from `@trigger.dev/sdk/v3`? (2) Have you exported every task? (3) Have you generated any deprecated code patterns?

Applied to files:

  • .changeset/five-nails-whisper.md
📚 Learning: applies to trigger.config.ts : global lifecycle hooks, telemetry, runtime, machine settings, log lev...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to trigger.config.ts : Global lifecycle hooks, telemetry, runtime, machine settings, log level, max duration, and build configuration must be set in `trigger.config.ts` as shown.

Applied to files:

  • .changeset/five-nails-whisper.md
  • packages/core/src/v3/otel/tracingSDK.ts
📚 Learning: applies to trigger.config.ts : build extensions such as `additionalfiles`, `additionalpackages`, `ap...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to trigger.config.ts : Build extensions such as `additionalFiles`, `additionalPackages`, `aptGet`, `emitDecoratorMetadata`, `prismaExtension`, `syncEnvVars`, `puppeteer`, `ffmpeg`, and `esbuildPlugin` must be configured in `trigger.config.ts` as shown.

Applied to files:

  • .changeset/five-nails-whisper.md
  • packages/core/src/v3/otel/tracingSDK.ts
📚 Learning: applies to **/trigger/**/*.{ts,tsx,js,jsx} : when triggering a task from inside another task, use `y...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : When triggering a task from inside another task, use `yourTask.trigger`, `yourTask.batchTrigger`, `yourTask.triggerAndWait`, `yourTask.batchTriggerAndWait`, `batch.triggerAndWait`, `batch.triggerByTask`, or `batch.triggerByTaskAndWait` as shown.

Applied to files:

  • .changeset/five-nails-whisper.md
📚 Learning: applies to **/trigger/**/*.{ts,tsx,js,jsx} : when triggering a task from backend code, use `tasks.tr...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : When triggering a task from backend code, use `tasks.trigger`, `tasks.batchTrigger`, or `tasks.triggerAndPoll` as shown in the examples.

Applied to files:

  • .changeset/five-nails-whisper.md
📚 Learning: applies to **/trigger/**/*.{ts,tsx,js,jsx} : you must `export` every task, including subtasks, in tr...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : You MUST `export` every task, including subtasks, in Trigger.dev task files.

Applied to files:

  • .changeset/five-nails-whisper.md
📚 Learning: applies to apps/webapp/**/*.{ts,tsx} : when importing from `@trigger.dev/core` in the webapp, never ...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/webapp.mdc:0-0
Timestamp: 2025-07-18T17:49:47.180Z
Learning: Applies to apps/webapp/**/*.{ts,tsx} : When importing from `@trigger.dev/core` in the webapp, never import from the root `@trigger.dev/core` path; always use one of the subpath exports as defined in the package's package.json.

Applied to files:

  • .changeset/five-nails-whisper.md
📚 Learning: applies to **/trigger/**/*.{ts,tsx,js,jsx} : when logging in tasks, use the `logger` api (`logger.de...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : When logging in tasks, use the `logger` API (`logger.debug`, `logger.log`, `logger.info`, `logger.warn`, `logger.error`) as shown.

Applied to files:

  • packages/core/src/v3/otel/tracingSDK.ts
📚 Learning: applies to trigger.config.ts : the `trigger.config.ts` file must use `defineconfig` from `@trigger.d...
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to trigger.config.ts : The `trigger.config.ts` file must use `defineConfig` from `@trigger.dev/sdk/v3` and follow the configuration structure shown.

Applied to files:

  • packages/core/src/v3/otel/tracingSDK.ts
🧬 Code Graph Analysis (1)
packages/core/src/v3/otel/tracingSDK.ts (5)
packages/core/src/v3/utils/getEnv.ts (1)
  • getEnvVar (11-13)
packages/core/src/v3/semanticInternalAttributes.ts (1)
  • SemanticInternalAttributes (1-64)
packages/core/src/v3/task-context-api.ts (1)
  • taskContext (5-5)
packages/core/src/v3/taskContext/otelProcessors.ts (1)
  • TaskContextSpanProcessor (8-46)
packages/core/src/v3/trace-context-api.ts (1)
  • traceContext (5-5)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (25)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (7, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (3, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (6, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (8, 10)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (5, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (6, 8)
  • GitHub Check: units / packages / 🧪 Unit Tests: Packages (1, 1)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (2, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (4, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (10, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (1, 10)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (8, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (5, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (9, 10)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - npm)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (7, 10)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (4, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (1, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (3, 10)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (2, 10)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - pnpm)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (9)
packages/core/src/v3/otel/tracingSDK.ts (6)

103-123: Span processor array approach improves maintainability

The refactor to collect span processors in an array before passing to NodeTracerProvider constructor is cleaner than the previous approach of adding processors post-creation. The configuration logic for batch vs simple processors is consistent.

Also applies to: 129-150


125-126: External trace context integration implemented correctly

The integration of external trace context via traceContext.getExternalTraceContext() and its propagation to wrapper classes is well-designed. The fallback to generated externalTraceId when no external context exists maintains backward compatibility.

Also applies to: 132-133, 147-148, 194-198, 211-215


152-164: Trace provider instantiation refactor improves clarity

Moving span processor configuration to the constructor via the spanProcessors array eliminates the need for post-creation processor registration, making the initialization flow more explicit and easier to follow.


220-228: Log provider instantiation follows same pattern

The log provider refactor mirrors the span provider approach consistently, using constructor-based processor injection rather than post-creation addition.


300-322: Attempt span logic is complex but correct

The special handling for attempt spans to update parent span context with external trace context details (including tracestate) is sophisticated. The logic correctly preserves trace flags and handles optional trace state.


284-288: External span wrapper type safety needs improvement

The externalTraceContext parameter allows undefined but the logic assumes certain properties exist. The type definition should be more specific to prevent runtime errors.

Improve type safety for external trace context:

-    private externalTraceContext:
-      | { traceId: string; spanId: string; tracestate?: string }
-      | undefined
+    private externalTraceContext: {
+      traceId: string;
+      spanId: string;
+      tracestate?: string;
+    } | null

Add proper null checks in the transformSpan method:

-    if (isAttemptSpan && this.externalTraceContext) {
+    if (isAttemptSpan && this.externalTraceContext !== null) {

Also applies to: 296-322

⛔ Skipped due to learnings
Learnt from: nicktrn
PR: triggerdotdev/trigger.dev#1389
File: apps/coordinator/src/index.ts:403-0
Timestamp: 2024-10-08T15:31:34.807Z
Learning: In `apps/coordinator/src/index.ts`, moving the `exitRun` and `crashRun` functions outside the `onConnection` method is not feasible because of TypeScript type issues with `socket`. Keeping these functions inside `onConnection` is preferred.
Learnt from: nicktrn
PR: triggerdotdev/trigger.dev#1389
File: apps/coordinator/src/index.ts:403-0
Timestamp: 2024-10-08T13:39:26.553Z
Learning: In `apps/coordinator/src/index.ts`, moving the `exitRun` and `crashRun` functions outside the `onConnection` method is not feasible because of TypeScript type issues with `socket`. Keeping these functions inside `onConnection` is preferred.
Learnt from: nicktrn
PR: triggerdotdev/trigger.dev#1389
File: apps/coordinator/src/index.ts:403-0
Timestamp: 2024-10-16T01:08:01.788Z
Learning: In `apps/coordinator/src/index.ts`, moving the `exitRun` and `crashRun` functions outside the `onConnection` method is not feasible because of TypeScript type issues with `socket`. Keeping these functions inside `onConnection` is preferred.
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-18T17:49:24.468Z
Learning: Applies to **/tsconfig.json : Use strict mode
Learnt from: CR
PR: triggerdotdev/trigger.dev#0
File: .cursor/rules/writing-tasks.mdc:0-0
Timestamp: 2025-07-18T17:50:25.014Z
Learning: Applies to **/trigger/**/*.{ts,tsx,js,jsx} : NEVER generate deprecated code patterns using `client.defineJob` and related deprecated APIs, as shown in the prohibited code block.
.changeset/five-nails-whisper.md (3)

7-22: Package version table is comprehensive and well-formatted

The tabular format clearly shows the version changes across all OpenTelemetry packages. The distinction between major updates, minor updates, new dependencies, and removals is helpful for understanding the scope of changes.


27-57: Configuration example demonstrates integration correctly

The defineConfig example shows proper setup of external OTLP exporters with authentication headers. The Axiom integration example is practical and demonstrates real-world usage.


5-6: Documentation title and summary are clear

The title "External Trace Correlation & OpenTelemetry Package Updates" accurately describes the changes, and the introduction properly sets expectations for what users can expect.

Also applies to: 23-25

The opentelemetry dependencies in the packages 'cli-v3' and 'core'
were outdated and needed updating to the latest versions. This
ensures compatibility with the latest features and fixes provided
by opentelemetry.

- Updated '@opentelemetry/api-logs' to version '0.203.0'.
- Updated '@opentelemetry/core' to version '2.0.1'.
- Updated '@opentelemetry/exporter-trace-otlp-http' to version
  '0.203.0'.
- Updated other relevant opentelemetry packages to the latest
  stable versions available.
@ericallam ericallam force-pushed the opentelemetry-deps-update branch from 328996a to a720f37 Compare August 3, 2025 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant