|
34 | 34 |
|
35 | 35 | from opentelemetry.trace import Link, SpanContext, SpanKind, TraceFlags |
36 | 36 | from opentelemetry.trace.propagation import _SPAN_KEY |
| 37 | +from opentelemetry.trace.status import Status, StatusCode |
37 | 38 |
|
38 | 39 | import elasticapm.contrib.opentelemetry.context as context |
39 | 40 | import elasticapm.contrib.opentelemetry.trace as trace |
@@ -155,4 +156,52 @@ def test_span_links(tracer: Tracer): |
155 | 156 | assert span["links"][0]["span_id"] == "0011223344556677" |
156 | 157 |
|
157 | 158 |
|
158 | | -# TODO Add some span subtype testing? |
| 159 | +def test_set_status_with_status_object(tracer: Tracer): |
| 160 | + """Test set_status with Status object (original API)""" |
| 161 | + with tracer.start_as_current_span("test") as span: |
| 162 | + span.set_status(Status(StatusCode.OK)) |
| 163 | + |
| 164 | + client = tracer.client |
| 165 | + transaction = client.events[constants.TRANSACTION][0] |
| 166 | + assert transaction["outcome"] == "success" |
| 167 | + |
| 168 | + |
| 169 | +def test_set_status_with_status_code(tracer: Tracer): |
| 170 | + """Test set_status with StatusCode enum (new API)""" |
| 171 | + with tracer.start_as_current_span("test") as span: |
| 172 | + span.set_status(StatusCode.ERROR) |
| 173 | + |
| 174 | + client = tracer.client |
| 175 | + transaction = client.events[constants.TRANSACTION][0] |
| 176 | + assert transaction["outcome"] == "failure" |
| 177 | + |
| 178 | + |
| 179 | +def test_set_status_with_status_code_and_description(tracer: Tracer): |
| 180 | + """Test set_status with StatusCode enum and optional description""" |
| 181 | + with tracer.start_as_current_span("test") as span: |
| 182 | + span.set_status(StatusCode.OK, "Everything is fine") |
| 183 | + |
| 184 | + client = tracer.client |
| 185 | + transaction = client.events[constants.TRANSACTION][0] |
| 186 | + assert transaction["outcome"] == "success" |
| 187 | + |
| 188 | + |
| 189 | +def test_set_status_unset(tracer: Tracer): |
| 190 | + """Test set_status with UNSET status code""" |
| 191 | + with tracer.start_as_current_span("test") as span: |
| 192 | + span.set_status(StatusCode.UNSET) |
| 193 | + |
| 194 | + client = tracer.client |
| 195 | + transaction = client.events[constants.TRANSACTION][0] |
| 196 | + assert transaction["outcome"] == "unknown" |
| 197 | + |
| 198 | + |
| 199 | +def test_set_status_on_span(tracer: Tracer): |
| 200 | + """Test set_status on a child span (not transaction)""" |
| 201 | + with tracer.start_as_current_span("test"): |
| 202 | + with tracer.start_as_current_span("testspan") as span: |
| 203 | + span.set_status(StatusCode.ERROR) |
| 204 | + |
| 205 | + client = tracer.client |
| 206 | + span_event = client.events[constants.SPAN][0] |
| 207 | + assert span_event["outcome"] == "failure" |
0 commit comments