@@ -182,8 +182,19 @@ def client_response_hook(span, future):
182182from opentelemetry .metrics import get_meter
183183from opentelemetry .metrics ._internal .instrument import Histogram
184184from opentelemetry .propagators import textmap
185+ from opentelemetry .semconv ._incubating .attributes .http_attributes import (
186+ HTTP_CLIENT_IP ,
187+ HTTP_FLAVOR ,
188+ HTTP_HOST ,
189+ HTTP_METHOD ,
190+ HTTP_SCHEME ,
191+ HTTP_STATUS_CODE ,
192+ HTTP_TARGET ,
193+ )
194+ from opentelemetry .semconv ._incubating .attributes .net_attributes import (
195+ NET_PEER_IP ,
196+ )
185197from opentelemetry .semconv .metrics import MetricInstruments
186- from opentelemetry .semconv .trace import SpanAttributes
187198from opentelemetry .trace .status import Status , StatusCode
188199from opentelemetry .util .http import (
189200 OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST ,
@@ -442,23 +453,21 @@ def _collect_custom_response_headers_attributes(response_headers):
442453
443454def _get_attributes_from_request (request ):
444455 attrs = {
445- SpanAttributes . HTTP_METHOD : request .method ,
446- SpanAttributes . HTTP_SCHEME : request .protocol ,
447- SpanAttributes . HTTP_HOST : request .host ,
448- SpanAttributes . HTTP_TARGET : request .path ,
456+ HTTP_METHOD : request .method ,
457+ HTTP_SCHEME : request .protocol ,
458+ HTTP_HOST : request .host ,
459+ HTTP_TARGET : request .path ,
449460 }
450461
451462 if request .remote_ip :
452463 # NET_PEER_IP is the address of the network peer
453464 # HTTP_CLIENT_IP is the address of the client, which might be different
454465 # if Tornado is set to trust X-Forwarded-For headers (xheaders=True)
455- attrs [SpanAttributes . HTTP_CLIENT_IP ] = request .remote_ip
466+ attrs [HTTP_CLIENT_IP ] = request .remote_ip
456467 if hasattr (request .connection , "context" ) and getattr (
457468 request .connection .context , "_orig_remote_ip" , None
458469 ):
459- attrs [SpanAttributes .NET_PEER_IP ] = (
460- request .connection .context ._orig_remote_ip
461- )
470+ attrs [NET_PEER_IP ] = request .connection .context ._orig_remote_ip
462471
463472 return extract_attributes_from_object (
464473 request , _traced_request_attrs , attrs
@@ -550,7 +559,7 @@ def _finish_span(tracer, handler, error=None):
550559 return
551560
552561 if ctx .span .is_recording ():
553- ctx .span .set_attribute (SpanAttributes . HTTP_STATUS_CODE , status_code )
562+ ctx .span .set_attribute (HTTP_STATUS_CODE , status_code )
554563 otel_status_code = http_status_to_status_code (
555564 status_code , server_span = True
556565 )
@@ -601,7 +610,7 @@ def _record_on_finish_metrics(server_histograms, handler, error=None):
601610 metric_attributes = _create_metric_attributes (handler )
602611
603612 if isinstance (error , tornado .web .HTTPError ):
604- metric_attributes [SpanAttributes . HTTP_STATUS_CODE ] = error .status_code
613+ metric_attributes [HTTP_STATUS_CODE ] = error .status_code
605614
606615 server_histograms [MetricInstruments .HTTP_SERVER_RESPONSE_SIZE ].record (
607616 response_size , attributes = metric_attributes
@@ -621,18 +630,18 @@ def _record_on_finish_metrics(server_histograms, handler, error=None):
621630
622631def _create_active_requests_attributes (request ):
623632 metric_attributes = {
624- SpanAttributes . HTTP_METHOD : request .method ,
625- SpanAttributes . HTTP_SCHEME : request .protocol ,
626- SpanAttributes . HTTP_FLAVOR : request .version ,
627- SpanAttributes . HTTP_HOST : request .host ,
628- SpanAttributes . HTTP_TARGET : request .path ,
633+ HTTP_METHOD : request .method ,
634+ HTTP_SCHEME : request .protocol ,
635+ HTTP_FLAVOR : request .version ,
636+ HTTP_HOST : request .host ,
637+ HTTP_TARGET : request .path ,
629638 }
630639
631640 return metric_attributes
632641
633642
634643def _create_metric_attributes (handler ):
635644 metric_attributes = _create_active_requests_attributes (handler .request )
636- metric_attributes [SpanAttributes . HTTP_STATUS_CODE ] = handler .get_status ()
645+ metric_attributes [HTTP_STATUS_CODE ] = handler .get_status ()
637646
638647 return metric_attributes
0 commit comments