Skip to content

feat: capture request metadata#58

Merged
Alex R (alexr17) merged 4 commits into
mainfrom
alexr/capture-request-metadata
May 21, 2026
Merged

feat: capture request metadata#58
Alex R (alexr17) merged 4 commits into
mainfrom
alexr/capture-request-metadata

Conversation

@alexr17
Copy link
Copy Markdown
Contributor

fixes: #55

Summary

OpenAI and Anthropic instrumentation now captures a braintrust.metadata tag on LLM spans containing all request parameters except messages — including model, temperature, max_tokens, tools, tool_choice, top_p, and
more. This mirrors the Python SDK behavior where non-message params are separated into metadata for trace observability.

Changes

  • OpenAI (baggage path): Extracts all non-messages fields from the raw request JSON into braintrust.metadata (captures the full wire request including tools, temperature, max_tokens, response_format, etc.)
  • OpenAI (fallback path): Manually extracts temperature, max_tokens, top_p, frequency_penalty, presence_penalty, stop, end_user_id, tools, tool_choice, and response_format from ChatCompletionOptions
  • Anthropic: Captures model, max_tokens, temperature, top_p, top_k, stop_sequences, tools, and tool_choice from MessageCreateParams in both streaming and non-streaming paths
  • Tests: Added braintrust.metadata assertions to ChatCompletion_CapturesRequestAndResponse (both transport and fallback paths) and MessageCreation_CapturesRequestAndResponse

Format

  {
    "provider": "anthropic",
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 512,
    "temperature": 0.7
  }

Copy link
Copy Markdown
Collaborator

@realark Andrew Kent (realark) left a comment

Choose a reason for hiding this comment

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

LGTM -- if you haven't already, I'd recommend running the examples to make sure this shows up as expected in the UI (I'm pretty sure this is correct but usually good to verify)

@alexr17 Alex R (alexr17) merged commit 4c13647 into main May 21, 2026
1 check 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.

[bot] OpenAI and Anthropic integrations do not capture request metadata (tools definitions, temperature, max_tokens)

2 participants