Skip to content

Conversation

@nina-kollman
Copy link
Contributor

@nina-kollman nina-kollman commented Sep 21, 2025

Important

Adds GEN_AI_AGENT_NAME span attribute for agent context in tracing, with tests and HAR recordings for validation.

  • Behavior:
    • Adds GEN_AI_AGENT_NAME attribute to SpanAttributes in SemanticAttributes.ts.
    • Updates withEntity() in decorators.ts to set GEN_AI_AGENT_NAME for agent spans.
    • Updates withVectorDBCall() and withLLMCall() in manual.ts to set GEN_AI_AGENT_NAME if agent context is active.
    • Updates onSpanStart() in span-processor.ts to set GEN_AI_AGENT_NAME for active agent context.
  • Tests:
    • Adds agent_decorator.test.ts to test agent spans, decorator usage, and manual LLM instrumentation.
    • Includes HAR recordings for OpenAI interactions in recordings/Test-Agent-Decorator_2969879889/.
  • Misc:
    • Renames withWorkflow to withAgent in sample_vercel_ai_tools.ts.

This description was created by Ellipsis for 732c0b2. You can customize this summary. It will automatically update as commits are pushed.


Summary by CodeRabbit

  • New Features

    • Spans now include an agent name attribute (gen_ai.agent.name) for agent, LLM, and Vector DB calls, improving trace filtering and analysis across workflows and instrumentation approaches.
  • Tests

    • Added comprehensive tests validating agent spans, decorator and manual instrumentation, and agent-name propagation, plus HAR recordings of OpenAI interactions.

@coderabbitai
Copy link

coderabbitai bot commented Sep 21, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds a new span attribute gen_ai.agent.name and a tracing context key AGENT_NAME_KEY; propagates agent name into spans in decorators, manual instrumentation, and the span processor. Updates a sample to use withAgent, adds tests for agent flows, and includes HAR recordings.

Changes

Cohort / File(s) Summary
Semantic Conventions
packages/ai-semantic-conventions/src/SemanticAttributes.ts
Adds SpanAttributes.GEN_AI_AGENT_NAME = "gen_ai.agent.name".
Tracing Context Keys
packages/traceloop-sdk/src/lib/tracing/tracing.ts
Exports AGENT_NAME_KEY = createContextKey("agent_name").
Agent Name Propagation in Tracing
packages/traceloop-sdk/src/lib/tracing/decorators.ts, packages/traceloop-sdk/src/lib/tracing/manual.ts, packages/traceloop-sdk/src/lib/tracing/span-processor.ts
Read/writes AGENT_NAME_KEY in entity/context handling and set SpanAttributes.GEN_AI_AGENT_NAME on started spans (agent, LLM, vector DB); adjust span start/context usage to propagate agent name.
Sample App Update
packages/sample-app/src/sample_vercel_ai_tools.ts
Replaces traceloop.withWorkflow with traceloop.withAgent in planTrip.
Tests
packages/traceloop-sdk/test/agent_decorator.test.ts
Adds tests covering withAgent, decorator syntax, and manual LLM instrumentation; asserts agent-name propagation, span attributes, and parent-child relationships.
Recordings (HAR)
packages/traceloop-sdk/recordings/Test-Agent-Decorator_2969879889/.../recording.har
Adds three HAR fixture recordings used by the new tests (OpenAI chat completions).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor App
  participant Traceloop as Traceloop SDK
  participant Ctx as Tracing Context
  participant SpanProc as Span Processor
  participant OpenAI as OpenAI API

  App->>Traceloop: withAgent("plan_trip.agent"){...}
  Traceloop->>Ctx: set AGENT_NAME_KEY="plan_trip.agent"
  Traceloop->>SpanProc: start agent span
  Note right of SpanProc #ffeead: onSpanStart reads AGENT_NAME_KEY\nsets gen_ai.agent.name attribute
  SpanProc-->Traceloop: agent span started

  App->>Traceloop: withLLMCall(...) -> start LLM span
  Traceloop->>SpanProc: start llm span (uses active context)
  Note right of SpanProc #d0f0c0: reads AGENT_NAME_KEY from context\nsets gen_ai.agent.name on LLM span
  Traceloop->>OpenAI: POST /v1/chat/completions
  OpenAI-->>Traceloop: 200 OK
  Traceloop-->>App: result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • avivhalfon
  • galkleinman

Poem

I hop through traces, whiskers tuned to name,
An agent's whisper nested in each span's frame.
Context burrows softly, attributes claim,
gen_ai.agent.name now sings in the game. 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "fix(agent): Add gen_ai.agent.name span attribute" succinctly and accurately describes the primary change—adding the gen_ai.agent.name span attribute and associated tracing updates. It aligns with the PR objectives and the file-level changes (SemanticAttributes, tracing context key, instrumentation, and tests). The conventional prefix and concise wording make the main intent clear to reviewers scanning history.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch nk/gen_ai_agent

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • 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 b22a9a6 and 732c0b2.

