Skip to content

feat(tracing)!: JSON-serialize propagated metadata values - #1932

Merged
hassiebp merged 24 commits into
prepare-v5-releasefrom
lfe-17061-python-sdk-v5-json-serialize-propagated-metadata-align-with
Oct 7, 2026
Merged

hassiebp merged 24 commits into
prepare-v5-releasefrom
lfe-17061-python-sdk-v5-json-serialize-propagated-metadata-align-with

Conversation

@hassiebp

@hassiebp hassiebp commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

propagate_attributes(metadata=...) coerced non-string values with str(), so True became "True", ["a"] became "['a']", and dicts became their Python repr. Propagated metadata values are now serialized exactly like JSON.stringify in the JS SDK (langfuse-js#980), so both SDKs emit byte-identical values: compact separators, non-ASCII kept as is, insertion key order, and None → "null".

value before after (= JS)
True "True" "true"
["branch:agent"] "['branch:agent']" '["branch:agent"]'
{"model": "gpt-4o", "n": {"a": "ü"}} "{'model': 'gpt-4o', 'n': {'a': 'ü'}}" '{"model":"gpt-4o","n":{"a":"ü"}}'
None "None" "null"

Strings are kept as is, and ints serialize the same as before. The 200-character limit applies to the serialized value. Non-JSON Python types (datetimes, pydantic models, and so on) go through EventSerializer, as elsewhere in the SDK.

Stack: 5 of 10. Base: #1931. Merge after #1931.

Type of change

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

Verification

uv run --frozen ruff check .                       # All checks passed!
uv run --frozen mypy langfuse --no-error-summary   # clean
uv run --frozen pytest -q tests/unit/test_propagate_attributes.py  # the new test failed before the change; 133 passed after
uv run --frozen pytest -n auto tests/unit          # 714 passed, 2 skipped

Byte-equality with Node's JSON.stringify was checked for ints, floats, bools, null, lists, nested dicts, non-ASCII/emoji, escaped quotes and tabs, and large safe ints: all identical.

Notes for the reviewer

These Python-only cases can't match JS exactly, by design:

  • Integral floats: 1.0 serializes as "1.0" here, but "1" in JS.
  • NaN/Infinity: these become "\"NaN\"" here, but "null" in JS.
  • Datetimes: they use EventSerializer's ISO format (no forced milliseconds), so they aren't identical to JS Date.toJSON.
  • Tuples and sets: these serialize as JSON arrays.

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.
Open in Web Open in Cursor 

RetriggerConfidence Score: 4/5

The PR should not merge until propagated large integer metadata retains its intended representation.

Summary

The PR JSON-serializes non-string propagated metadata, drops None values, and updates unit tests.

  • Large integers acquire JSON quotation marks in propagated attributes.
  • The tests do not cover a baggage-header round trip for the new value formats.

Reviews (1) · Last reviewed commit: "feat(tracing)!: JSON-serialize propagate..."

cursoragent and others added 5 commits October 6, 2026 14:15
Python 3.10 reaches end of life in October 2026. Raise requires-python
to >=3.11, target py311 in ruff, drop 3.10 from the CI unit matrix, and
remove the pre-3.11 fallbacks for asyncio.create_task(context=...) and
typing.NotRequired.

Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com>
The OpenAI integration now always uses the v1 client shapes. Remove the
pre-1.0 method definitions and every _is_openai_v1() branch, and raise
the dev dependency floor to openai>=1.0.0.

Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com>
The default OTLP exporter now sends x-langfuse-ingestion-version: 4 so
servers in dual-write or preview mode process exported spans directly.
It is a no-op on events_only deployments, and additional_headers can
still override it.

Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com>
blocked_instrumentation_scopes was deprecated in favor of
should_export_span. Remove it from Langfuse, the resource manager and
the span processor, and drop the leftover is_active entry from the
create_prompt docstring. LANGFUSE_HOST and host keep working, but now
log a deprecation warning when they decide the base URL.

Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com>
propagate_attributes(metadata=...) coerced non-string values with str(),
so a boolean became "True" and a list became its Python repr. Serialize
them as JSON instead, like observation metadata, and drop None values
instead of sending "None".

Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com>
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown

@claude review

@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

No review was started: this request came from a bot account. Manual reviews can only be requested by someone with write access to this repository. Ask a maintainer to comment @claude review, or have your automation post the comment from a user account with write access.

Tip: disable this comment in your organization's Code Review settings.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-06T14:34:16.155740Z e9623ee PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Comment thread langfuse/_client/propagation.py Outdated

@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.

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Comment thread langfuse/_client/propagation.py Outdated
cursoragent and others added 18 commits October 6, 2026 15:02
Use compact separators, keep non-ASCII characters, and send None as
"null", so the Python and JS SDKs emit byte-identical propagated
metadata values.

Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com>
inspect.iscoroutinefunction ignores asyncio's _is_coroutine marker,
which asgiref's markcoroutinefunction sets on Python < 3.12. Accept
both so such functions keep the async wrapper and their observation
ends after the coroutine runs.

Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com>
…o lfe-17074-python-sdk-v5-send-x-langfuse-ingestion-version-4-by-default

Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com>
…scopes-and' into lfe-17061-python-sdk-v5-json-serialize-propagated-metadata-align-with

Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com>
…on-4-by-default' into lfe-17078-python-sdk-v5-remove-blocked_instrumentation_scopes-and

Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com>
…0' into lfe-17080-python-sdk-v5-drop-openai-sdk-10-support

Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com>
Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com>
Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com>
…on-4-by-default' into lfe-17078-python-sdk-v5-remove-blocked_instrumentation_scopes-and

Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com>
…scopes-and' into lfe-17061-python-sdk-v5-json-serialize-propagated-metadata-align-with

Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com>
…penai-sdk-10-support

Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com>
…o lfe-17074-python-sdk-v5-send-x-langfuse-ingestion-version-4-by-default

Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com>
…on-4-by-default' into lfe-17078-python-sdk-v5-remove-blocked_instrumentation_scopes-and

Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com>
…scopes-and' into lfe-17061-python-sdk-v5-json-serialize-propagated-metadata-align-with

Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com>
Integers keep their exact digits as JSON numbers at any depth, and
propagated metadata values containing NaN or Infinity are dropped with a
warning instead of being stored, matching the JS SDK.

Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com>
…-blocked_instrumentation_scopes-and

Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com>
Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com>
…scopes-and' into lfe-17061-python-sdk-v5-json-serialize-propagated-metadata-align-with

Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com>
Base automatically changed from lfe-17078-python-sdk-v5-remove-blocked_instrumentation_scopes-and to prepare-v5-release October 7, 2026 14:33
…erialize-propagated-metadata-align-with

Co-authored-by: Hassieb Pakzad <hassiebp@users.noreply.github.com>
@hassiebp
hassiebp merged commit 8d7c066 into prepare-v5-release Oct 7, 2026
13 checks passed
@hassiebp
hassiebp deleted the lfe-17061-python-sdk-v5-json-serialize-propagated-metadata-align-with branch October 7, 2026 15:38
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