Skip to content

Conversation

@nirga
Copy link
Member

@nirga nirga commented Aug 9, 2025

  • Add ToolCall, ToolCallFunction, ToolFunction, and Tool types to tracing_types.go
  • Extend Message type with ToolCalls field for tool calling support
  • Add Tools field to Prompt type for function definitions
  • Implement setMessageToolCallsAttribute and setToolsAttribute functions
  • Update setMessagesAttribute to handle tool calls with individual span attributes
  • Create comprehensive tool calling sample with workflow API
  • Support multi-turn tool calling conversations with proper tracing
  • Set individual span attributes matching Python OpenLLMetry implementation:
    • llm.completions.{i}.tool_calls.{j}.id
    • llm.completions.{i}.tool_calls.{j}.name
    • llm.completions.{i}.tool_calls.{j}.arguments
    • llm.request.functions.{i}.name
    • llm.request.functions.{i}.description
    • llm.request.functions.{i}.parameters

🤖 Generated with Claude Code


Important

Implement tool calling support in workflow API with new types, functions, and a sample application.

  • Behavior:
    • Add ToolCall, ToolCallFunction, ToolFunction, and Tool types to tracing_types.go for tool calling support.
    • Extend Message type with ToolCalls field and Prompt type with Tools field.
    • Implement setMessageToolCallsAttribute and setToolsAttribute functions in sdk.go.
    • Update setMessagesAttribute in sdk.go to handle tool calls.
    • Create a tool calling sample in main.go with multi-turn conversation support.
  • Tracing:
    • Set individual span attributes for tool calls in sdk.go to match Python OpenLLMetry implementation.
  • Dependencies:
    • Add dependencies in go.work.sum, go.mod, and go.sum for tool calling support.

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

Summary by CodeRabbit

  • New Features

    • Introduced a new tool-calling workflow example, allowing users to simulate weather tool calls and view assistant responses with tool integration.
    • Enhanced tracing with detailed tool and tool call metadata, providing richer insights into tool usage within prompts and messages.
  • Improvements

    • Expanded support for tool-related data in prompts and messages, enabling more comprehensive tracking and display of tool interactions.
  • Removals

    • Removed the previous workflow example, streamlining the available examples for users.

- Add ToolCall, ToolCallFunction, ToolFunction, and Tool types to tracing_types.go
- Extend Message type with ToolCalls field for tool calling support
- Add Tools field to Prompt type for function definitions
- Implement setMessageToolCallsAttribute and setToolsAttribute functions
- Update setMessagesAttribute to handle tool calls with individual span attributes
- Create comprehensive tool calling sample with workflow API
- Support multi-turn tool calling conversations with proper tracing
- Set individual span attributes matching Python OpenLLMetry implementation:
  - llm.completions.{i}.tool_calls.{j}.id
  - llm.completions.{i}.tool_calls.{j}.name
  - llm.completions.{i}.tool_calls.{j}.arguments
  - llm.request.functions.{i}.name
  - llm.request.functions.{i}.description
  - llm.request.functions.{i}.parameters

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Aug 9, 2025

Walkthrough

The changes introduce a tool-calling example workflow in the sample application, integrating Traceloop tracing and OpenAI APIs. The Traceloop SDK and its types are extended to support tool and tool call metadata. The sample app's dependencies are expanded and local module replacements added. An older workflow example is deleted.

Changes

Cohort / File(s) Change Summary
Sample App Tool-Calling Example
sample-app/main.go
Adds a new tool-calling workflow example using Traceloop and OpenAI. Introduces weather tool simulation, conversion helpers, and conditional main logic for the new example.
Traceloop SDK Tool Support
traceloop-sdk/sdk.go, traceloop-sdk/tracing_types.go
Adds support for tool and tool call metadata in tracing. Extends types for tools/tool calls, updates attribute setting, and enhances prompt/message logging.
Sample App Dependency Management
sample-app/go.mod
Expands and restructures dependencies, adds local replacements for Traceloop SDK and semconv-ai, and lists indirect dependencies explicitly.
Sample App Legacy Example Removal
sample-app/workflow_example.go
Deletes the old workflow example file, removing its main function and all related code.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MainApp
    participant TraceloopSDK
    participant OpenAI

    User->>MainApp: Run with "tool-calling" argument
    MainApp->>TraceloopSDK: Initialize tracing
    MainApp->>OpenAI: Send chat completion with tool (weather)
    OpenAI->>MainApp: Return assistant response (with tool calls)
    MainApp->>TraceloopSDK: Log assistant response and tool calls
    MainApp->>MainApp: Parse tool calls, run getWeather
    MainApp->>TraceloopSDK: Log tool results
    MainApp->>OpenAI: Send follow-up chat completion with tool results
    OpenAI->>MainApp: Return final assistant response
    MainApp->>TraceloopSDK: Log final response
    MainApp->>User: Print results
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~18 minutes

Poem

🐇
In fields of code, a rabbit hops,
Tool-calling magic, tracing stops!
Weather summoned, spans enriched,
Old workflows gone, new ones stitched.
SDK grows with types anew—
Dependencies fresh, the sky turns blue!
Review complete—let’s hop on through!

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch tool-calling-workflow-api

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

Support

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

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