📒 Files selected for processing (3)
  • packages/ai-semantic-conventions/src/SemanticAttributes.ts (1 hunks)
  • packages/traceloop-sdk/src/lib/tracing/decorators.ts (3 hunks)
  • packages/traceloop-sdk/src/lib/tracing/manual.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/traceloop-sdk/src/lib/tracing/manual.ts
  • packages/ai-semantic-conventions/src/SemanticAttributes.ts
🧰 Additional context used
📓 Path-based instructions (2)
packages/{instrumentation-*,traceloop-sdk}/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Import AI/LLM semantic attribute constants from @traceloop/ai-semantic-conventions rather than hardcoding strings

Files:

  • packages/traceloop-sdk/src/lib/tracing/decorators.ts
packages/traceloop-sdk/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

packages/traceloop-sdk/**/*.{ts,tsx}: Use the provided decorators (@workflow, @task, @agent) for workflow/task/agent spans instead of re-implementing them
For manual LLM operations, use trace.withLLMSpan from @traceloop/node-server-sdk

Files:

  • packages/traceloop-sdk/src/lib/tracing/decorators.ts
🧠 Learnings (4)
📚 Learning: 2025-08-24T22:08:07.023Z
Learnt from: CR
PR: traceloop/openllmetry-js#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-24T22:08:07.023Z
Learning: Applies to packages/traceloop-sdk/**/*.{ts,tsx} : Use the provided decorators (workflow, task, agent) for workflow/task/agent spans instead of re-implementing them

Applied to files:

  • packages/traceloop-sdk/src/lib/tracing/decorators.ts
📚 Learning: 2025-08-24T22:08:07.023Z
Learnt from: CR
PR: traceloop/openllmetry-js#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-24T22:08:07.023Z
Learning: Applies to packages/{instrumentation-*,traceloop-sdk}/**/*.{ts,tsx} : Import AI/LLM semantic attribute constants from traceloop/ai-semantic-conventions rather than hardcoding strings

Applied to files:

  • packages/traceloop-sdk/src/lib/tracing/decorators.ts
📚 Learning: 2025-08-24T22:08:07.023Z
Learnt from: CR
PR: traceloop/openllmetry-js#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-24T22:08:07.023Z
Learning: Applies to packages/ai-semantic-conventions/src/SemanticAttributes.ts : Define all AI/LLM span attribute constants in packages/ai-semantic-conventions/src/SemanticAttributes.ts

Applied to files:

  • packages/traceloop-sdk/src/lib/tracing/decorators.ts
📚 Learning: 2025-08-24T22:08:07.023Z
Learnt from: CR
PR: traceloop/openllmetry-js#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-24T22:08:07.023Z
Learning: Applies to packages/instrumentation-*/**/*.{ts,tsx} : Instrumentations must create spans with appropriate AI/LLM semantic attributes for calls they wrap

Applied to files:

  • packages/traceloop-sdk/src/lib/tracing/decorators.ts
🧬 Code graph analysis (1)
packages/traceloop-sdk/src/lib/tracing/decorators.ts (2)
packages/traceloop-sdk/src/lib/tracing/tracing.ts (1)
  • AGENT_NAME_KEY (7-7)
packages/ai-semantic-conventions/src/SemanticAttributes.ts (1)
  • SpanAttributes (17-63)
🔇 Additional comments (3)
packages/traceloop-sdk/src/lib/tracing/decorators.ts (3)

4-4: Importing AGENT_NAME_KEY from tracing — LGTM

Correct key source; aligns with our context management.


53-55: Agent context propagation is correctly scoped

Setting AGENT_NAME_KEY only for AGENT spans is right; downstream spans created under this context will inherit it.


102-110: Using semantic constant for gen_ai.agent.name — LGTM; consider dedup via helper

Looks correct and uses SpanAttributes.GEN_AI_AGENT_NAME (resolves prior hardcoded literal concern). To avoid duplication across decorators.ts, manual.ts, and span-processor.ts, extract a small helper and reuse.

Apply this diff locally to simplify the block:

-        // Set agent name on all spans when there's an active agent context
-        const agentName = entityContext.getValue(AGENT_NAME_KEY);
-        if (agentName) {
-          span.setAttribute(
-            SpanAttributes.GEN_AI_AGENT_NAME,
-            agentName as string,
-          );
-        }
+        // Set agent name on all spans when there's an active agent context
+        applyAgentNameAttribute(span, entityContext);

Add this helper in tracing.ts (or a shared tracing utils module) and import it here:

// tracing.ts
import { Context, Span } from "@opentelemetry/api";
import { SpanAttributes } from "@traceloop/ai-semantic-conventions";
export const AGENT_NAME_KEY = createContextKey("agent_name");

export function applyAgentNameAttribute(span: Span, ctx: Context) {
  const agentName = ctx.getValue(AGENT_NAME_KEY);
  if (agentName) {
    span.setAttribute(SpanAttributes.GEN_AI_AGENT_NAME, agentName as string);
  }
}

And update decorators.ts imports accordingly:

