Skip to content

Commit b07b3cf

Browse files
authored
Test emitting both new and old semantic convention attribute names (#340)
1 parent 76834a1 commit b07b3cf

File tree

11 files changed

+276
-0
lines changed

11 files changed

+276
-0
lines changed

logfire/_internal/scrubbing.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ class BaseScrubber(ABC):
124124
SpanAttributes.HTTP_ROUTE,
125125
SpanAttributes.DB_STATEMENT,
126126
'db.plan',
127+
# Newer semantic conventions
128+
SpanAttributes.URL_FULL,
129+
SpanAttributes.URL_PATH,
130+
SpanAttributes.URL_QUERY,
127131
}
128132

129133
@abstractmethod

tests/conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
from logfire._internal.config import METRICS_PREFERRED_TEMPORALITY
1717
from logfire.testing import IncrementalIdGenerator, TestExporter, TimeGenerator
1818

19+
# Emit both new and old semantic convention attribute names
20+
os.environ['OTEL_SEMCONV_STABILITY_OPT_IN'] = 'http/dup'
21+
1922

2023
@pytest.fixture(scope='session', autouse=True)
2124
def anyio_backend():

tests/otel_integrations/test_asgi.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def homepage(_: Request):
6565
'http.status_code': 200,
6666
'asgi.event.type': 'http.response.start',
6767
'logfire.level_num': 5,
68+
'http.response.status_code': 200,
6869
},
6970
},
7071
{
@@ -90,17 +91,28 @@ def homepage(_: Request):
9091
'logfire.span_type': 'span',
9192
'logfire.msg': 'GET /',
9293
'http.scheme': 'http',
94+
'url.scheme': 'http',
9395
'http.host': 'testserver',
96+
'server.address': 'testserver',
9497
'net.host.port': 80,
98+
'server.port': 80,
9599
'http.flavor': '1.1',
100+
'network.protocol.version': '1.1',
96101
'http.target': '/',
102+
'url.path': '/',
97103
'http.url': 'http://testserver/',
104+
'url.full': 'http://testserver/',
98105
'http.method': 'GET',
106+
'http.request.method': 'GET',
99107
'http.server_name': 'testserver',
100108
'http.user_agent': 'testclient',
109+
'user_agent.original': 'testclient',
101110
'net.peer.ip': 'testclient',
111+
'client.address': 'testclient',
102112
'net.peer.port': 50000,
113+
'client.port': 50000,
103114
'http.status_code': 200,
115+
'http.response.status_code': 200,
104116
},
105117
},
106118
{

tests/otel_integrations/test_django.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ def test_good_route(client: Client, exporter: TestExporter, metrics_reader: InMe
3838
'http.server_name': 'testserver',
3939
'http.scheme': 'http',
4040
'http.flavor': '1.1',
41+
'http.request.method': 'GET',
42+
'url.scheme': 'http',
4143
},
4244
'start_time_unix_nano': IsInt(),
4345
'time_unix_nano': IsInt(),
@@ -79,6 +81,36 @@ def test_good_route(client: Client, exporter: TestExporter, metrics_reader: InMe
7981
'aggregation_temporality': 1,
8082
},
8183
},
84+
{
85+
'name': 'http.server.request.duration',
86+
'description': 'Duration of HTTP server requests.',
87+
'unit': 's',
88+
'data': {
89+
'data_points': [
90+
{
91+
'attributes': {
92+
'http.request.method': 'GET',
93+
'url.scheme': 'http',
94+
'network.protocol.version': '1.1',
95+
'http.route': 'django_test_app/<int:item_id>/',
96+
'http.response.status_code': 200,
97+
},
98+
'start_time_unix_nano': IsInt(),
99+
'time_unix_nano': IsInt(),
100+
'count': 1,
101+
'sum': IsNumeric(),
102+
'scale': 20,
103+
'zero_count': 0,
104+
'positive': {'offset': IsInt(), 'bucket_counts': [1]},
105+
'negative': {'offset': 0, 'bucket_counts': [0]},
106+
'flags': 0,
107+
'min': IsNumeric(),
108+
'max': IsNumeric(),
109+
}
110+
],
111+
'aggregation_temporality': 1,
112+
},
113+
},
82114
]
83115
)
84116

@@ -95,14 +127,20 @@ def test_good_route(client: Client, exporter: TestExporter, metrics_reader: InMe
95127
'logfire.span_type': 'span',
96128
'logfire.msg': "GET /django_test_app/123/ ? foo='1' & very_long…aram_name='very long…ram value'",
97129
'http.method': 'GET',
130+
'http.request.method': 'GET',
98131
'http.server_name': 'testserver',
99132
'http.scheme': 'http',
133+
'url.scheme': 'http',
100134
'net.host.port': 80,
135+
'server.port': 80,
101136
'http.url': 'http://testserver/django_test_app/123/?very_long_query_param_name=very+long+query+param+value&foo=1',
102137
'net.peer.ip': '127.0.0.1',
138+
'client.address': '127.0.0.1',
103139
'http.flavor': '1.1',
140+
'network.protocol.version': '1.1',
104141
'http.route': 'django_test_app/<int:item_id>/',
105142
'http.status_code': 200,
143+
'http.response.status_code': 200,
106144
'http.target': '/django_test_app/123/',
107145
},
108146
}
@@ -127,14 +165,20 @@ def test_error_route(client: Client, exporter: TestExporter):
127165
'logfire.span_type': 'span',
128166
'logfire.msg': "GET /django_test_app/bad/ ? foo='1'",
129167
'http.method': 'GET',
168+
'http.request.method': 'GET',
130169
'http.server_name': 'testserver',
131170
'http.scheme': 'http',
171+
'url.scheme': 'http',
132172
'net.host.port': 80,
173+
'server.port': 80,
133174
'http.url': 'http://testserver/django_test_app/bad/?foo=1',
134175
'net.peer.ip': '127.0.0.1',
176+
'client.address': '127.0.0.1',
135177
'http.flavor': '1.1',
178+
'network.protocol.version': '1.1',
136179
'http.route': 'django_test_app/bad/',
137180
'http.status_code': 400,
181+
'http.response.status_code': 400,
138182
'http.target': '/django_test_app/bad/',
139183
'logfire.level_num': 17,
140184
},
@@ -172,13 +216,19 @@ def test_no_matching_route(client: Client, exporter: TestExporter):
172216
'logfire.span_type': 'span',
173217
'logfire.msg': "GET /django_test_app/nowhere/ ? foo='1'",
174218
'http.method': 'GET',
219+
'http.request.method': 'GET',
175220
'http.server_name': 'testserver',
176221
'http.scheme': 'http',
222+
'url.scheme': 'http',
177223
'net.host.port': 80,
224+
'server.port': 80,
178225
'http.url': 'http://testserver/django_test_app/nowhere/?foo=1',
179226
'net.peer.ip': '127.0.0.1',
227+
'client.address': '127.0.0.1',
180228
'http.flavor': '1.1',
229+
'network.protocol.version': '1.1',
181230
'http.status_code': 404,
231+
'http.response.status_code': 404,
182232
'http.target': '/django_test_app/nowhere/',
183233
},
184234
}

0 commit comments

Comments
 (0)