@@ -562,7 +562,15 @@ def event_processor(event: "Event", hint: "Dict[str, Any]") -> "Event":
562562 if "cookies" in info :
563563 request_info ["cookies" ] = info ["cookies" ]
564564 if "data" in info :
565- request_info ["data" ] = info ["data" ]
565+ attach_request_data = True
566+ if has_data_collection_enabled (client .options ):
567+ attach_request_data = (
568+ "incoming_request"
569+ in client .options ["data_collection" ]["http_bodies" ]
570+ )
571+
572+ if attach_request_data :
573+ request_info ["data" ] = info ["data" ]
566574 event ["request" ] = deepcopy (request_info )
567575
568576 return event
@@ -580,15 +588,23 @@ def event_processor(event: "Event", hint: "Dict[str, Any]") -> "Event":
580588 current_span = get_current_span ()
581589
582590 if type (current_span ) is StreamedSpan :
583- request_body = _get_cached_request_body_attribute (
584- client = client , request = request
585- )
586- if request_body :
587- current_span ._segment .set_attribute (
588- SPANDATA .HTTP_REQUEST_BODY_DATA ,
589- request_body ,
591+ attach_request_data = True
592+ if has_data_collection_enabled (client .options ):
593+ attach_request_data = (
594+ "incoming_request"
595+ in client .options ["data_collection" ]["http_bodies" ]
590596 )
591597
598+ if attach_request_data :
599+ request_body = _get_cached_request_body_attribute (
600+ client = client , request = request
601+ )
602+ if request_body :
603+ current_span ._segment .set_attribute (
604+ SPANDATA .HTTP_REQUEST_BODY_DATA ,
605+ request_body ,
606+ )
607+
592608
593609def patch_request_response () -> None :
594610 old_request_response = starlette .routing .request_response
@@ -827,21 +843,24 @@ async def json(self: "StarletteRequestExtractor") -> "Optional[Dict[str, Any]]":
827843 return None
828844
829845
830- def _transaction_name_from_router (scope : "StarletteScope" ) -> "Optional[str]" :
846+ def _transaction_name_and_source_from_router (
847+ scope : "StarletteScope" ,
848+ ) -> "Tuple[Optional[str], TransactionSource]" :
831849 router = scope .get ("router" )
832850 if not router :
833- return None
851+ return None , TransactionSource . ROUTE
834852
835853 for route in router .routes :
836854 match = route .matches (scope )
837855 if match [0 ] == Match .FULL :
838856 try :
839- return route .path
857+ return route .path , TransactionSource . ROUTE
840858 except AttributeError :
841- # routes added via app.host() won't have a path attribute
842- return scope .get ("path" )
859+ # Host routes have no path template, so fall back to the
860+ # concrete request path and classify it as a URL.
861+ return scope .get ("path" ), TransactionSource .URL
843862
844- return None
863+ return None , TransactionSource . ROUTE
845864
846865
847866def _set_transaction_name_and_source (
@@ -856,7 +875,7 @@ def _set_transaction_name_and_source(
856875 name = transaction_from_function (endpoint ) or None
857876
858877 elif transaction_style == "url" :
859- name = _transaction_name_from_router (request .scope )
878+ name , source = _transaction_name_and_source_from_router (request .scope )
860879
861880 if name is None :
862881 name = _DEFAULT_TRANSACTION_NAME
@@ -877,7 +896,6 @@ def _get_transaction_from_middleware(
877896 name = transaction_from_function (app .__class__ )
878897 source = TransactionSource .COMPONENT
879898 elif integration .transaction_style == "url" :
880- name = _transaction_name_from_router (asgi_scope )
881- source = TransactionSource .ROUTE
899+ name , source = _transaction_name_and_source_from_router (asgi_scope )
882900
883901 return name , source
0 commit comments