Skip to content

Commit 1071ac7

Browse files
committed
fixed according to linter
1 parent cadd51b commit 1071ac7

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/opentelemetry/instrumentation/langchain_v2/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121

2222

2323
class LangChainInstrumentor(BaseInstrumentor):
24+
def __init__(self):
25+
super().__init__()
26+
self.handler = None # Initialize the handler attribute
27+
self._wrapped = []
2428

2529
def instrumentation_dependencies(self) -> Collection[str]:
2630
return _instruments

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/opentelemetry/instrumentation/langchain_v2/callback_handler.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,12 +355,13 @@ def on_chain_end(
355355
_set_span_attribute(span, "gen_ai.completion", str(outputs))
356356
self._end_span(span, run_id)
357357

358+
# pylint: disable=arguments-differ
358359
def on_chain_error(
359360
self,
360361
error: BaseException,
362+
*,
361363
run_id: UUID,
362364
parent_run_id: Optional[UUID] = None,
363-
tags: Optional[list[str]] = None,
364365
**kwargs: Any,
365366
):
366367
self._handle_error(error, run_id, parent_run_id, **kwargs)
@@ -425,14 +426,14 @@ def on_tool_end(
425426
def on_tool_error(
426427
self,
427428
error: BaseException,
429+
*,
428430
run_id: UUID,
429431
parent_run_id: Optional[UUID] = None,
430-
tags: Optional[list[str]] = None,
431432
**kwargs: Any,
432433
):
433434
self._handle_error(error, run_id, parent_run_id, **kwargs)
434435

435-
def on_agent_action(self, action: AgentAction, run_id: UUID, parent_run_id: UUID, **kwargs: Any):
436+
def on_agent_action(self, action: AgentAction, *, run_id: UUID, parent_run_id: UUID, **kwargs: Any):
436437
tool = getattr(action, "tool", None)
437438
tool_input = getattr(action, "tool_input", None)
438439

@@ -443,7 +444,7 @@ def on_agent_action(self, action: AgentAction, run_id: UUID, parent_run_id: UUID
443444
_set_span_attribute(span, "gen_ai.agent.tool.name", tool)
444445
_set_span_attribute(span, SpanAttributes.GEN_AI_OPERATION_NAME, "invoke_agent")
445446

446-
def on_agent_finish(self, finish: AgentFinish, run_id: UUID, parent_run_id: UUID, **kwargs: Any):
447+
def on_agent_finish(self, finish: AgentFinish, *, run_id: UUID, parent_run_id: UUID, **kwargs: Any):
447448

448449
span = self.span_mapping[run_id].span
449450

aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test-opentelemetry-instrumentation-langchain-v2/mock_agents.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,13 @@ def mock_prompt():
6060
)
6161

6262

63-
def test_agents(instrument_langchain, span_exporter, mock_model, mock_search_tool, mock_prompt):
64-
tools = [mock_search_tool]
63+
def test_agents(
64+
instrument_langchain, span_exporter, model_fixture, search_tool_fixture, prompt_fixture
65+
): # Changed parameter names
66+
# pylint: disable=redefined-outer-name
67+
tools = [search_tool_fixture] # Use renamed parameter
6568

66-
agent = create_tool_calling_agent(mock_model, tools, mock_prompt)
69+
agent = create_tool_calling_agent(model_fixture, tools, prompt_fixture) # Use renamed parameters
6770
agent_executor = AgentExecutor(agent=agent, tools=tools)
6871

6972
# Mock the agent's intermediate steps
@@ -90,11 +93,12 @@ def test_agents(instrument_langchain, span_exporter, mock_model, mock_search_too
9093

9194

9295
def test_agents_with_events_with_content(
93-
instrument_with_content, span_exporter, mock_model, mock_search_tool, mock_prompt
96+
instrument_with_content, span_exporter, model_param, search_tool_param, prompt_param # Changed parameter names
9497
):
95-
tools = [mock_search_tool]
98+
# pylint: disable=redefined-outer-name
99+
tools = [search_tool_param] # Use renamed parameter
96100

97-
agent = create_tool_calling_agent(mock_model, tools, mock_prompt)
101+
agent = create_tool_calling_agent(model_param, tools, prompt_param) # Use renamed parameters
98102
agent_executor = AgentExecutor(agent=agent, tools=tools)
99103

100104
with patch("langchain.agents.AgentExecutor._iter_next_step") as mock_iter:
@@ -120,11 +124,12 @@ def test_agents_with_events_with_content(
120124

121125

122126
def test_agents_with_events_with_no_content(
123-
instrument_langchain, span_exporter, mock_model, mock_search_tool, mock_prompt
127+
instrument_langchain, span_exporter, model_input, search_tool_input, prompt_input # Changed parameter names
124128
):
125-
tools = [mock_search_tool]
129+
# pylint: disable=redefined-outer-name
130+
tools = [search_tool_input] # Use renamed parameter
126131

127-
agent = create_tool_calling_agent(mock_model, tools, mock_prompt)
132+
agent = create_tool_calling_agent(model_input, tools, prompt_input) # Use renamed parameters
128133
agent_executor = AgentExecutor(agent=agent, tools=tools)
129134

130135
with patch("langchain.agents.AgentExecutor._iter_next_step") as mock_iter:

aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/test-opentelemetry-instrumentation-langchain-v2/mock_langgraph_agent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ async def test_langgraph_ainvoke(instrument_langchain, span_exporter):
2121
# Mock the boto3 client
2222
with patch("boto3.client", autospec=True):
2323
# Mock the ChatBedrock client
24-
with patch("langchain_aws.chat_models.ChatBedrock", autospec=True) as MockChatBedrock:
24+
with patch("langchain_aws.chat_models.ChatBedrock", autospec=True) as mock_chat_bedrock:
2525
# Create a mock instance that will be returned by the constructor
2626
mock_client = MagicMock()
27-
MockChatBedrock.return_value = mock_client
27+
mock_chat_bedrock.return_value = mock_client
2828

2929
# Set up the response for the invoke method
3030
mock_response = AIMessage(content="The answer is 10.")

0 commit comments

Comments
 (0)