Skip to content

[AAI-611] Align metadata encoding and propagation - #133

Open
kxzk wants to merge 5 commits into
mainfrom
aai-611-align-metadata-encoding-and-propagation
Open

kxzk wants to merge 5 commits into
mainfrom
aai-611-align-metadata-encoding-and-propagation

Conversation

@kxzk

@kxzk kxzk commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

TL;DR

Accept JSON-valued metadata propagation and add opt-in JSON object encoding for observations, traces, and experiments.

Why

Ruby is excluded from Langfuse's per-key JSON decoding. Whole-object encoding preserves structured payloads without changing SDK identity. Legacy encoding remains the default; migration guidance covers hooks, filters, and server readback limits.

Checklist

  • Has label
  • Has linked issue
  • Tests added for new behavior
  • Docs updated (if user-facing)

Closes AAI-611

Verification

Local tests passed with 97.31% coverage. CI passed on Ruby 3.2–3.4 with both JSON dependency matrices, plus RuboCop. Langfuse 4.78.0 CLI readback, observation metadata filters, and browser inspection verified propagation, concurrent updates, experiments, and masking. Older self-hosted versions remain unverified.


Note

Medium Risk
Touches core trace propagation, OpenTelemetry attribute shape, and cross-service baggage; opting into :json can break existing metadata filters and export masking hooks until migrated.

Overview
Introduces metadata_encoding on Langfuse::Config (:legacy default, :json opt-in) and a new MetadataEncoding module that owns how observation, trace, experiment, and experiment-item metadata are serialized on the wire, propagated through context/baggage, merged on span updates, and applied via MetadataEncoding.apply_to_span.

Legacy behavior is unchanged by default. In :json mode, metadata is sent as a single JSON object per base attribute (e.g. langfuse.trace.metadata) instead of flattened dotted keys; propagate_attributes now accepts JSON-serializable metadata values with encoded length limits, frozen snapshots, and safer handling of invalid JSON, oversized values, and inbound baggage (including dropping non–UTF-8 entries so export batches are not lost). Observation/trace updates use striped locks to merge concurrent JSON metadata writes.

OtelAttributes, Propagation, ExperimentAttributes, and observation update/update_trace paths route through MetadataEncoding. Docs add METADATA.md plus updates to configuration, tracing, and experiments guidance (backend contract, filters, hook migration). A large metadata_encoding_spec covers encoding modes, propagation, baggage round-trips, masking, and export hooks.

Reviewed by Cursor Bugbot for commit b4fca75. Bugbot is set up for automated code reviews on this repo. Configure here.

@kxzk kxzk added the enhancement New feature or request label Nov 11, 2026
@linear-code

linear-code Bot commented Nov 11, 2026

Copy link
Copy Markdown

AAI-611

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

Stale Bugbot comment from a previous run.

Comment thread lib/langfuse/propagation.rb Resolved
Comment thread lib/langfuse/propagation.rb Resolved

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 9519362. Configure here.

Comment thread lib/langfuse/metadata_encoding.rb Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant