Skip to content

Commit 51a2bd7

Browse files
committed
style: apply ruff-format fixes
Change-Id: I2b522c578078ebf8ac70d258027906dc1c7c57b5
1 parent 8da1b47 commit 51a2bd7

File tree

5 files changed

+63
-45
lines changed

5 files changed

+63
-45
lines changed

instrumentation-loongsuite/loongsuite-instrumentation-mem0/src/opentelemetry/instrumentation/mem0/internal/_extractors.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ def _extract_input_content(
175175
return None
176176

177177

178-
def _extract_output_preview(result: Any, max_len: Optional[int] = None) -> Optional[str]:
178+
def _extract_output_preview(
179+
result: Any, max_len: Optional[int] = None
180+
) -> Optional[str]:
179181
"""
180182
Extract output content from Memory operation result, returning fields containing content.
181183

instrumentation-loongsuite/loongsuite-instrumentation-mem0/src/opentelemetry/instrumentation/mem0/internal/_wrapper.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,12 @@ def _float_or_none(value: Any) -> float | None:
226226
def _filter_operation_attrs_for_invocation(operation_attrs: dict) -> dict:
227227
"""Remove keys that should be carried by MemoryInvocation fields rather than custom attributes."""
228228
# Strip content keys: content should go to invocation.input_messages/output_messages
229-
operation_attrs.pop(SemanticAttributes.GEN_AI_MEMORY_INPUT_MESSAGES, None)
230-
operation_attrs.pop(SemanticAttributes.GEN_AI_MEMORY_OUTPUT_MESSAGES, None)
229+
operation_attrs.pop(
230+
SemanticAttributes.GEN_AI_MEMORY_INPUT_MESSAGES, None
231+
)
232+
operation_attrs.pop(
233+
SemanticAttributes.GEN_AI_MEMORY_OUTPUT_MESSAGES, None
234+
)
231235
# Strip server info keys: server info should go to invocation.server_address/server_port
232236
operation_attrs.pop(SemanticAttributes.SERVER_ADDRESS, None)
233237
operation_attrs.pop(SemanticAttributes.SERVER_PORT, None)
@@ -265,23 +269,31 @@ def _apply_extracted_attrs_to_invocation(
265269
)
266270

267271
# Map content to invocation fields (let util decide whether to record them)
268-
if (input_msg := operation_attrs.get(
269-
SemanticAttributes.GEN_AI_MEMORY_INPUT_MESSAGES
270-
)) is not None:
272+
if (
273+
input_msg := operation_attrs.get(
274+
SemanticAttributes.GEN_AI_MEMORY_INPUT_MESSAGES
275+
)
276+
) is not None:
271277
invocation.input_messages = input_msg
272-
if (output_msg := operation_attrs.get(
273-
SemanticAttributes.GEN_AI_MEMORY_OUTPUT_MESSAGES
274-
)) is not None:
278+
if (
279+
output_msg := operation_attrs.get(
280+
SemanticAttributes.GEN_AI_MEMORY_OUTPUT_MESSAGES
281+
)
282+
) is not None:
275283
invocation.output_messages = output_msg
276284

277285
# Map server info to invocation fields
278-
if (server_addr := operation_attrs.get(
279-
SemanticAttributes.SERVER_ADDRESS
280-
)) is not None:
286+
if (
287+
server_addr := operation_attrs.get(
288+
SemanticAttributes.SERVER_ADDRESS
289+
)
290+
) is not None:
281291
invocation.server_address = safe_str(server_addr)
282-
if (server_port := operation_attrs.get(
283-
SemanticAttributes.SERVER_PORT
284-
)) is not None:
292+
if (
293+
server_port := operation_attrs.get(
294+
SemanticAttributes.SERVER_PORT
295+
)
296+
) is not None:
285297
try:
286298
invocation.server_port = int(server_port)
287299
except Exception:

instrumentation-loongsuite/loongsuite-instrumentation-mem0/tests/conftest.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,9 @@ def environment():
338338

339339
@pytest.fixture(scope="function")
340340
def instrument_with_content(tracer_provider, meter_provider):
341-
os.environ["OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT"] = "SPAN_ONLY"
341+
os.environ["OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT"] = (
342+
"SPAN_ONLY"
343+
)
342344
instrumentor = Mem0Instrumentor()
343345
instrumentor.instrument(
344346
tracer_provider=tracer_provider, meter_provider=meter_provider
@@ -350,7 +352,9 @@ def instrument_with_content(tracer_provider, meter_provider):
350352

351353
@pytest.fixture(scope="function")
352354
def instrument_no_content(tracer_provider, meter_provider):
353-
os.environ["OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT"] = "NO_CONTENT"
355+
os.environ["OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT"] = (
356+
"NO_CONTENT"
357+
)
354358
instrumentor = Mem0Instrumentor()
355359
instrumentor.instrument(
356360
tracer_provider=tracer_provider, meter_provider=meter_provider
@@ -371,7 +375,9 @@ def instrument_with_factories_patched(
371375
patch_factories(monkeypatch)
372376

373377
# Then instrument (enable internal phase capture)
374-
os.environ["OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT"] = "SPAN_ONLY"
378+
os.environ["OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT"] = (
379+
"SPAN_ONLY"
380+
)
375381
os.environ["OTEL_INSTRUMENTATION_MEM0_INNER_ENABLED"] = "True"
376382
instrumentor = Mem0Instrumentor()
377383
instrumentor.instrument(

instrumentation-loongsuite/loongsuite-instrumentation-mem0/tests/test_memory_client_errors_vcr.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ def test_client_connection_error_vcr(
5555
error_spans = [
5656
s for s in spans if s.status.status_code == StatusCode.ERROR
5757
]
58-
assert error_spans, (
59-
"Should generate at least one top-level span with ERROR status"
60-
)
61-
assert any("error.type" in s.attributes for s in error_spans), (
62-
"Error span should contain error.type"
63-
)
58+
assert (
59+
error_spans
60+
), "Should generate at least one top-level span with ERROR status"
61+
assert any(
62+
"error.type" in s.attributes for s in error_spans
63+
), "Error span should contain error.type"
6464

6565

6666
def _start_test_http_server(status_code: int) -> Tuple[HTTPServer, str]:

instrumentation-loongsuite/loongsuite-instrumentation-mem0/tests/test_memory_operations_vcr.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,7 @@ def test_internal_subphases_attributes(
342342
assert any(
343343
s.attributes.get("gen_ai.memory.vector.method") in valid_vec_methods
344344
for s in vec_spans
345-
), (
346-
f"Vector method should be one of valid values, actual: {[s.attributes.get('gen_ai.memory.vector.method') for s in vec_spans]}"
347-
)
345+
), f"Vector method should be one of valid values, actual: {[s.attributes.get('gen_ai.memory.vector.method') for s in vec_spans]}"
348346
# Verify provider (now uses data_source.type)
349347
assert any(
350348
s.attributes.get("gen_ai.memory.data_source.type") is not None
@@ -360,9 +358,9 @@ def test_internal_subphases_attributes(
360358
if m.reranker is not None:
361359
# If Memory instance has reranker, should be able to collect reranker span
362360
# Because reranker is created via factory, will be instrumented
363-
assert reranker_spans, (
364-
"When reranker exists, should collect reranker stage spans"
365-
)
361+
assert (
362+
reranker_spans
363+
), "When reranker exists, should collect reranker stage spans"
366364
# Verify attributes
367365
assert any(
368366
s.attributes.get("gen_ai.provider.name") is not None
@@ -376,9 +374,9 @@ def test_internal_subphases_attributes(
376374
if s.attributes.get("gen_ai.memory.graph.method") is not None
377375
]
378376
if m.enable_graph:
379-
assert graph_spans, (
380-
"When graph is enabled, should collect graph stage spans"
381-
)
377+
assert (
378+
graph_spans
379+
), "When graph is enabled, should collect graph stage spans"
382380

383381
# 4. LLM and Embedding: do not require generating mem0 subphase spans
384382
# These should be handled by corresponding LLM/Embedding plugins
@@ -440,17 +438,17 @@ def test_vector_operations_detailed_attributes(
440438
or "gen_ai.memory.vector.k" in search_span.attributes
441439
), "search span should contain limit or k"
442440
# Verify filter_keys (note: actual attribute name is filter_keys, not filters.keys)
443-
assert "gen_ai.memory.vector.filter_keys" in search_span.attributes, (
444-
"search span should contain filter_keys"
445-
)
441+
assert (
442+
"gen_ai.memory.vector.filter_keys" in search_span.attributes
443+
), "search span should contain filter_keys"
446444
filter_keys = search_span.attributes.get(
447445
"gen_ai.memory.vector.filter_keys"
448446
)
449447
assert "user_id" in filter_keys, "filter_keys should contain user_id"
450448
# Verify result_count
451-
assert "gen_ai.memory.vector.result_count" in search_span.attributes, (
452-
"search span should contain result_count"
453-
)
449+
assert (
450+
"gen_ai.memory.vector.result_count" in search_span.attributes
451+
), "search span should contain result_count"
454452

455453

456454
@pytest.mark.vcr()
@@ -516,9 +514,9 @@ def test_graph_operations_detailed_attributes(
516514
result_count = add_span.attributes.get(
517515
"gen_ai.memory.graph.result_count"
518516
)
519-
assert result_count is not None and result_count >= 0, (
520-
f"add span should contain result_count, actual value: {result_count}"
521-
)
517+
assert (
518+
result_count is not None and result_count >= 0
519+
), f"add span should contain result_count, actual value: {result_count}"
522520

523521

524522
@pytest.mark.vcr()
@@ -557,9 +555,9 @@ def test_reranker_operations_detailed_attributes(
557555
assert reranker_spans, "should collect reranker spans"
558556

559557
reranker_span = reranker_spans[0]
560-
assert reranker_span.attributes.get("gen_ai.provider.name") == "fake", (
561-
"should contain correct provider.name"
562-
)
558+
assert (
559+
reranker_span.attributes.get("gen_ai.provider.name") == "fake"
560+
), "should contain correct provider.name"
563561
# Now uses gen_ai.rerank.documents_count instead of gen_ai.memory.reranker.input_count
564562
if "gen_ai.rerank.documents_count" in reranker_span.attributes:
565563
documents_count = reranker_span.attributes.get(

0 commit comments

Comments
 (0)