Skip to content

fix(scores): apply trace sampling to scores again - #1891

Open
moldhouse wants to merge 1 commit into
langfuse:mainfrom
moldhouse:fix/score-sampling
Open

moldhouse wants to merge 1 commit into
langfuse:mainfrom
moldhouse:fix/score-sampling

Conversation

@moldhouse

@moldhouse moldhouse commented Sep 18, 2026

Copy link
Copy Markdown

What does this PR do?

create_score passed camelCase kwargs to the v4 ScoreBody, which takes snake_case field names and keeps unknown kwargs as extras. body.trace_id was always None, so add_score_task never sampled a score out. This builds the body by field name and serialises it by alias in the consumer, so the wire format is unchanged.

Fixes #1890

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Refactor
  • Documentation update
  • Tooling, CI, or repo maintenance

Verification

uv run --frozen ruff check .
uv run --frozen mypy langfuse --no-error-summary
uv run --frozen pytest tests/unit/test_resource_manager.py tests/unit/test_otel.py::TestAdvancedSpans::test_score_sampling_follows_trace_sampling

Checklist

  • I self-reviewed the diff using code_review.md.
  • I added or updated tests for behavior changes.
  • I updated docs, examples, or .env.template if needed.
  • I did not hand-edit generated files; if generated files changed, I used the upstream regeneration path.
  • I did not commit secrets or credentials.

RetriggerConfidence Score: 5/5

The PR appears safe to merge; the corrected model population restores score sampling while preserving the ingestion contract.

Summary

This PR restores trace-consistent sampling for scores by populating the generated score model through its Python field names and applying API aliases when the queued model is serialized.

  • Trace-linked scores now expose trace_id to queue-admission sampling.
  • Score and trace-update bodies retain their camelCase ingestion wire format.
  • Unit tests cover sampled, dropped, and non-trace-linked scores plus alias serialization.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
    A[create_score] --> B[Build ScoreBody with snake_case fields]
    B --> C{Trace-linked and sampled?}
    C -->|No| D[Drop score]
    C -->|Yes or unlinked| E[Score ingestion queue]
    E --> F[Convert model fields to API aliases]
    F --> G[camelCase ingestion payload]
Loading

Reviews (1) · Last reviewed commit: "fix(scores): apply trace sampling to sco..."

create_score passed camelCase kwargs to the v4 ScoreBody, which takes
snake_case field names and keeps unknown kwargs as extras. body.trace_id
was always None, so add_score_task never sampled a score out.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@CLAassistant

CLAassistant commented Sep 18, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.

Scores bypass sample_rate since v4

2 participants