From f63885bb5bb11e149dad14eb31eb1ed6ff509332 Mon Sep 17 00:00:00 2001 From: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com> Date: Mon, 17 Aug 2026 21:57:07 +0100 Subject: [PATCH 1/2] fix(tracing): respect model-data logging redaction --- src/agents/util/_error_tracing.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/agents/util/_error_tracing.py b/src/agents/util/_error_tracing.py index c06a4c6482..230ef3acf2 100644 --- a/src/agents/util/_error_tracing.py +++ b/src/agents/util/_error_tracing.py @@ -5,7 +5,7 @@ from .. import _debug from ..exceptions import ModelTimeoutError -from ..logger import logger +from ..logger import log_model_action_warning, logger from ..tracing import Span, SpanError, get_current_span REDACTED_TRACE_ERROR_MESSAGE = "Error details are redacted." @@ -114,8 +114,12 @@ def record_model_error_on_span( }, ), ) - except Exception: - logger.warning("Could not record the model error on the span", exc_info=True) + except Exception as tracing_error: + log_model_action_warning( + logger, + "Could not record the model error on the span", + tracing_error, + ) @contextlib.contextmanager From 4a24fb429259ab66864f2d43951ff6fd7bac942d Mon Sep 17 00:00:00 2001 From: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com> Date: Mon, 17 Aug 2026 21:57:19 +0100 Subject: [PATCH 2/2] test(tracing): cover redacted annotation failures --- tests/test_model_error_logging_redaction.py | 34 +++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/test_model_error_logging_redaction.py diff --git a/tests/test_model_error_logging_redaction.py b/tests/test_model_error_logging_redaction.py new file mode 100644 index 0000000000..deac487b1c --- /dev/null +++ b/tests/test_model_error_logging_redaction.py @@ -0,0 +1,34 @@ +from __future__ import annotations + +import logging +from typing import Any, cast + +import pytest + +from agents import _debug +from agents.tracing import Span +from agents.util._error_tracing import record_model_error_on_span + + +class _FailingSpan: + def set_error(self, _error: Any) -> None: + raise RuntimeError("span-annotation-secret") + + +def test_model_error_annotation_failure_respects_log_redaction( + monkeypatch: pytest.MonkeyPatch, + caplog: pytest.LogCaptureFixture, +) -> None: + monkeypatch.setattr(_debug, "DONT_LOG_MODEL_DATA", True) + + with caplog.at_level(logging.WARNING, logger="openai.agents"): + record_model_error_on_span( + cast(Span[Any], _FailingSpan()), + message="Error getting response", + error=RuntimeError("model-secret"), + trace_include_sensitive_data=False, + ) + + assert "span-annotation-secret" not in caplog.text + assert "model-secret" not in caplog.text + assert all(record.exc_info is None for record in caplog.records)