Skip to content

Conversation

@nicktrn
Copy link
Collaborator

@nicktrn nicktrn commented Aug 29, 2025

Also, the runlock span now takes additional attributes

@changeset-bot
Copy link

changeset-bot bot commented Aug 29, 2025

⚠️ No Changeset found

Latest commit: 892575e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 29, 2025

Walkthrough

  • Adds asyncResourceAttributes.server.ts to resolve AWS ECS metadata (task/container) via ECS_CONTAINER_METADATA_URI_V4, validate with Zod, map to OpenTelemetry ResourceAttributes, cache results, and return empty on errors.
  • Updates tracer.server.ts to centralize Resource creation in getResource(), including host name and async attributes; applies to tracer, logger, and meter providers.
  • Modifies RunLocker.lock signature to accept optional tracing attributes and merge them into span attributes.
  • Extends dequeueFromWorkerQueue return path with an additional object containing snake_case telemetry fields derived from the dequeued message context.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/async-resource-attrs

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.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbit in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbit 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:
    • @coderabbit gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbit read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbit help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbit ignore or @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbit summary or @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbit or @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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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: 2

🧹 Nitpick comments (7)
internal-packages/run-engine/src/engine/locking.ts (1)

195-196: Avoid letting caller attributes clobber canonical fields

Right now, user-supplied attributes can override name/resources/timeout. Prefer canonical fields to win, or namespace caller attrs (e.g., custom.*).

Apply this diff to change precedence:

-        attributes: { name, resources, timeout: this.duration, ...attributes },
+        attributes: { ...(attributes ?? {}), name, resources, timeout: this.duration },
internal-packages/run-engine/src/engine/systems/dequeueSystem.ts (1)

576-586: Consider OTel naming convention for attributes

Dotted, namespaced keys (e.g., trigger.run.id) are easier to query than snake_case custom keys.

Example:

-              run_id: runId,
+              "trigger.run.id": runId,
apps/webapp/app/v3/telemetry/asyncResourceAttributes.server.ts (4)

167-176: Handle image digests and multi-colon names

Image can be repo@sha256:..., or have multiple colons. Safer parsing:

