Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

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

):
Comment on lines +40 to 41
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Import Optional to satisfy type hints.

Optional is used in the signature but not imported; Flake8 F821.

Add to the typing import:

-from typing import Collection
+from typing import Collection, Optional
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
metadata_key_prefix: Optional[str] = None
):
from typing import Collection, Optional
🧰 Tools
🪛 Ruff (0.12.2)

40-40: Undefined name Optional

(F821)

🪛 Flake8 (7.2.0)

[error] 40-40: undefined name 'Optional'

(F821)

🤖 Prompt for AI Agents
packages/opentelemetry-instrumentation-langchain/opentelemetry/instrumentation/langchain/__init__.py
around lines 40-41: the function signature uses Optional in the type hints but
Optional is not imported, causing Flake8 F821; add Optional to the existing
typing import (e.g., from typing import Any, Dict, Iterable, Optional) at the
top of the file so the type hint is resolved.

"""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]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Copy link
Contributor

Choose a reason for hiding this comment

The 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 from opentelemetry.instrumentation.langchain.config import Config.

value,
)

Expand Down
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
Loading