import { AGENT_NAME_KEY, getEntityPath, getTracer, WORKFLOW_NAME_KEY, ASSOCATION_PROPERTIES_KEY, applyAgentNameAttribute } from "./tracing";

Run to ensure no remaining literals and consistent constant usage:

#!/bin/bash
set -euo pipefail

echo "Search for hardcoded gen_ai.agent.name literals:"
rg -nP -C2 '"gen_ai\.agent\.name"' || true

echo -e "\nCheck for consistent constant usage:"
rg -nP -C2 '\bSpanAttributes\.(GEN_AI_AGENT_NAME|LLM_AGENT_NAME)\b'

echo -e "\nVerify all sites set agent attribute via helper (post-refactor expected):"
rg -nP -C2 'applyAgentNameAttribute\s*\('

echo -e "\nLocate all AGENT_NAME_KEY usages:"
rg -nP -C2 '\bAGENT_NAME_KEY\b'

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Caution

Changes requested ❌

Reviewed everything up to acdc019 in 1 minute and 43 seconds. Click for details.
  • Reviewed 144 lines of code in 6 files
  • Skipped 0 files when reviewing.
  • Skipped posting 6 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. packages/ai-semantic-conventions/src/SemanticAttributes.ts:30
  • Draft comment:
    LLM_AGENT_NAME has been added appropriately to the semantic attributes. This aligns with the naming conventions for agent spans.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
2. packages/sample-app/src/sample_vercel_ai_tools.ts:116
  • Draft comment:
    planTrip now uses withAgent instead of withWorkflow. This change correctly reflects that this function is acting as an agent.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
3. packages/traceloop-sdk/src/lib/tracing/decorators.ts:104
  • Draft comment:
    Consider replacing the literal string 'gen_ai.agent.name' with the constant SpanAttributes.LLM_AGENT_NAME to ensure consistency.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50% The suggestion to use a constant makes sense from a code quality perspective to ensure consistency and avoid typos. However, I don't see clear evidence that SpanAttributes.LLM_AGENT_NAME actually exists or that it contains the same value. Without being able to verify the constant exists and has the correct value, this suggestion could introduce bugs. I could be wrong about the constant not existing - it may be a well-known standard that I'm not aware of. The suggestion to use constants is generally good practice. While using constants is good practice, we need to be certain the constant exists and has the correct value before suggesting its use. The risk of introducing bugs outweighs the benefit here. Delete this comment since we don't have strong evidence that SpanAttributes.LLM_AGENT_NAME exists or contains the correct value.
4. packages/traceloop-sdk/src/lib/tracing/manual.ts:176
  • Draft comment:
    The agent name is correctly captured from context and set in both withVectorDBCall and withLLMCall. The implementation looks consistent.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
5. packages/traceloop-sdk/src/lib/tracing/tracing.ts:7
  • Draft comment:
    AGENT_NAME_KEY is defined correctly with createContextKey and matches the established naming convention.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
6. packages/traceloop-sdk/src/lib/tracing/decorators.ts:5
  • Draft comment:
    Typo notice: The identifier 'ASSOCATION_PROPERTIES_KEY' appears to have a misspelling. Consider changing it to 'ASSOCIATION_PROPERTIES_KEY' if that is the intended spelling.
  • Reason this comment was not posted:
    Comment was on unchanged code.

Workflow ID: wflow_RySnYvdbphc4K5KY

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

Copy link

@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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • 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 c1ee4af and acdc019.

📒 Files selected for processing (6)
  • packages/ai-semantic-conventions/src/SemanticAttributes.ts (1 hunks)
  • packages/sample-app/src/sample_vercel_ai_tools.ts (1 hunks)
  • packages/traceloop-sdk/src/lib/tracing/decorators.ts (3 hunks)
  • packages/traceloop-sdk/src/lib/tracing/manual.ts (3 hunks)
  • packages/traceloop-sdk/src/lib/tracing/span-processor.ts (2 hunks)
  • packages/traceloop-sdk/src/lib/tracing/tracing.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
packages/{instrumentation-*,traceloop-sdk}/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Import AI/LLM semantic attribute constants from @traceloop/ai-semantic-conventions rather than hardcoding strings

Files:

  • packages/traceloop-sdk/src/lib/tracing/tracing.ts
  • packages/traceloop-sdk/src/lib/tracing/manual.ts
  • packages/traceloop-sdk/src/lib/tracing/span-processor.ts
  • packages/traceloop-sdk/src/lib/tracing/decorators.ts
packages/traceloop-sdk/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

packages/traceloop-sdk/**/*.{ts,tsx}: Use the provided decorators (@workflow, @task, @agent) for workflow/task/agent spans instead of re-implementing them
For manual LLM operations, use trace.withLLMSpan from @traceloop/node-server-sdk

Files:

  • packages/traceloop-sdk/src/lib/tracing/tracing.ts
  • packages/traceloop-sdk/src/lib/tracing/manual.ts
  • packages/traceloop-sdk/src/lib/tracing/span-processor.ts
  • packages/traceloop-sdk/src/lib/tracing/decorators.ts
packages/ai-semantic-conventions/src/SemanticAttributes.ts

📄 CodeRabbit inference engine (CLAUDE.md)

Define all AI/LLM span attribute constants in packages/ai-semantic-conventions/src/SemanticAttributes.ts

Files:

  • packages/ai-semantic-conventions/src/SemanticAttributes.ts
🧠 Learnings (5)
📚 Learning: 2025-08-24T22:08:07.023Z
Learnt from: CR
PR: traceloop/openllmetry-js#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-24T22:08:07.023Z
Learning: Applies to packages/{instrumentation-*,traceloop-sdk}/**/*.{ts,tsx} : Import AI/LLM semantic attribute constants from traceloop/ai-semantic-conventions rather than hardcoding strings

Applied to files:

  • packages/traceloop-sdk/src/lib/tracing/tracing.ts
  • packages/ai-semantic-conventions/src/SemanticAttributes.ts
  • packages/traceloop-sdk/src/lib/tracing/manual.ts
  • packages/sample-app/src/sample_vercel_ai_tools.ts
  • packages/traceloop-sdk/src/lib/tracing/span-processor.ts
  • packages/traceloop-sdk/src/lib/tracing/decorators.ts
📚 Learning: 2025-08-24T22:08:07.023Z
Learnt from: CR
PR: traceloop/openllmetry-js#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-24T22:08:07.023Z
Learning: Applies to packages/ai-semantic-conventions/src/SemanticAttributes.ts : Define all AI/LLM span attribute constants in packages/ai-semantic-conventions/src/SemanticAttributes.ts

Applied to files:

  • packages/ai-semantic-conventions/src/SemanticAttributes.ts
  • packages/traceloop-sdk/src/lib/tracing/span-processor.ts
📚 Learning: 2025-08-24T22:08:07.023Z
Learnt from: CR
PR: traceloop/openllmetry-js#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-24T22:08:07.023Z
Learning: Applies to packages/instrumentation-*/**/*.{ts,tsx} : Instrumentations must create spans with appropriate AI/LLM semantic attributes for calls they wrap

Applied to files:

  • packages/ai-semantic-conventions/src/SemanticAttributes.ts
  • packages/traceloop-sdk/src/lib/tracing/manual.ts
📚 Learning: 2025-08-24T22:08:07.023Z
Learnt from: CR
PR: traceloop/openllmetry-js#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-24T22:08:07.023Z
Learning: Applies to packages/traceloop-sdk/**/*.{ts,tsx} : For manual LLM operations, use trace.withLLMSpan from traceloop/node-server-sdk

Applied to files:

  • packages/traceloop-sdk/src/lib/tracing/manual.ts
📚 Learning: 2025-08-24T22:08:07.023Z
Learnt from: CR
PR: traceloop/openllmetry-js#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-24T22:08:07.023Z
Learning: Applies to packages/traceloop-sdk/**/*.{ts,tsx} : Use the provided decorators (workflow, task, agent) for workflow/task/agent spans instead of re-implementing them

Applied to files:

  • packages/traceloop-sdk/src/lib/tracing/manual.ts
  • packages/sample-app/src/sample_vercel_ai_tools.ts
  • packages/traceloop-sdk/src/lib/tracing/span-processor.ts
  • packages/traceloop-sdk/src/lib/tracing/decorators.ts
🧬 Code graph analysis (3)
packages/traceloop-sdk/src/lib/tracing/manual.ts (2)
packages/traceloop-sdk/src/lib/tracing/tracing.ts (2)
  • AGENT_NAME_KEY (7-7)
  • getTracer (12-14)
packages/ai-semantic-conventions/src/SemanticAttributes.ts (1)
  • SpanAttributes (17-62)
packages/traceloop-sdk/src/lib/tracing/span-processor.ts (2)
packages/traceloop-sdk/src/lib/tracing/tracing.ts (1)
  • AGENT_NAME_KEY (7-7)
packages/ai-semantic-conventions/src/SemanticAttributes.ts (1)
  • SpanAttributes (17-62)
packages/traceloop-sdk/src/lib/tracing/decorators.ts (1)
packages/traceloop-sdk/src/lib/tracing/tracing.ts (1)
  • AGENT_NAME_KEY (7-7)
🪛 GitHub Actions: CI
packages/traceloop-sdk/src/lib/tracing/span-processor.ts

[error] 1-1: Prettier formatting check failed. The command 'pnpm prettier --check .' exited with code 1. Run 'pnpm prettier --write .' to fix code style issues in this file.

🔇 Additional comments (10)
packages/traceloop-sdk/src/lib/tracing/tracing.ts (1)

7-7: LGTM - Agent context key added successfully.

The addition of AGENT_NAME_KEY follows the existing pattern and properly extends the public context API for agent tracing support.

packages/ai-semantic-conventions/src/SemanticAttributes.ts (2)

30-30: LGTM - Semantic attribute follows convention.

