-
Notifications
You must be signed in to change notification settings - Fork 810
fix(langchain): callback handler overwrites custom names for task and w… #3324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -27,6 +27,7 @@ | |||||||||||||||||||||
LLMResult, | ||||||||||||||||||||||
) | ||||||||||||||||||||||
from opentelemetry import context as context_api | ||||||||||||||||||||||
from opentelemetry.context import get_value | ||||||||||||||||||||||
from opentelemetry.instrumentation.langchain.event_emitter import emit_event | ||||||||||||||||||||||
from opentelemetry.instrumentation.langchain.event_models import ( | ||||||||||||||||||||||
ChoiceEvent, | ||||||||||||||||||||||
|
@@ -391,6 +392,10 @@ def on_chain_start( | |||||||||||||||||||||
if context_api.get_value(_SUPPRESS_INSTRUMENTATION_KEY): | ||||||||||||||||||||||
return | ||||||||||||||||||||||
|
||||||||||||||||||||||
# Check for existing Traceloop context first | ||||||||||||||||||||||
existing_workflow_name = get_value("workflow_name") | ||||||||||||||||||||||
existing_entity_path = get_value("entity_path") | ||||||||||||||||||||||
|
||||||||||||||||||||||
workflow_name = "" | ||||||||||||||||||||||
entity_path = "" | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
@@ -402,7 +407,9 @@ def on_chain_start( | |||||||||||||||||||||
) | ||||||||||||||||||||||
|
||||||||||||||||||||||
if kind == TraceloopSpanKindValues.WORKFLOW: | ||||||||||||||||||||||
workflow_name = name | ||||||||||||||||||||||
# Respect existing Traceloop decorator context if present | ||||||||||||||||||||||
workflow_name = existing_workflow_name or name | ||||||||||||||||||||||
entity_path = existing_entity_path or "" | ||||||||||||||||||||||
else: | ||||||||||||||||||||||
workflow_name = self.get_workflow_name(parent_run_id) | ||||||||||||||||||||||
entity_path = self.get_entity_path(parent_run_id) | ||||||||||||||||||||||
|
@@ -724,6 +731,11 @@ def get_workflow_name(self, parent_run_id: str): | |||||||||||||||||||||
return parent_span.workflow_name | ||||||||||||||||||||||
|
||||||||||||||||||||||
def get_entity_path(self, parent_run_id: str): | ||||||||||||||||||||||
# Check for existing Traceloop context first | ||||||||||||||||||||||
existing_entity_path = get_value("entity_path") | ||||||||||||||||||||||
if existing_entity_path: | ||||||||||||||||||||||
return existing_entity_path | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
# Check for existing Traceloop context first | |
existing_entity_path = get_value("entity_path") | |
if existing_entity_path: | |
return existing_entity_path | |
# Check for existing Traceloop context first | |
existing_entity_path = context_api.get_value("entity_path") | |
# Important: honor empty string ("") as a valid, explicit root path | |
if existing_entity_path is not None: | |
return existing_entity_path |
🤖 Prompt for AI Agents
In
packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/callback_handler.py
around lines 734 to 738, the code uses a truthy check on existing_entity_path
which treats an explicitly empty string ("") as false and incorrectly falls back
to deriving a path; change the condition to check `is not None` so that an
intentionally empty string is preserved (i.e., if get_value("entity_path") is
not None: return that value), and if you implement this change remove the
now-unnecessary direct get_value import noted earlier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New import of get_value is added. Consider using a consistent approach (e.g., context_api.get_value) throughout the file for clarity.