-  if (containerData.Image) {
-    const [name, tag] = containerData.Image.split(":");
+  if (containerData.Image) {
+    // prefer tag after last colon if not using digest form
+    const atIndex = containerData.Image.indexOf("@");
+    const imageRef = atIndex >= 0 ? containerData.Image.slice(0, atIndex) : containerData.Image;
+    const lastColon = imageRef.lastIndexOf(":");
+    const name = lastColon >= 0 ? imageRef.slice(0, lastColon) : imageRef;
+    const tag = lastColon >= 0 ? imageRef.slice(lastColon + 1) : undefined;

237-239: Reduce log noise: downgrade to debug

Fetching ECS metadata every boot can spam logs.

-  logger.info("🔦 Fetched ECS metadata", { attributes });
+  logger.debug("🔦 Fetched ECS metadata", { attributes });

54-56: Optional: coalesce concurrent fetches

Prevent duplicate network calls on first access by memoizing the in-flight Promise.

Add alongside ecsMetadataCache:

let ecsMetadataPromise: Promise<ResourceAttributes> | null = null;

Then in fetchECSMetadata():

if (ecsMetadataCache) return ecsMetadataCache;
if (ecsMetadataPromise) return ecsMetadataPromise;
ecsMetadataPromise = (async () => {
  // existing body that computes `attributes`
  ecsMetadataCache = attributes;
  ecsMetadataPromise = null;
  return attributes;
})();
return ecsMetadataPromise;

Also applies to: 207-241


232-235: Schema additions needed in env.server.ts

To support the above, add optional fields to EnvironmentSchema:

Add to apps/webapp/app/env.server.ts:

AWS_REGION: z.string().optional(),
AWS_DEFAULT_REGION: z.string().optional(),
ECS_CONTAINER_METADATA_URI_V4: z.string().optional(),

Want me to open a follow-up PR for this?

Also applies to: 255-263

apps/webapp/app/v3/tracer.server.ts (1)

203-204: Reuse a single Resource instance to avoid divergence and extra async work

Create it once inside setupTelemetry and pass to all providers.

Apply these diffs:

-  const provider = new NodeTracerProvider({
-    forceFlushTimeoutMillis: 15_000,
-    resource: getResource(),
+  const resource = getResource();
+  const provider = new NodeTracerProvider({
+    forceFlushTimeoutMillis: 15_000,
+    resource,
-    const loggerProvider = new LoggerProvider({
-      resource: getResource(),
+    const loggerProvider = new LoggerProvider({
+      resource,
-  const meterProvider = new MeterProvider({
-    resource: getResource(),
+  const meterProvider = new MeterProvider({
+    resource,

Also applies to: 253-254, 308-309

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between b0b0df6 and 892575e.

📒 Files selected for processing (4)
  • apps/webapp/app/v3/telemetry/asyncResourceAttributes.server.ts (1 hunks)
  • apps/webapp/app/v3/tracer.server.ts (6 hunks)
  • internal-packages/run-engine/src/engine/locking.ts (2 hunks)
  • internal-packages/run-engine/src/engine/systems/dequeueSystem.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{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:

  • internal-packages/run-engine/src/engine/locking.ts
  • apps/webapp/app/v3/telemetry/asyncResourceAttributes.server.ts
  • apps/webapp/app/v3/tracer.server.ts
  • internal-packages/run-engine/src/engine/systems/dequeueSystem.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:

  • apps/webapp/app/v3/telemetry/asyncResourceAttributes.server.ts
  • apps/webapp/app/v3/tracer.server.ts
apps/webapp/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/webapp.mdc)

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.
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.

Files:

  • apps/webapp/app/v3/telemetry/asyncResourceAttributes.server.ts
  • apps/webapp/app/v3/tracer.server.ts
🧬 Code graph analysis (4)
internal-packages/run-engine/src/engine/locking.ts (2)
internal-packages/run-engine/src/run-queue/index.ts (2)
  • T (997-1026)
  • name (272-274)
internal-packages/tracing/src/index.ts (1)
  • Attributes (15-15)
apps/webapp/app/v3/telemetry/asyncResourceAttributes.server.ts (1)
apps/webapp/app/v3/tracer.server.ts (1)
  • logger (104-109)
apps/webapp/app/v3/tracer.server.ts (2)
apps/webapp/app/env.server.ts (1)
  • env (1099-1099)
apps/webapp/app/v3/telemetry/asyncResourceAttributes.server.ts (1)
  • getAsyncResourceAttributes (255-263)
internal-packages/run-engine/src/engine/systems/dequeueSystem.ts (1)
internal-packages/run-engine/src/run-queue/index.ts (6)
  • message (1395-1443)
  • message (1692-1747)
  • message (1749-1797)
  • message (1799-1827)
  • message (1848-1861)
  • workerQueue (1557-1690)
⏰ 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 (5, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (7, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (8, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (4, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (1, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (1, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (2, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (8, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (2, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (3, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (4, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (5, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (6, 8)
  • GitHub Check: units / webapp / 🧪 Unit Tests: Webapp (7, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (6, 8)
  • GitHub Check: units / internal / 🧪 Unit Tests: Internal (3, 8)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (ubuntu-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: units / packages / 🧪 Unit Tests: Packages (1, 1)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (4)
internal-packages/run-engine/src/engine/locking.ts (1)

147-152: Nice: lock() accepts span attributes without breaking callers

Optional attributes on the 4th param keeps the API backward-compatible and enables richer spans.

Also applies to: 195-196

internal-packages/run-engine/src/engine/systems/dequeueSystem.ts (2)

146-154: Good: useful span context for dequeue operation

Run, org, env, queue, consumer, and blocking flags on the span help root-cause latency.


576-586: blocking_pop default matches run-queue
No changes required.

apps/webapp/app/v3/tracer.server.ts (1)

174-183: LGTM: centralized Resource with host name and async attributes

Good consolidation and use of async resource enrichment.

@nicktrn nicktrn merged commit 73e7378 into main Aug 29, 2025
31 checks passed
@nicktrn nicktrn deleted the feat/async-resource-attrs branch August 29, 2025 10:05
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.

3 participants