fix(llmobs): move listener hooks to enable instead of on init #11889
+40
−4
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.
Follow up on #11781 to fix a weird duplicate span writing issue with the new listener hook logic.
Since we were registering these hooks on
LLMObs.__init__()
which also happens at startup (as we create a default LLMObs() instance) as well as onLLMObs.enable()
, we were double registering these hooks, and the default LLMObsSpanWriter was still saved and called each time the tracer finished a span. A symptom of this issue is that if a user was to manually enable agentless mode, they would see noisy logs indicating a failure to send spans to the agent proxy endpoint (which is the default writer mode) even though they also submitted spans to the agentless endpoint succesfully.This fix resolves the issue by moving the hook registering to
LLMObs.enable()
, and adding corresponding logic to deregister the hooks on_stop_service()
. This way we should only ever have one set of hooks registered per process.Checklist
Reviewer Checklist