Skip to content
Merged
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
18 changes: 18 additions & 0 deletions tests/test_tracing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import pytest
from opentelemetry import trace
from opentelemetry.trace import StatusCode

Expand Down Expand Up @@ -245,3 +246,20 @@ def test_send_error_with_context(spans):
assert event.name == "exception"
assert event.attributes["exception.type"] == "tests.test_tracing.FooError"
assert event.attributes["exception.message"] == "Whoops!"


def test_send_error_with_context_closes_span_when_block_raises(spans):
# An error raised inside the `with` block bubbles out to the caller, but the
# error span is still ended and exported.
with pytest.raises(RuntimeError, match="Kaboom!"):
with send_error_with_context(raised_error()):
raise RuntimeError("Kaboom!")

span = spans()[0]
assert span.name == "FooError"
assert span.status.status_code == StatusCode.ERROR

event = span.events[0]
assert event.name == "exception"
assert event.attributes["exception.type"] == "tests.test_tracing.FooError"
assert event.attributes["exception.message"] == "Whoops!"
Loading