85742ab165
Deploy Documentation / deploy (push) Has been cancelled
CPU Test / Test (Utilities, legacy, Python 3.10) (push) Has been cancelled
CPU Test / Test (LLM proxy, stable, Python 3.11) (push) Has been cancelled
CPU Test / Test (Others, stable, Python 3.11) (push) Has been cancelled
CPU Test / Test (Store, stable, Python 3.11) (push) Has been cancelled
CPU Test / Test (Utilities, stable, Python 3.11) (push) Has been cancelled
CPU Test / Test (Weave, stable, Python 3.11) (push) Has been cancelled
CPU Test / Test (AgentOps, stable, Python 3.12) (push) Has been cancelled
CPU Test / Test (LLM proxy, stable, Python 3.12) (push) Has been cancelled
CPU Test / Test (Others, stable, Python 3.12) (push) Has been cancelled
CPU Test / Test (Weave, latest, Python 3.13) (push) Has been cancelled
Dashboard / Chromatic (push) Has been cancelled
CPU Test / Lint - fast (push) Has been cancelled
CPU Test / Lint - next (push) Has been cancelled
CPU Test / Lint - slow (push) Has been cancelled
CPU Test / Lint - JavaScript (push) Has been cancelled
CPU Test / Build documentation (push) Has been cancelled
CPU Test / Test (AgentOps, legacy, Python 3.10) (push) Has been cancelled
CPU Test / Test (LLM proxy, legacy, Python 3.10) (push) Has been cancelled
CPU Test / Test (Others, legacy, Python 3.10) (push) Has been cancelled
CPU Test / Test (Store, legacy, Python 3.10) (push) Has been cancelled
CPU Test / Test (Weave, legacy, Python 3.10) (push) Has been cancelled
CPU Test / Test (AgentOps, stable, Python 3.11) (push) Has been cancelled
CPU Test / Test (Store, stable, Python 3.12) (push) Has been cancelled
CPU Test / Test (Utilities, stable, Python 3.12) (push) Has been cancelled
CPU Test / Test (Weave, stable, Python 3.12) (push) Has been cancelled
CPU Test / Test (AgentOps, latest, Python 3.13) (push) Has been cancelled
CPU Test / Test (LLM proxy, latest, Python 3.13) (push) Has been cancelled
CPU Test / Test (Others, latest, Python 3.13) (push) Has been cancelled
CPU Test / Test (Store, latest, Python 3.13) (push) Has been cancelled
CPU Test / Test (Utilities, latest, Python 3.13) (push) Has been cancelled
CPU Test / Test (JavaScript) (push) Has been cancelled
56 lines
2.0 KiB
Python
56 lines
2.0 KiB
Python
# Copyright (c) Microsoft. All rights reserved.
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
from opentelemetry.semconv.attributes import exception_attributes
|
|
|
|
from agentlightning.emitter import emit_exception
|
|
from agentlightning.emitter import exception as exception_module
|
|
from agentlightning.semconv import AGL_EXCEPTION
|
|
|
|
from ..common.tracer import RecordingDummyTracer
|
|
|
|
|
|
def _install_tracer(monkeypatch: pytest.MonkeyPatch) -> RecordingDummyTracer:
|
|
tracer = RecordingDummyTracer()
|
|
monkeypatch.setattr(exception_module, "get_active_tracer", lambda: tracer)
|
|
return tracer
|
|
|
|
|
|
def test_emit_exception_records_exception(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
tracer = _install_tracer(monkeypatch)
|
|
err = ValueError("boom")
|
|
|
|
emit_exception(err)
|
|
|
|
assert tracer.last_span is not None
|
|
assert tracer.last_span.name == AGL_EXCEPTION
|
|
assert tracer.last_span.attributes[exception_attributes.EXCEPTION_TYPE] == "ValueError"
|
|
assert tracer.last_span.attributes[exception_attributes.EXCEPTION_MESSAGE] == "boom"
|
|
assert tracer.last_span.attributes[exception_attributes.EXCEPTION_ESCAPED] is True
|
|
|
|
|
|
def test_emit_exception_requires_exception_instance() -> None:
|
|
with pytest.raises(TypeError):
|
|
emit_exception("boom") # type: ignore[arg-type]
|
|
|
|
|
|
def test_emit_exception_flattens_attributes(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
tracer = _install_tracer(monkeypatch)
|
|
|
|
emit_exception(ValueError("boom"), attributes={"meta": {"tag": "foo"}, "labels": ["x"]})
|
|
|
|
assert tracer.last_span is not None
|
|
assert tracer.last_span.attributes["meta.tag"] == "foo"
|
|
assert tracer.last_span.attributes["labels"] == ["x"]
|
|
|
|
|
|
def test_emit_exception_propagate_false(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
def fail_get_active_tracer() -> RecordingDummyTracer:
|
|
raise AssertionError("Should not resolve tracer when propagate=False")
|
|
|
|
monkeypatch.setattr(exception_module, "get_active_tracer", fail_get_active_tracer)
|
|
|
|
emit_exception(ValueError("boom"), propagate=False)
|