1717from enum import Enum
1818
1919from opentelemetry .instrumentation .utils import http_status_to_status_code
20+ from opentelemetry .semconv ._incubating .attributes .http_attributes import (
21+ HTTP_FLAVOR ,
22+ HTTP_HOST ,
23+ HTTP_METHOD ,
24+ HTTP_SCHEME ,
25+ HTTP_SERVER_NAME ,
26+ HTTP_STATUS_CODE ,
27+ HTTP_TARGET ,
28+ HTTP_URL ,
29+ HTTP_USER_AGENT ,
30+ )
31+ from opentelemetry .semconv ._incubating .attributes .net_attributes import (
32+ NET_HOST_NAME ,
33+ NET_HOST_PORT ,
34+ NET_PEER_IP ,
35+ NET_PEER_NAME ,
36+ NET_PEER_PORT ,
37+ )
2038from opentelemetry .semconv .attributes .client_attributes import (
2139 CLIENT_ADDRESS ,
2240 CLIENT_PORT ,
4462from opentelemetry .semconv .attributes .user_agent_attributes import (
4563 USER_AGENT_ORIGINAL ,
4664)
47- from opentelemetry .semconv .trace import SpanAttributes
65+ from opentelemetry .semconv .schemas import Schemas
4866from opentelemetry .trace .status import Status , StatusCode
4967
5068# Values defined in milliseconds
87105# These lists represent attributes for metrics that are currently supported
88106
89107_client_duration_attrs_old = [
90- SpanAttributes . HTTP_STATUS_CODE ,
91- SpanAttributes . HTTP_HOST ,
92- SpanAttributes . NET_PEER_PORT ,
93- SpanAttributes . NET_PEER_NAME ,
94- SpanAttributes . HTTP_METHOD ,
95- SpanAttributes . HTTP_FLAVOR ,
96- SpanAttributes . HTTP_SCHEME ,
108+ HTTP_STATUS_CODE ,
109+ HTTP_HOST ,
110+ HTTP_METHOD ,
111+ HTTP_FLAVOR ,
112+ HTTP_SCHEME ,
113+ NET_PEER_PORT ,
114+ NET_PEER_NAME ,
97115]
98116
99117_client_duration_attrs_new = [
108126]
109127
110128_server_duration_attrs_old = [
111- SpanAttributes . HTTP_METHOD ,
112- SpanAttributes . HTTP_HOST ,
113- SpanAttributes . HTTP_SCHEME ,
114- SpanAttributes . HTTP_STATUS_CODE ,
115- SpanAttributes . HTTP_FLAVOR ,
116- SpanAttributes . HTTP_SERVER_NAME ,
117- SpanAttributes . NET_HOST_NAME ,
118- SpanAttributes . NET_HOST_PORT ,
129+ HTTP_METHOD ,
130+ HTTP_HOST ,
131+ HTTP_SCHEME ,
132+ HTTP_STATUS_CODE ,
133+ HTTP_FLAVOR ,
134+ HTTP_SERVER_NAME ,
135+ NET_HOST_NAME ,
136+ NET_HOST_PORT ,
119137]
120138
121139_server_duration_attrs_new = [
128146]
129147
130148_server_active_requests_count_attrs_old = [
131- SpanAttributes . HTTP_METHOD ,
132- SpanAttributes . HTTP_HOST ,
133- SpanAttributes . HTTP_SCHEME ,
134- SpanAttributes . HTTP_FLAVOR ,
135- SpanAttributes . HTTP_SERVER_NAME ,
149+ HTTP_METHOD ,
150+ HTTP_HOST ,
151+ HTTP_SCHEME ,
152+ HTTP_FLAVOR ,
153+ HTTP_SERVER_NAME ,
136154]
137155
138156_server_active_requests_count_attrs_new = [
@@ -287,44 +305,42 @@ def _set_http_method(result, original, normalized, sem_conv_opt_in_mode):
287305 set_string_attribute (result , HTTP_REQUEST_METHOD_ORIGINAL , original )
288306
289307 if _report_old (sem_conv_opt_in_mode ):
290- set_string_attribute (result , SpanAttributes . HTTP_METHOD , normalized )
308+ set_string_attribute (result , HTTP_METHOD , normalized )
291309 if _report_new (sem_conv_opt_in_mode ):
292310 set_string_attribute (result , HTTP_REQUEST_METHOD , normalized )
293311
294312
295313def _set_http_status_code (result , code , sem_conv_opt_in_mode ):
296314 if _report_old (sem_conv_opt_in_mode ):
297- set_int_attribute (result , SpanAttributes . HTTP_STATUS_CODE , code )
315+ set_int_attribute (result , HTTP_STATUS_CODE , code )
298316 if _report_new (sem_conv_opt_in_mode ):
299317 set_int_attribute (result , HTTP_RESPONSE_STATUS_CODE , code )
300318
301319
302320def _set_http_url (result , url , sem_conv_opt_in_mode ):
303321 if _report_old (sem_conv_opt_in_mode ):
304- set_string_attribute (result , SpanAttributes . HTTP_URL , url )
322+ set_string_attribute (result , HTTP_URL , url )
305323 if _report_new (sem_conv_opt_in_mode ):
306324 set_string_attribute (result , URL_FULL , url )
307325
308326
309327def _set_http_scheme (result , scheme , sem_conv_opt_in_mode ):
310328 if _report_old (sem_conv_opt_in_mode ):
311- set_string_attribute (result , SpanAttributes . HTTP_SCHEME , scheme )
329+ set_string_attribute (result , HTTP_SCHEME , scheme )
312330 if _report_new (sem_conv_opt_in_mode ):
313331 set_string_attribute (result , URL_SCHEME , scheme )
314332
315333
316334def _set_http_flavor_version (result , version , sem_conv_opt_in_mode ):
317335 if _report_old (sem_conv_opt_in_mode ):
318- set_string_attribute (result , SpanAttributes . HTTP_FLAVOR , version )
336+ set_string_attribute (result , HTTP_FLAVOR , version )
319337 if _report_new (sem_conv_opt_in_mode ):
320338 set_string_attribute (result , NETWORK_PROTOCOL_VERSION , version )
321339
322340
323341def _set_http_user_agent (result , user_agent , sem_conv_opt_in_mode ):
324342 if _report_old (sem_conv_opt_in_mode ):
325- set_string_attribute (
326- result , SpanAttributes .HTTP_USER_AGENT , user_agent
327- )
343+ set_string_attribute (result , HTTP_USER_AGENT , user_agent )
328344 if _report_new (sem_conv_opt_in_mode ):
329345 set_string_attribute (result , USER_AGENT_ORIGINAL , user_agent )
330346
@@ -334,28 +350,28 @@ def _set_http_user_agent(result, user_agent, sem_conv_opt_in_mode):
334350
335351def _set_http_host_client (result , host , sem_conv_opt_in_mode ):
336352 if _report_old (sem_conv_opt_in_mode ):
337- set_string_attribute (result , SpanAttributes . HTTP_HOST , host )
353+ set_string_attribute (result , HTTP_HOST , host )
338354 if _report_new (sem_conv_opt_in_mode ):
339355 set_string_attribute (result , SERVER_ADDRESS , host )
340356
341357
342358def _set_http_net_peer_name_client (result , peer_name , sem_conv_opt_in_mode ):
343359 if _report_old (sem_conv_opt_in_mode ):
344- set_string_attribute (result , SpanAttributes . NET_PEER_NAME , peer_name )
360+ set_string_attribute (result , NET_PEER_NAME , peer_name )
345361 if _report_new (sem_conv_opt_in_mode ):
346362 set_string_attribute (result , SERVER_ADDRESS , peer_name )
347363
348364
349365def _set_http_peer_port_client (result , port , sem_conv_opt_in_mode ):
350366 if _report_old (sem_conv_opt_in_mode ):
351- set_int_attribute (result , SpanAttributes . NET_PEER_PORT , port )
367+ set_int_attribute (result , NET_PEER_PORT , port )
352368 if _report_new (sem_conv_opt_in_mode ):
353369 set_int_attribute (result , SERVER_PORT , port )
354370
355371
356372def _set_http_network_protocol_version (result , version , sem_conv_opt_in_mode ):
357373 if _report_old (sem_conv_opt_in_mode ):
358- set_string_attribute (result , SpanAttributes . HTTP_FLAVOR , version )
374+ set_string_attribute (result , HTTP_FLAVOR , version )
359375 if _report_new (sem_conv_opt_in_mode ):
360376 set_string_attribute (result , NETWORK_PROTOCOL_VERSION , version )
361377
@@ -365,21 +381,21 @@ def _set_http_network_protocol_version(result, version, sem_conv_opt_in_mode):
365381
366382def _set_http_net_host (result , host , sem_conv_opt_in_mode ):
367383 if _report_old (sem_conv_opt_in_mode ):
368- set_string_attribute (result , SpanAttributes . NET_HOST_NAME , host )
384+ set_string_attribute (result , NET_HOST_NAME , host )
369385 if _report_new (sem_conv_opt_in_mode ):
370386 set_string_attribute (result , SERVER_ADDRESS , host )
371387
372388
373389def _set_http_net_host_port (result , port , sem_conv_opt_in_mode ):
374390 if _report_old (sem_conv_opt_in_mode ):
375- set_int_attribute (result , SpanAttributes . NET_HOST_PORT , port )
391+ set_int_attribute (result , NET_HOST_PORT , port )
376392 if _report_new (sem_conv_opt_in_mode ):
377393 set_int_attribute (result , SERVER_PORT , port )
378394
379395
380396def _set_http_target (result , target , path , query , sem_conv_opt_in_mode ):
381397 if _report_old (sem_conv_opt_in_mode ):
382- set_string_attribute (result , SpanAttributes . HTTP_TARGET , target )
398+ set_string_attribute (result , HTTP_TARGET , target )
383399 if _report_new (sem_conv_opt_in_mode ):
384400 if path :
385401 set_string_attribute (result , URL_PATH , path )
@@ -389,7 +405,7 @@ def _set_http_target(result, target, path, query, sem_conv_opt_in_mode):
389405
390406def _set_http_host_server (result , host , sem_conv_opt_in_mode ):
391407 if _report_old (sem_conv_opt_in_mode ):
392- set_string_attribute (result , SpanAttributes . HTTP_HOST , host )
408+ set_string_attribute (result , HTTP_HOST , host )
393409 if _report_new (sem_conv_opt_in_mode ):
394410 if not result .get (SERVER_ADDRESS ):
395411 set_string_attribute (result , SERVER_ADDRESS , host )
@@ -402,7 +418,7 @@ def _set_http_host_server(result, host, sem_conv_opt_in_mode):
402418# https://github.com/open-telemetry/semantic-conventions/blob/main/docs/non-normative/http-migration.md#common-attributes-across-http-client-and-server-spans
403419def _set_http_peer_ip_server (result , ip , sem_conv_opt_in_mode ):
404420 if _report_old (sem_conv_opt_in_mode ):
405- set_string_attribute (result , SpanAttributes . NET_PEER_IP , ip )
421+ set_string_attribute (result , NET_PEER_IP , ip )
406422 if _report_new (sem_conv_opt_in_mode ):
407423 # Only populate if not already populated
408424 if not result .get (CLIENT_ADDRESS ):
@@ -411,14 +427,14 @@ def _set_http_peer_ip_server(result, ip, sem_conv_opt_in_mode):
411427
412428def _set_http_peer_port_server (result , port , sem_conv_opt_in_mode ):
413429 if _report_old (sem_conv_opt_in_mode ):
414- set_int_attribute (result , SpanAttributes . NET_PEER_PORT , port )
430+ set_int_attribute (result , NET_PEER_PORT , port )
415431 if _report_new (sem_conv_opt_in_mode ):
416432 set_int_attribute (result , CLIENT_PORT , port )
417433
418434
419435def _set_http_net_peer_name_server (result , name , sem_conv_opt_in_mode ):
420436 if _report_old (sem_conv_opt_in_mode ):
421- set_string_attribute (result , SpanAttributes . NET_PEER_NAME , name )
437+ set_string_attribute (result , NET_PEER_NAME , name )
422438 if _report_new (sem_conv_opt_in_mode ):
423439 set_string_attribute (result , CLIENT_ADDRESS , name )
424440
@@ -450,10 +466,8 @@ def _set_status(
450466
451467 if _report_old (sem_conv_opt_in_mode ):
452468 if span .is_recording ():
453- span .set_attribute (
454- SpanAttributes .HTTP_STATUS_CODE , status_code
455- )
456- metrics_attributes [SpanAttributes .HTTP_STATUS_CODE ] = status_code
469+ span .set_attribute (HTTP_STATUS_CODE , status_code )
470+ metrics_attributes [HTTP_STATUS_CODE ] = status_code
457471 if _report_new (sem_conv_opt_in_mode ):
458472 if span .is_recording ():
459473 span .set_attribute (HTTP_RESPONSE_STATUS_CODE , status_code )
@@ -470,4 +484,4 @@ def _set_status(
470484def _get_schema_url (mode : _StabilityMode ) -> str :
471485 if mode is _StabilityMode .DEFAULT :
472486 return "https://opentelemetry.io/schemas/1.11.0"
473- return SpanAttributes . SCHEMA_URL
487+ return Schemas . V1_33_0 . value
0 commit comments