Skip to content

Commit a2d2396

Browse files
authored
feat: use non-deprecated variant of code span attributes (#134)
The `SpanAttributes` enum we use, from `opentelemetry` lib, is using the deprecated variant of the span attributes for the `code` section. https://opentelemetry.io/docs/specs/semconv/registry/attributes/code/#code-attributes
1 parent 9957d7b commit a2d2396

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

pytest_mergify/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import _pytest.reports
1111
import _pytest.config
1212
import _pytest.config.argparsing
13+
import _pytest.pathlib
1314
import _pytest.nodes
1415
import _pytest.terminal
1516
import opentelemetry.trace
@@ -106,11 +107,15 @@ def _attributes_from_item(
106107
namespace = testname.replace(item.name, "")
107108
if namespace.endswith("."):
108109
namespace = namespace[:-1]
110+
109111
return {
110112
SpanAttributes.CODE_FILEPATH: filepath,
111113
SpanAttributes.CODE_FUNCTION: item.name,
112114
SpanAttributes.CODE_LINENO: line_number or 0,
113115
SpanAttributes.CODE_NAMESPACE: namespace,
116+
"code.function.name": item.nodeid,
117+
"code.file.path": str(_pytest.pathlib.absolutepath(item.reportinfo()[0])),
118+
"code.line.number": line_number or 0,
114119
}
115120

116121
@pytest.hookimpl(hookwrapper=True)

tests/test_spans.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import opentelemetry.trace
2+
import anys
23
from opentelemetry.semconv.trace import SpanAttributes
34

45
import pytest
@@ -51,6 +52,9 @@ def test_test(
5152
"code.filepath": "test_test.py",
5253
"code.namespace": "",
5354
"test.case.result.status": "passed",
55+
"code.file.path": anys.ANY_STR,
56+
"code.function.name": "test_test.py::test_pass",
57+
"code.line.number": 0,
5458
}
5559
assert spans["test_pass"].status.status_code == opentelemetry.trace.StatusCode.OK
5660
assert session_span.context is not None
@@ -79,6 +83,9 @@ def test_test_failure(
7983
E assert False
8084
8185
test_test_failure.py:1: AssertionError""",
86+
"code.file.path": anys.ANY_STR,
87+
"code.function.name": "test_test_failure.py::test_error",
88+
"code.line.number": 0,
8289
}
8390
assert (
8491
spans["test_error"].status.status_code == opentelemetry.trace.StatusCode.ERROR
@@ -110,6 +117,9 @@ def test_skipped():
110117
"code.lineno": 1,
111118
"code.filepath": "test_test_skipped.py",
112119
"code.namespace": "",
120+
"code.file.path": anys.ANY_STR,
121+
"code.function.name": "test_test_skipped.py::test_skipped",
122+
"code.line.number": 1,
113123
}
114124
assert spans["test_skipped"].status.status_code == opentelemetry.trace.StatusCode.OK
115125
assert session_span.context is not None
@@ -147,6 +157,9 @@ def test_skipped():
147157
"code.lineno": 1,
148158
"code.filepath": "test_mark_skipped.py",
149159
"code.namespace": "",
160+
"code.file.path": anys.ANY_STR,
161+
"code.function.name": "test_mark_skipped.py::test_skipped",
162+
"code.line.number": 1,
150163
}
151164
assert (
152165
spans["test_skipped"].status.status_code == opentelemetry.trace.StatusCode.UNSET
@@ -175,6 +188,9 @@ def test_not_skipped():
175188
"code.lineno": 1,
176189
"code.filepath": "test_mark_not_skipped.py",
177190
"code.namespace": "",
191+
"code.file.path": anys.ANY_STR,
192+
"code.function.name": "test_mark_not_skipped.py::test_not_skipped",
193+
"code.line.number": 1,
178194
}
179195
assert (
180196
spans["test_not_skipped"].status.status_code

0 commit comments

Comments
 (0)