The LLM_AGENT_NAME attribute with value "gen_ai.agent.name" properly follows the GenAI semantic conventions and aligns with the agent tracing infrastructure being introduced.


30-30: ✅ Verified - Follows OpenTelemetry GenAI semantic conventions.

The gen_ai.agent.name attribute is defined in the official OpenTelemetry GenAI semantic conventions as "Human-readable name of the GenAI agent provided by the application" with examples like "Math Tutor; Fiction Writer". The implementation correctly follows the standard.

packages/traceloop-sdk/src/lib/tracing/decorators.ts (2)

4-4: LGTM - Import follows established pattern.

The import of AGENT_NAME_KEY correctly follows the established pattern for context keys in this file.


53-56: LGTM - Agent context setup is correct.

The logic properly sets the agent name in the context for AGENT type entities, following the same pattern used for workflow names.

packages/sample-app/src/sample_vercel_ai_tools.ts (1)

117-117: LGTM - Switch to agent decorator is appropriate.

The change from withWorkflow to withAgent aligns with the new agent tracing capabilities and maintains the same function signature and behavior.

packages/traceloop-sdk/src/lib/tracing/span-processor.ts (1)

14-14: LGTM - Import follows established pattern.

The import of AGENT_NAME_KEY is consistent with the other context key imports.

packages/traceloop-sdk/src/lib/tracing/manual.ts (3)

2-2: LGTM - Import follows established pattern.

The import of AGENT_NAME_KEY is consistent with other context key imports in the file.


148-153: LGTM - Agent name propagation implemented correctly.

The agent name is properly retrieved from the entity context and set on the span using the correct semantic attribute constant.


171-181: LGTM - Consistent agent name propagation.

The changes properly propagate agent name to LLM call spans and use consistent context handling throughout.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed a8d41ef in 29 seconds. Click for details.
  • Reviewed 30 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. packages/traceloop-sdk/src/lib/tracing/decorators.ts:104
  • Draft comment:
    Good change: using SpanAttributes.LLM_AGENT_NAME instead of a hardcoded string improves consistency. Ensure that the constant is correctly defined and documented in the semantic conventions.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50% The comment starts with a positive note about the change, which is not necessary. The second part of the comment asks the author to ensure that the constant is correctly defined and documented, which is not allowed according to the rules. The comment does not provide a specific suggestion or point out a specific issue with the code.
2. packages/traceloop-sdk/src/lib/tracing/span-processor.ts:146
  • Draft comment:
    Removal of debug logging for agentName cleans up the output. Confirm no vital debugging info is lost.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50% The comment is asking the PR author to confirm that no vital debugging information is lost, which is against the rules. It does not provide a specific suggestion or point out a clear issue with the code.

Workflow ID: wflow_0FiIunuwNNa15YFT

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

Copy link

@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: 1

🧹 Nitpick comments (4)
packages/traceloop-sdk/test/agent_decorator.test.ts (4)

40-56: Gate Polly logging to keep CI noise down

Set logging based on env and default to false in CI.

-    logging: true,
+    logging: process.env.POLLY_LOGGING === "true",

71-78: Broaden secret/header scrubbing before persisting recordings

Make the filter case-insensitive and scrub other sensitive headers.

-    server.any().on("beforePersist", (_req, recording) => {
-      recording.request.headers = recording.request.headers.filter(
-        ({ name }: { name: string }) => name !== "authorization",
-      );
-    });
+    server.any().on("beforePersist", (_req, recording) => {
+      const SENSITIVE = new Set(["authorization", "x-api-key", "openai-organization"]);
+      recording.request.headers = recording.request.headers.filter(
+        ({ name }: { name: string }) => !SENSITIVE.has(name.toLowerCase()),
+      );
+    });

101-150: Assert agent span also carries gen_ai.agent.name and parent/child relation

Strengthen the test to validate the new attribute on the agent span and the linkage to the chat span.

   assert.ok(agentSpan);
+  assert.strictEqual(
+    agentSpan.attributes[`${SpanAttributes.LLM_AGENT_NAME}`],
+    "plan_trip",
+  );
   assert.strictEqual(
     agentSpan.attributes[`${SpanAttributes.TRACELOOP_WORKFLOW_NAME}`],
     "plan_trip",
   );
@@
   assert.ok(chatSpan);
+  // Ensure chat span is a child of the agent span
+  assert.strictEqual(
+    chatSpan.parentSpanId,
+    agentSpan.spanContext.spanId,
+  );

170-209: Also assert agent name attribute and parent/child for decoration path

Mirror the assertions from the withAgent test.

   assert.ok(agentSpan);
+  assert.strictEqual(
+    agentSpan.attributes[`${SpanAttributes.LLM_AGENT_NAME}`],
+    "travel_planner",
+  );
@@
   assert.ok(chatSpan);
+  assert.strictEqual(
+    chatSpan.parentSpanId,
+    agentSpan.spanContext.spanId,
+  );
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • 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 acdc019 and a8d41ef.

