Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Digma
Copy link
Contributor

@Digma Digma commented Aug 20, 2025

Fixes langfuse/langfuse#8619

Another approach would be passing the environment starting from the call to LangfuseGeneration in start_generation. Not sure which one is the best fix


Important

In LangfuseSpanWrapper.__init__(), fallback to langfuse_client._environment if environment is not provided.

  • Behavior:
    • In LangfuseSpanWrapper.__init__(), set _environment to environment or fallback to langfuse_client._environment if not provided.

This description was created by Ellipsis for a197b67. You can customize this summary. It will automatically update as commits are pushed.

Disclaimer: Experimental PR review

Greptile Summary

This PR fixes a bug where span wrappers were losing their environment context when no environment parameter was explicitly provided during span creation. The change implements a simple fallback mechanism in the Span constructor at line 111, changing from self._environment = environment to self._environment = environment or langfuse_client._environment.

The issue occurred because the Langfuse client stores its environment setting in the _environment attribute (as configured via constructor or environment variables like LANGFUSE_TRACING_ENVIRONMENT), but when creating spans in a trace hierarchy, this environment wasn't being automatically inherited by child spans unless explicitly passed down through all method calls.

This fix ensures that all spans within a trace maintain consistent environment settings by falling back to the client's configured environment when none is explicitly provided. This is critical for proper trace organization in Langfuse, as the environment field is used for categorizing and filtering traces in the UI. The solution is minimal and non-breaking - it only affects spans where no environment is explicitly set, maintaining backward compatibility while fixing the inheritance issue.

The change integrates well with the existing codebase architecture where the client acts as the central configuration holder, and spans should naturally inherit these settings unless overridden.

Confidence score: 5/5

  • This PR is safe to merge with minimal risk as it's a simple fallback mechanism that doesn't change existing behavior
  • Score reflects the straightforward nature of the fix and its alignment with expected inheritance patterns
  • No files require special attention as the change is isolated and well-contained

@CLAassistant
Copy link

CLAassistant commented Aug 20, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, no comments

Edit Code Review Bot Settings | Greptile

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
@hassiebp hassiebp self-requested a review August 25, 2025 08:35
@hassiebp hassiebp merged commit a43873e into langfuse:main Aug 27, 2025
1 check passed
@hassiebp
Copy link
Contributor

Thanks for your contribution, @Digma !

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: Lost environment context when using .start_generation
3 participants