@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 everything up to de1ead2 in 1 minute and 20 seconds. Click for details.
  • Reviewed 773 lines of code in 7 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. traceloop-sdk/sdk.go:117
  • Draft comment:
    In the setToolsAttribute function, the error from json.Marshal is silently ignored. Consider logging or otherwise handling the error (lines 117–123) to aid in debugging parameter serialization issues.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 30% vs. threshold = 50% This is a tracing/observability function that sets span attributes. If serialization fails, the code gracefully degrades by simply not setting that particular attribute. Since this is non-critical observability code, silent failure might be acceptable. However, having no indication of serialization failures could make debugging issues harder. I might be underestimating the impact of missing parameter data in traces. Also, json.Marshal errors are rare but could indicate deeper issues with the data structure. While logging the error could help debugging, the current behavior of graceful degradation is reasonable for observability code. The parameters attribute is optional metadata. The comment raises a valid point but the current implementation is acceptable given this is non-critical observability code. The comment should be removed as it doesn't highlight a significant issue requiring change.
2. sample-app/main.go:100
  • Draft comment:
    The conversion functions (convertOpenAIToolCallsToTLP and convertToolsToTLP) are straightforward and correctly implemented; however, adding inline documentation and unit tests could improve clarity and maintainability.
  • Reason this comment was not posted:
    Confidence changes required: 40% <= threshold 50% None
3. traceloop-sdk/sdk.go:174
  • Draft comment:
    In the Shutdown function, tracerProvider.Shutdown is invoked without capturing its error. Consider capturing and logging any error returned to ensure shutdown issues are not silently ignored.
  • Reason this comment was not posted:
    Confidence changes required: 40% <= threshold 50% None

Workflow ID: wflow_IYFjcZwhxz9QFyBm

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: 0

🔭 Outside diff range comments (1)
sample-app/main.go (1)

17-22: Nil-pointer risk when NewClient fails

defer func() { traceloop.Shutdown(ctx) }() is executed before you check err.
If NewClient returns an error, traceloop is nil and the deferred call panics.

Move the defer after the error check:

-traceloop, err := tlp.NewClient(ctx, tlp.Config{ ... })
-defer func() { traceloop.Shutdown(ctx) }()
-if err != nil {
+traceloop, err := tlp.NewClient(ctx, tlp.Config{ ... })
+if err != nil {
     fmt.Printf("NewClient error: %v\n", err)
     return
 }
+defer func() { traceloop.Shutdown(ctx) }()
♻️ Duplicate comments (1)
sample-app/main.go (1)

170-175: Same nil-pointer panic pattern here

Replicate the fix inside runToolCallingExample() for the second NewClient call.

🧹 Nitpick comments (4)
traceloop-sdk/tracing_types.go (1)

20-23: Exported type lacks JSON “omitempty” safeguard

Tool.Function will always serialize the empty function object even when no data are provided.
If you want the field to be truly optional (consistent with tool_calls and tools), add omitempty:

-type Tool struct {
-	Type     string       `json:"type"`
-	Function ToolFunction `json:"function"`
+type Tool struct {
+	Type     string       `json:"type"`
+	Function ToolFunction `json:"function,omitempty"`
 }
traceloop-sdk/sdk.go (2)

80-89: Missing propagation of toolCall.Type

setMessageToolCallsAttribute records id, name, and arguments but drops the tool-call type even though this value is available in the struct.
If multiple tool-call types are ever introduced, observability will be incomplete.

 attribute.String(toolCallPrefix+".arguments", toolCall.Function.Arguments),
+attribute.String(toolCallPrefix+".type", toolCall.Type),

117-124: Silent JSON-marshal failure hides problems

If json.Marshal on tool.Function.Parameters errors, the SDK swallows it and emits no attribute, silently degrading telemetry.
At minimum log the error so integrators know something is wrong:

-	if tool.Function.Parameters != nil {
-		parametersJSON, err := json.Marshal(tool.Function.Parameters)
-		if err == nil {
-			span.SetAttributes(attribute.String(prefix+".parameters", string(parametersJSON)))
-		}
-	}
+	if tool.Function.Parameters != nil {
+		if parametersJSON, err := json.Marshal(tool.Function.Parameters); err == nil {
+			span.SetAttributes(attribute.String(prefix+".parameters", string(parametersJSON)))
+		} else {
+			log.Printf("traceloop: failed to marshal tool parameters: %v", err)
+		}
+	}
sample-app/main.go (1)

269-286: Default unit assignment bypasses schema enum

Assigning "F" when unit is empty is fine, but if the assistant explicitly passes an empty string, the result silently changes.
Consider validating params.Unit against the enum (C|F) and returning an error to the model instead of coercing.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6b2b4b4 and de1ead2.

⛔ Files ignored due to path filters (2)
  • go.work.sum is excluded by !**/*.sum
  • sample-app/go.sum is excluded by !**/*.sum
📒 Files selected for processing (5)
  • sample-app/go.mod (1 hunks)
  • sample-app/main.go (2 hunks)
  • sample-app/workflow_example.go (0 hunks)
  • traceloop-sdk/sdk.go (3 hunks)
  • traceloop-sdk/tracing_types.go (2 hunks)
💤 Files with no reviewable changes (1)
  • sample-app/workflow_example.go
🧰 Additional context used
🧬 Code Graph Analysis (1)
traceloop-sdk/sdk.go (2)
traceloop-sdk/tracing_types.go (3)
  • ToolCall (8-12)
  • Message (25-30)
  • Tool (20-23)
semconv-ai/attributes.go (1)
  • LLMRequestFunctions (25-25)
🔇 Additional comments (1)
sample-app/go.mod (1)

11-23: Duplicate major versions of the same library

Both github.com/cenkalti/backoff (v2) and github.com/cenkalti/backoff/v4 are required.
Having two major versions of the same package inflates the build and usually indicates an unintended transitive dependency.
Run go mod tidy and, if possible, align downstream libs to a single major version.

@nirga nirga closed this Aug 9, 2025
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.

2 participants