📒 Files selected for processing (5)
  • packages/traceloop-sdk/recordings/Test-SDK-Decorators_847855269/should-create-spans-for-agents-using-decoration-syntax_1932039671/recording.har (1 hunks)
  • packages/traceloop-sdk/recordings/Test-SDK-Decorators_847855269/should-create-spans-for-agents-using-withAgent-syntax_3895564654/recording.har (1 hunks)
  • packages/traceloop-sdk/src/lib/tracing/decorators.ts (3 hunks)
  • packages/traceloop-sdk/src/lib/tracing/span-processor.ts (2 hunks)
  • packages/traceloop-sdk/test/agent_decorator.test.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/traceloop-sdk/recordings/Test-SDK-Decorators_847855269/should-create-spans-for-agents-using-decoration-syntax_1932039671/recording.har
  • packages/traceloop-sdk/recordings/Test-SDK-Decorators_847855269/should-create-spans-for-agents-using-withAgent-syntax_3895564654/recording.har
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/traceloop-sdk/src/lib/tracing/span-processor.ts
  • packages/traceloop-sdk/src/lib/tracing/decorators.ts
🧰 Additional context used
📓 Path-based instructions (2)
packages/{instrumentation-*,traceloop-sdk}/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Import AI/LLM semantic attribute constants from @traceloop/ai-semantic-conventions rather than hardcoding strings

Files:

  • packages/traceloop-sdk/test/agent_decorator.test.ts
packages/traceloop-sdk/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

packages/traceloop-sdk/**/*.{ts,tsx}: Use the provided decorators (@workflow, @task, @agent) for workflow/task/agent spans instead of re-implementing them
For manual LLM operations, use trace.withLLMSpan from @traceloop/node-server-sdk

Files:

  • packages/traceloop-sdk/test/agent_decorator.test.ts
🧠 Learnings (1)
📚 Learning: 2025-08-24T22:08:07.023Z
Learnt from: CR
PR: traceloop/openllmetry-js#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-24T22:08:07.023Z
Learning: Applies to packages/traceloop-sdk/**/*.{ts,tsx} : Use the provided decorators (workflow, task, agent) for workflow/task/agent spans instead of re-implementing them

Applied to files:

  • packages/traceloop-sdk/test/agent_decorator.test.ts
🧬 Code graph analysis (1)
packages/traceloop-sdk/test/agent_decorator.test.ts (2)
packages/traceloop-sdk/test/test-setup.ts (2)
  • getSharedExporter (37-39)
  • initializeSharedTraceloop (23-35)
packages/ai-semantic-conventions/src/SemanticAttributes.ts (1)
  • SpanAttributes (17-62)
🪛 GitHub Actions: CI
packages/traceloop-sdk/test/agent_decorator.test.ts

[warning] 1-1: Code style issues found in the above file. Run Prettier with --write to fix.

🔇 Additional comments (7)
packages/traceloop-sdk/test/agent_decorator.test.ts (7)

27-29: Good: semantic attributes imported from the right package

Using SpanAttributes from @traceloop/ai-semantic-conventions aligns with the guidelines.


33-36: Polly registration looks correct

Adapters and FS persister registration are in the right order.


58-69: Init sequence is solid

OpenAI is initialized after Polly; shared tracer init avoids cross-suite conflicts.


84-100: Nice: withAgent usage exercises association properties and child LLM span

Good coverage for the new agent context.


216-233: Manual LLM instrumentation path is exercised correctly

Good use of reportRequest/reportResponse and attribute checks; agent name propagation is validated.

Given the guidelines, confirm that using traceloop.withLLMCall here is intentional to test the SDK wrapper (vs. trace.withLLMSpan from @traceloop/node-server-sdk).


1-279: Prettier applied — formatting fixed

Ran Prettier on packages/traceloop-sdk/test/agent_decorator.test.ts; the file was formatted successfully and no further changes are required.


211-279: Keep parentSpanContext; use ReadableSpan property for spanContext

Do not replace completionSpan.parentSpanContext?.spanId with parentSpanId (parentSpanId was removed in recent OTel JS SDK); only change the spanContext accessor to the property form. (newreleases.io)

-    assert.strictEqual(
-      completionSpan.parentSpanContext?.spanId,
-      agentSpan.spanContext().spanId,
-    );
+    assert.strictEqual(
+      completionSpan.parentSpanContext?.spanId,
+      agentSpan.spanContext.spanId,
+    );

Likely an incorrect or invalid review comment.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed a11c838 in 27 seconds. Click for details.
  • Reviewed 22 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. packages/traceloop-sdk/test/agent_decorator.test.ts:168
  • Draft comment:
    Formatting change: The agentSpan assignment is now split over multiple lines, which improves readability. Ensure this matches the project's style guidelines.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
2. packages/traceloop-sdk/test/agent_decorator.test.ts:283
  • Draft comment:
    Trailing newline added at the end of the file. This adheres to best practices.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None

Workflow ID: wflow_rJLIiV9yuO8rkK09

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed 014b1a6 in 30 seconds. Click for details.
  • Reviewed 422 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. packages/traceloop-sdk/recordings/Test-SDK-Decorators_847855269/should-create-spans-for-agents-using-decoration-syntax_1932039671/recording.har:1
  • Draft comment:
    Removed outdated HAR recording for agent span tests. Ensure that updated recordings (with the new gen_ai.agent.name attribute) are in place to prevent test regressions.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
2. packages/traceloop-sdk/recordings/Test-SDK-Decorators_847855269/should-create-spans-for-agents-using-withAgent-syntax_3895564654/recording.har:1
  • Draft comment:
    Removed obsolete HAR recording for agent span tests (withAgent syntax). Verify that new test fixtures correctly capture the updated agent name attribute behavior.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.

Workflow ID: wflow_GXeN6vSZrehRfqFH

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

Copy link
Contributor

@galkleinman galkleinman left a comment

Choose a reason for hiding this comment

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

LGTM

LLM_RESPONSE_MODEL: "gen_ai.response.model",
LLM_USAGE_PROMPT_TOKENS: "gen_ai.usage.prompt_tokens",
LLM_USAGE_COMPLETION_TOKENS: "gen_ai.usage.completion_tokens",
LLM_AGENT_NAME: "gen_ai.agent.name",
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

if it is, i'll at least stick to their consts naming... LLM_AGENT_NAMe doesn't make a lot of sense imo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@galkleinman Yes it is, I will rename it

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed b22a9a6 in 35 seconds. Click for details.
  • Reviewed 101 lines of code in 5 files
  • Skipped 0 files when reviewing.
  • Skipped posting 5 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. packages/ai-semantic-conventions/src/SemanticAttributes.ts:31
  • Draft comment:
    Remove the extra blank line before GEN_AI_AGENT_NAME for cleaner formatting.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
2. packages/traceloop-sdk/src/lib/tracing/decorators.ts:105
  • Draft comment:
    Updated agent name attribute correctly to GEN_AI_AGENT_NAME; ensure related docs reflect this change.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
3. packages/traceloop-sdk/src/lib/tracing/manual.ts:149
  • Draft comment:
    Consistently update agent name attribute to GEN_AI_AGENT_NAME in manual instrumentation.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
4. packages/traceloop-sdk/src/lib/tracing/span-processor.ts:153
  • Draft comment:
    Using GEN_AI_AGENT_NAME for setting agent name in span processor is correct.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
5. packages/traceloop-sdk/test/agent_decorator.test.ts:129
  • Draft comment:
    Test assertions updated to use GEN_AI_AGENT_NAME are correct.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None

Workflow ID: wflow_eIRxnUSKn5x90CnD

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

Copy link

@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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/traceloop-sdk/src/lib/tracing/manual.ts (1)

143-153: Fix startActiveSpan options and ensure span ends on rejection

Second arg to startActiveSpan must be SpanOptions; currently passing attributes directly. Also end the span on promise rejection.

