Skip to content

Commit 6a71890

Browse files
committed
fix: satisfy misc ci checks
1 parent a55f07a commit 6a71890

5 files changed

Lines changed: 28 additions & 11 deletions

File tree

instrumentation-genai/opentelemetry-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/callback_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def on_chat_model_start(
115115
for sub_messages in messages:
116116
for message in sub_messages:
117117
# Cast to Any to avoid type checking issues with LangChain's complex content type
118-
raw_content: Any = message.content # type: ignore[misc]
118+
raw_content: Any = message.content
119119
role = message.type
120120
parts: list[Text] = []
121121

instrumentation-loongsuite/loongsuite-instrumentation-langchain/src/opentelemetry/instrumentation/langchain/internal/_tracer.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,9 @@ def _start_chain(self, run: Run) -> None:
436436

437437
# Attach chain span context so non-LangChain children nest correctly.
438438
current_context = (
439-
parent_ctx if parent_ctx is not None else otel_context.get_current()
439+
parent_ctx
440+
if parent_ctx is not None
441+
else otel_context.get_current()
440442
)
441443
ctx = set_span_in_context(span, current_context)
442444
token = otel_context.attach(ctx)
@@ -725,7 +727,9 @@ def _enter_react_step(self, agent_run_id: UUID) -> None:
725727
self._handler.start_react_step(inv, context=agent_rd.original_context)
726728

727729
step_ctx = (
728-
otel_context.get_current() if inv.span else agent_rd.original_context
730+
otel_context.get_current()
731+
if inv.span
732+
else agent_rd.original_context
729733
)
730734
agent_rd.active_step = _RunData(
731735
run_kind="react_step",

instrumentation-loongsuite/loongsuite-instrumentation-langchain/tests/test_agent_spans.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ def test_agent_context_colors_child_llm_and_tool_spans(
116116

117117
spans = span_exporter.get_finished_spans()
118118
llm_span = next(span for span in spans if span.name == "chat gpt-4o-mini")
119-
tool_span = next(span for span in spans if span.name == "execute_tool search")
119+
tool_span = next(
120+
span for span in spans if span.name == "execute_tool search"
121+
)
120122

121123
assert llm_span.attributes[GenAI.GEN_AI_AGENT_NAME] == "AgentExecutor"
122124
assert tool_span.attributes[GenAI.GEN_AI_AGENT_NAME] == "AgentExecutor"

util/opentelemetry-util-genai/src/opentelemetry/util/genai/handler.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
import logging
6565
import timeit
6666
from contextlib import contextmanager
67-
from typing import Iterator
67+
from typing import Any, Iterator, Protocol
6868

6969
from opentelemetry import baggage
7070
from opentelemetry import context as otel_context
@@ -96,7 +96,6 @@
9696
)
9797
from opentelemetry.util.genai.types import (
9898
Error,
99-
GenAIInvocation,
10099
LLMInvocation,
101100
)
102101
from opentelemetry.util.genai.version import __version__
@@ -106,7 +105,13 @@
106105

107106
# Aliyun Python Agent Extension
108107
_AUTO_INJECT_BAGGAGE_PREFIX = "traffic.llm_sdk."
109-
_AGENT_NAME_BAGGAGE_KEY = f"{_AUTO_INJECT_BAGGAGE_PREFIX}{GenAI.GEN_AI_AGENT_NAME}"
108+
_AGENT_NAME_BAGGAGE_KEY = (
109+
f"{_AUTO_INJECT_BAGGAGE_PREFIX}{GenAI.GEN_AI_AGENT_NAME}"
110+
)
111+
112+
113+
class _InvocationWithAttributes(Protocol):
114+
attributes: dict[str, Any]
110115

111116

112117
# LoongSuite Extension
@@ -135,7 +140,7 @@ def _current_context(context: Context | None = None) -> Context:
135140

136141

137142
def _inject_agent_name_from_baggage(
138-
invocation: GenAIInvocation, context: Context
143+
invocation: _InvocationWithAttributes, context: Context
139144
) -> None:
140145
if GenAI.GEN_AI_AGENT_NAME in invocation.attributes:
141146
return

util/opentelemetry-util-genai/tests/test_extended_handler.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -711,8 +711,12 @@ def test_agent_context_colors_llm_and_tool_spans(self):
711711
self.telemetry_handler.stop_invoke_agent(agent_invocation)
712712

713713
spans = self.span_exporter.get_finished_spans()
714-
llm_span = next(span for span in spans if span.name == "chat gpt-4o-mini")
715-
tool_span = next(span for span in spans if span.name == "execute_tool search")
714+
llm_span = next(
715+
span for span in spans if span.name == "chat gpt-4o-mini"
716+
)
717+
tool_span = next(
718+
span for span in spans if span.name == "execute_tool search"
719+
)
716720
self.assertEqual(
717721
llm_span.attributes.get(GenAI.GEN_AI_AGENT_NAME),
718722
"PlannerAgent",
@@ -744,7 +748,9 @@ def test_explicit_agent_parent_context_colors_llm_span(self):
744748
self.telemetry_handler.stop_invoke_agent(agent_invocation)
745749

746750
spans = self.span_exporter.get_finished_spans()
747-
llm_span = next(span for span in spans if span.name == "chat gpt-4o-mini")
751+
llm_span = next(
752+
span for span in spans if span.name == "chat gpt-4o-mini"
753+
)
748754
self.assertEqual(
749755
llm_span.attributes.get(GenAI.GEN_AI_AGENT_NAME),
750756
"ExplicitParentAgent",

0 commit comments

Comments
 (0)