-
Notifications
You must be signed in to change notification settings - Fork 808
feat(langchain): allow configuration of metadata key prefix #3367
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 all commits
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 | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -37,10 +37,24 @@ def __init__( | |||||||
exception_logger=None, | ||||||||
disable_trace_context_propagation=False, | ||||||||
use_legacy_attributes: bool = True, | ||||||||
metadata_key_prefix: Optional[str] = None | ||||||||
): | ||||||||
Comment on lines
+40
to
41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Import Optional to satisfy type hints.
Add to the typing import: -from typing import Collection
+from typing import Collection, Optional 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Ruff (0.12.2)40-40: Undefined name (F821) 🪛 Flake8 (7.2.0)[error] 40-40: undefined name 'Optional' (F821) 🤖 Prompt for AI Agents
|
||||||||
"""Create a Langchain instrumentor instance. | ||||||||
|
||||||||
Args: | ||||||||
exception_logger: A callable that takes an Exception as input. This will be | ||||||||
used to log exceptions that occur during instrumentation. If None, exceptions will not be logged. | ||||||||
disable_trace_context_propagation: If True, disables trace context propagation to LLM providers. | ||||||||
use_legacy_attributes: If True, uses span attributes for Inputs/Outputs instead of events. | ||||||||
metadata_key_prefix: Prefix for metadata keys added to spans. If None, defaults to | ||||||||
`SpanAttributes.TRACELOOP_ASSOCIATION_PROPERTIES`. | ||||||||
Useful for using with other backends. | ||||||||
""" | ||||||||
super().__init__() | ||||||||
Config.exception_logger = exception_logger | ||||||||
Config.use_legacy_attributes = use_legacy_attributes | ||||||||
if metadata_key_prefix: | ||||||||
Config.metadata_key_prefix = metadata_key_prefix | ||||||||
self.disable_trace_context_propagation = disable_trace_context_propagation | ||||||||
|
||||||||
def instrumentation_dependencies(self) -> Collection[str]: | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -290,7 +290,7 @@ def _create_span( | |
for key, value in sanitized_metadata.items(): | ||
_set_span_attribute( | ||
span, | ||
f"{SpanAttributes.TRACELOOP_ASSOCIATION_PROPERTIES}.{key}", | ||
f"{Config.metadata_key_prefix}.{key}", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The 'Config' object is used for constructing the metadata attribute key, but it is not imported in this file. Please add |
||
value, | ||
) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
from typing import Optional | ||
|
||
from opentelemetry._events import EventLogger | ||
|
||
from opentelemetry.semconv_ai import SpanAttributes | ||
|
||
class Config: | ||
exception_logger = None | ||
use_legacy_attributes = True | ||
event_logger: Optional[EventLogger] = None | ||
metadata_key_prefix: str = SpanAttributes.TRACELOOP_ASSOCIATION_PROPERTIES |
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.
this should default to the way it works tdoay