Skip to content

fix(otel): do not set AS_ROOT on child spans with parent_span_id - #1823

Open
misinierijon4-debug wants to merge 1 commit into
langfuse:mainfrom
misinierijon4-debug:fix/issue-16272-trace-name-overwrite-by-child-span
Open

fix(otel): do not set AS_ROOT on child spans with parent_span_id#1823
misinierijon4-debug wants to merge 1 commit into
langfuse:mainfrom
misinierijon4-debug:fix/issue-16272-trace-name-overwrite-by-child-span

Conversation

@misinierijon4-debug

@misinierijon4-debug misinierijon4-debug commented Aug 18, 2026

Copy link
Copy Markdown

Problem

When creating spans using start_as_current_observation() or start_observation() within an existing trace or with a trace_context containing a parent_span_id, the client stamped LangfuseOtelSpanAttributes.AS_ROOT: True on the child span. This caused the Langfuse ingestion processor on the server to treat every child span as the root of the trace, overwriting the parent trace's name (and trace-level IO) with the child span's name during trace updates.

Root cause

_create_span_with_parent_context, start_observation, and create_event set LangfuseOtelSpanAttributes.AS_ROOT = True whenever remote_parent_span is not None, without checking whether parent_span_id was provided or whether the span was a non-root child span in an existing trace.

Solution

  • Updated start_observation, create_event, start_as_current_observation, and _create_span_with_parent_context to only set LangfuseOtelSpanAttributes.AS_ROOT = True when parent_span_id is None (i.e. only on true trace root spans).
  • Updated unit test assertions in tests/unit/test_otel.py so child spans with custom parent_span_id are not marked as AS_ROOT.

Proof

Test Run

PS C:\Users\erijo\Downloads\claude> python test_reproduce_langfuse_16272.py
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

Reference

Fixes langfuse/langfuse#16272

Greptile Summary

The PR corrects Langfuse root-span metadata so observations with an explicit parent span are not marked as trace roots.

  • Gates AS_ROOT on the absence of parent_span_id across observation and event creation paths.
  • Threads explicit root status through the shared parent-context span helper.
  • Updates the OTel unit assertion for an explicitly parented span.

Confidence Score: 4/5

The PR appears safe to merge after removing the non-blocking duplicate method definition.

The root-marker changes consistently distinguish explicitly parented observations, while the only accepted concern is an identical method definition that silently shadows its predecessor.

Files Needing Attention: langfuse/_client/client.py

Prompt To Fix All With AI
### Issue 1
langfuse/_client/client.py:1276-1283
**Duplicate observation-type method**

This adds a second identical `_get_observation_type` definition that silently replaces the existing method, leaving dead and misleading code that can diverge when this helper is updated later.

```suggestion

```

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "fix(otel): do not set AS_ROOT on child s..." | Re-trigger Greptile

Context used:

@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

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

bug: Trace name gets updated after creating a new span

3 participants