fix(client): pass env var tracing environment to resource manager #1331
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Important
Fixes bug in
client.pyby passingself._environmenttoLangfuseResourceManager, ensuring consistent environment tagging.client.pyby passingself._environmenttoLangfuseResourceManagerinstead of rawenvironmentparameter.sleep(1)intest_openai.pyto ensure proper test execution timing.This description was created by
for 70657a2. You can customize this summary. It will automatically update as commits are pushed.
Disclaimer: Experimental PR review
Greptile Summary
Updated On: 2025-09-10 16:36:03 UTC
This PR fixes a bug in the Langfuse client's environment variable handling. The issue was in the
client.pyfile where theLangfuseResourceManagerwas receiving the rawenvironmentparameter instead of the processedself._environmentvalue.The bug occurred because the client constructor has proper fallback logic that sets
self._environmentto either the provided environment parameter or reads from theLANGFUSE_TRACING_ENVIRONMENTenvironment variable if no explicit environment is provided. However, when initializing theLangfuseResourceManageron line 260, the code was incorrectly passing the unprocessedenvironmentparameter instead ofself._environment.This change ensures consistency between the client and resource manager by making both use the same processed environment value. The fix is critical for maintaining proper environment tagging across traces, generations, and scores, as demonstrated by the test cases in
test_core_sdk.pywhich verify that environment settings are correctly propagated throughout the tracing system.The change integrates seamlessly with the existing codebase architecture where the client acts as the main interface and delegates resource management to the
LangfuseResourceManager. This fix ensures both components operate with the same environment configuration, preventing potential inconsistencies in trace metadata.Confidence score: 5/5