Apply this diff:

   return getTracer().startActiveSpan(
     `${vendor}.${type}`,
-    { [SpanAttributes.LLM_REQUEST_TYPE]: type },
+    { attributes: { [SpanAttributes.LLM_REQUEST_TYPE]: type } },
     entityContext,
     (span: Span) => {
       // Set agent name if there's an active agent context
       const agentName = entityContext.getValue(AGENT_NAME_KEY);
       if (agentName) {
         span.setAttribute(SpanAttributes.GEN_AI_AGENT_NAME, agentName as string);
       }

       const res = fn.apply(thisArg, [{ span: new VectorSpan(span) }]);
       if (res instanceof Promise) {
-        return res.then((resolvedRes) => {
-          span.end();
-          return resolvedRes;
-        });
+        return res.finally(() => {
+          span.end();
+        });
       }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • 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 6eb35ca and b22a9a6.

📒 Files selected for processing (5)
  • packages/ai-semantic-conventions/src/SemanticAttributes.ts (2 hunks)
  • packages/traceloop-sdk/src/lib/tracing/decorators.ts (3 hunks)
  • packages/traceloop-sdk/src/lib/tracing/manual.ts (3 hunks)
  • packages/traceloop-sdk/src/lib/tracing/span-processor.ts (2 hunks)
  • packages/traceloop-sdk/test/agent_decorator.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/ai-semantic-conventions/src/SemanticAttributes.ts
  • packages/traceloop-sdk/src/lib/tracing/decorators.ts
  • packages/traceloop-sdk/test/agent_decorator.test.ts
🧰 Additional context used
📓 Path-based instructions (2)
packages/{instrumentation-*,traceloop-sdk}/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Import AI/LLM semantic attribute constants from @traceloop/ai-semantic-conventions rather than hardcoding strings

Files:

  • packages/traceloop-sdk/src/lib/tracing/manual.ts
  • packages/traceloop-sdk/src/lib/tracing/span-processor.ts
packages/traceloop-sdk/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

packages/traceloop-sdk/**/*.{ts,tsx}: Use the provided decorators (@workflow, @task, @agent) for workflow/task/agent spans instead of re-implementing them
For manual LLM operations, use trace.withLLMSpan from @traceloop/node-server-sdk

Files:

  • packages/traceloop-sdk/src/lib/tracing/manual.ts
  • packages/traceloop-sdk/src/lib/tracing/span-processor.ts
🧠 Learnings (5)
📓 Common learnings
Learnt from: CR
PR: traceloop/openllmetry-js#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-24T22:08:07.023Z
Learning: Applies to packages/instrumentation-*/**/*.{ts,tsx} : Instrumentations must create spans with appropriate AI/LLM semantic attributes for calls they wrap
📚 Learning: 2025-08-24T22:08:07.023Z
Learnt from: CR
PR: traceloop/openllmetry-js#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-24T22:08:07.023Z
Learning: Applies to packages/traceloop-sdk/**/*.{ts,tsx} : For manual LLM operations, use trace.withLLMSpan from traceloop/node-server-sdk

Applied to files:

  • packages/traceloop-sdk/src/lib/tracing/manual.ts
  • packages/traceloop-sdk/src/lib/tracing/span-processor.ts
📚 Learning: 2025-08-24T22:08:07.023Z
Learnt from: CR
PR: traceloop/openllmetry-js#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-24T22:08:07.023Z
Learning: Applies to packages/{instrumentation-*,traceloop-sdk}/**/*.{ts,tsx} : Import AI/LLM semantic attribute constants from traceloop/ai-semantic-conventions rather than hardcoding strings

Applied to files:

  • packages/traceloop-sdk/src/lib/tracing/manual.ts
  • packages/traceloop-sdk/src/lib/tracing/span-processor.ts
📚 Learning: 2025-08-24T22:08:07.023Z
Learnt from: CR
PR: traceloop/openllmetry-js#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-24T22:08:07.023Z
Learning: Applies to packages/traceloop-sdk/**/*.{ts,tsx} : Use the provided decorators (workflow, task, agent) for workflow/task/agent spans instead of re-implementing them

Applied to files:

  • packages/traceloop-sdk/src/lib/tracing/manual.ts
  • packages/traceloop-sdk/src/lib/tracing/span-processor.ts
📚 Learning: 2025-08-24T22:08:07.023Z
Learnt from: CR
PR: traceloop/openllmetry-js#0
File: CLAUDE.md:0-0
Timestamp: 2025-08-24T22:08:07.023Z
Learning: Applies to packages/instrumentation-*/**/*.{ts,tsx} : Instrumentations must create spans with appropriate AI/LLM semantic attributes for calls they wrap

Applied to files:

  • packages/traceloop-sdk/src/lib/tracing/manual.ts
  • packages/traceloop-sdk/src/lib/tracing/span-processor.ts
🧬 Code graph analysis (2)
packages/traceloop-sdk/src/lib/tracing/manual.ts (2)
packages/traceloop-sdk/src/lib/tracing/tracing.ts (2)
  • AGENT_NAME_KEY (7-7)
  • getTracer (12-14)
packages/ai-semantic-conventions/src/SemanticAttributes.ts (1)
  • SpanAttributes (18-64)
packages/traceloop-sdk/src/lib/tracing/span-processor.ts (2)
packages/traceloop-sdk/src/lib/tracing/tracing.ts (1)
  • AGENT_NAME_KEY (7-7)
packages/ai-semantic-conventions/src/SemanticAttributes.ts (1)
  • SpanAttributes (18-64)
🔇 Additional comments (3)
packages/traceloop-sdk/src/lib/tracing/span-processor.ts (2)

15-16: LGTM: context key import

Importing AGENT_NAME_KEY from ./tracing is correct and aligns with our context-handling design.


152-155: LGTM: set gen_ai.agent.name on span start

Correctly reads AGENT_NAME_KEY from context and uses SpanAttributes.GEN_AI_AGENT_NAME (no hardcoded string). Matches the semantic conventions.

packages/traceloop-sdk/src/lib/tracing/manual.ts (1)

2-2: LGTM: AGENT_NAME_KEY import

Using the shared context key avoids duplication and hardcoded strings.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed 732c0b2 in 31 seconds. Click for details.
  • Reviewed 53 lines of code in 3 files
  • Skipped 0 files when reviewing.
  • Skipped posting 3 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. packages/ai-semantic-conventions/src/SemanticAttributes.ts:14
  • Draft comment:
    Minor formatting change: redundant blank line removed before defining SpanAttributes.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
2. packages/traceloop-sdk/src/lib/tracing/decorators.ts:102
  • Draft comment:
    Multiline formatting for setAttribute call improves readability; update looks fine.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
3. packages/traceloop-sdk/src/lib/tracing/manual.ts:148
  • Draft comment:
    Consistent multiline formatting for setAttribute in withVectorDBCall; no issues.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None

Workflow ID: wflow_J0d6uF5t376mcbZJ

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@nina-kollman nina-kollman merged commit b2af9a2 into main Sep 21, 2025
8 checks passed
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