@@ -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 ,
@@ -446,23 +457,21 @@ def _collect_custom_response_headers_attributes(response_headers):
446457
447458def  _get_attributes_from_request (request ):
448459    attrs  =  {
449-         SpanAttributes . HTTP_METHOD : request .method ,
450-         SpanAttributes . HTTP_SCHEME : request .protocol ,
451-         SpanAttributes . HTTP_HOST : request .host ,
452-         SpanAttributes . HTTP_TARGET : request .path ,
460+         HTTP_METHOD : request .method ,
461+         HTTP_SCHEME : request .protocol ,
462+         HTTP_HOST : request .host ,
463+         HTTP_TARGET : request .path ,
453464    }
454465
455466    if  request .remote_ip :
456467        # NET_PEER_IP is the address of the network peer 
457468        # HTTP_CLIENT_IP is the address of the client, which might be different 
458469        # if Tornado is set to trust X-Forwarded-For headers (xheaders=True) 
459-         attrs [SpanAttributes . HTTP_CLIENT_IP ] =  request .remote_ip 
470+         attrs [HTTP_CLIENT_IP ] =  request .remote_ip 
460471        if  hasattr (request .connection , "context" ) and  getattr (
461472            request .connection .context , "_orig_remote_ip" , None 
462473        ):
463-             attrs [SpanAttributes .NET_PEER_IP ] =  (
464-                 request .connection .context ._orig_remote_ip 
465-             )
474+             attrs [NET_PEER_IP ] =  request .connection .context ._orig_remote_ip 
466475
467476    return  extract_attributes_from_object (
468477        request , _traced_request_attrs , attrs 
@@ -554,7 +563,7 @@ def _finish_span(tracer, handler, error=None):
554563        return 
555564
556565    if  ctx .span .is_recording ():
557-         ctx .span .set_attribute (SpanAttributes . HTTP_STATUS_CODE , status_code )
566+         ctx .span .set_attribute (HTTP_STATUS_CODE , status_code )
558567        otel_status_code  =  http_status_to_status_code (
559568            status_code , server_span = True 
560569        )
@@ -607,7 +616,7 @@ def _record_on_finish_metrics(server_histograms, handler, error=None):
607616    metric_attributes  =  _create_metric_attributes (handler )
608617
609618    if  isinstance (error , tornado .web .HTTPError ):
610-         metric_attributes [SpanAttributes . HTTP_STATUS_CODE ] =  error .status_code 
619+         metric_attributes [HTTP_STATUS_CODE ] =  error .status_code 
611620
612621    server_histograms [MetricInstruments .HTTP_SERVER_RESPONSE_SIZE ].record (
613622        response_size , attributes = metric_attributes 
@@ -627,18 +636,18 @@ def _record_on_finish_metrics(server_histograms, handler, error=None):
627636
628637def  _create_active_requests_attributes (request ):
629638    metric_attributes  =  {
630-         SpanAttributes . HTTP_METHOD : request .method ,
631-         SpanAttributes . HTTP_SCHEME : request .protocol ,
632-         SpanAttributes . HTTP_FLAVOR : request .version ,
633-         SpanAttributes . HTTP_HOST : request .host ,
634-         SpanAttributes . HTTP_TARGET : request .path ,
639+         HTTP_METHOD : request .method ,
640+         HTTP_SCHEME : request .protocol ,
641+         HTTP_FLAVOR : request .version ,
642+         HTTP_HOST : request .host ,
643+         HTTP_TARGET : request .path ,
635644    }
636645
637646    return  metric_attributes 
638647
639648
640649def  _create_metric_attributes (handler ):
641650    metric_attributes  =  _create_active_requests_attributes (handler .request )
642-     metric_attributes [SpanAttributes . HTTP_STATUS_CODE ] =  handler .get_status ()
651+     metric_attributes [HTTP_STATUS_CODE ] =  handler .get_status ()
643652
644653    return  metric_attributes 
0 commit comments