Skip to content

Conversation

@godwhoa
Copy link
Contributor

@godwhoa godwhoa commented Jul 17, 2025

Important

Ensures system prompt is placed first in span attributes for chat messages and adds corresponding tests.

  • Behavior:
    • Ensures system prompt is placed first in span attributes for chat messages in instrumentation.ts.
    • Handles cases where params.system is defined and non-undefined.
  • Testing:
    • Adds test should place system prompt first for messages in instrumentation.test.ts to verify system prompt ordering.
    • Includes new test recording recording.har to validate the change.

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

Summary by CodeRabbit

  • New Features
    • Improved handling of system prompts to ensure they are always placed first when sending messages.
  • Tests
    • Added a new test to verify correct ordering of system prompts in message attributes.
  • Chores
    • Included a new HAR recording capturing the system prompt handling scenario.
@CLAassistant
Copy link

CLAassistant commented Jul 17, 2025

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link

coderabbitai bot commented Jul 17, 2025

Walkthrough

A new HAR recording was added for a test verifying system prompt placement in Anthropic instrumentation. The startSpan method was updated to ensure the system prompt is always indexed first in span attributes, followed by other messages. A corresponding test case was introduced to validate this behavior.

Changes

File(s) Change Summary
.../recordings/Test-Anthropic-instrumentation_.../should-place-system-prompt-first-for-messages_... Added HAR recording for system prompt placement test.
packages/instrumentation-anthropic/src/instrumentation.ts Updated startSpan to index system prompt first in span attributes if present.
packages/instrumentation-anthropic/test/instrumentation.test.ts Added test to verify system prompt is first in span attributes for message requests.

Sequence Diagram(s)

sequenceDiagram participant TestSuite participant Instrumentation participant AnthropicAPI TestSuite->>Instrumentation: Send message request with system prompt and messages Instrumentation->>Instrumentation: startSpan() alt system prompt exists Instrumentation->>Instrumentation: Set prompt[0] to system prompt Instrumentation->>Instrumentation: Set prompt[1..n] to messages else no system prompt Instrumentation->>Instrumentation: Set prompt[0..n] to messages end Instrumentation->>AnthropicAPI: POST /v1/messages AnthropicAPI-->>Instrumentation: Respond with message Instrumentation-->>TestSuite: Return response and span attributes 
Loading

Poem

In a warren of code, a prompt found its place,
System words now lead, setting the pace.
With a shuffle and hop, the order is right,
The tests all agree—what a wonderful sight!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-07-17T18_35_55_936Z-debug-0.log


📜 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 c777386 and e01fee4.

📒 Files selected for processing (3)
  • packages/instrumentation-anthropic/recordings/Test-Anthropic-instrumentation_3769946143/should-place-system-prompt-first-for-messages_507270015/recording.har (1 hunks)
  • packages/instrumentation-anthropic/src/instrumentation.ts (1 hunks)
  • packages/instrumentation-anthropic/test/instrumentation.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/instrumentation-anthropic/src/instrumentation.ts
  • packages/instrumentation-anthropic/test/instrumentation.test.ts
  • packages/instrumentation-anthropic/recordings/Test-Anthropic-instrumentation_3769946143/should-place-system-prompt-first-for-messages_507270015/recording.har
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 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 c777386 in 2 minutes and 9 seconds. Click for details.
  • Reviewed 290 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/instrumentation-anthropic/recordings/Test-Anthropic-instrumentation_3769946143/should-place-system-prompt-first-for-messages_507270015/recording.har:1
  • Draft comment:
    Ensure the HAR recording does not include any sensitive data. Verify headers (e.g., API keys) are properly scrubbed.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
2. packages/instrumentation-anthropic/src/instrumentation.ts:220
  • Draft comment:
    Good use of 'promptIndex' to prepend the system prompt. Consider handling cases where the system value might be an empty string or null, and possibly extracting this logic into a helper for clarity.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% The code already handles undefined system prompts through the condition check. Empty strings are handled by the || "" fallback. The logic is straightforward and contained within a reasonable scope - extracting it would add unnecessary complexity. The comment is suggesting improvements that are either already handled or would make the code worse. I could be wrong about the value of extracting this logic - if this pattern appears multiple times in the codebase, a helper might be valuable. Also, there could be edge cases with system prompt handling that I'm missing. The code is localized to this file and this specific use case. The system prompt handling is already robust with type checking and undefined checks. Making it more complex would reduce readability. The comment should be deleted as it suggests changes that are either already handled or would unnecessarily complicate the code.
3. packages/instrumentation-anthropic/test/instrumentation.test.ts:302
  • Draft comment:
    Test 'should place system prompt first for messages' correctly verifies system prompt at index 0 and first user message at index 1. Consider also asserting that the assistant message (expected at index 2) is correctly set, and note that using Array.at(-1) may not be supported in all Node versions.
  • 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 about asserting the assistant message is not critical since the test's main purpose is verifying prompt order, specifically that system comes first. The Array.at() suggestion has merit since it's a relatively new method, but this is a test file in a modern codebase that likely controls its Node.js version. The comment is mixing a non-critical test coverage suggestion with a minor implementation detail. I might be underestimating the importance of complete test coverage. Also, Array.at() compatibility could be a real issue for some users of this library. The test's purpose is specifically about system prompt ordering, not complete message validation. The Node compatibility concern is minor since this is in test code, not production code. The comment should be deleted as it suggests changes that are not essential to the test's purpose and raises minor implementation concerns in test code.

Workflow ID: wflow_emrzu2m4V0899cGH

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

Copy link
Member

@nirga nirga left a comment

Choose a reason for hiding this comment

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

Thanks @godwhoa! Mind fixing the lint issues?

@godwhoa godwhoa force-pushed the fix-system-prompt branch from c777386 to e01fee4 Compare July 17, 2025 18:34
@nirga nirga merged commit 719c6f8 into traceloop:main Jul 17, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants