Skip to content
Merged
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
10 changes: 7 additions & 3 deletions src/agents/util/_error_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions tests/test_model_error_logging_redaction.py
Original file line number Diff line number Diff line change
@@ -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)
Loading