@@ -79,7 +79,11 @@ export function logMiddleware(app, options) {
7979
8080 // Skip eventStop if we don't have events enabled.
8181 // Skip eventStop for CORS requests, this gives a bit cleaner logs.
82- if ( options . disableRootEvent !== true && ctx . method !== "OPTIONS" ) {
82+ if (
83+ options . disableRootEvent !== true &&
84+ ctx . method !== "OPTIONS" &&
85+ ctx . method !== "HEAD"
86+ ) {
8387 if ( _compasSentryExport ) {
8488 const span = _compasSentryExport . getActiveSpan ( ) ;
8589 if ( span ) {
@@ -91,12 +95,12 @@ export function logMiddleware(app, options) {
9195 }
9296
9397 if ( _compasSentryExport ) {
94- if ( _compasSentryExport . metrics ?. increment ) {
95- let compasRouteName = ctx . event . name ;
96- if ( ! compasRouteName . startsWith ( "router." ) ) {
97- compasRouteName = "<unmatched>" ;
98- }
98+ const span = _compasSentryExport . getActiveSpan ( ) ;
99+ const routeName = ctx . event . name ;
100+ const isMatchedRoute = routeName . startsWith ( "router." ) ;
99101
102+ if ( _compasSentryExport . metrics ?. increment ) {
103+ const compasRouteName = isMatchedRoute ? routeName : "<unmatched>" ;
100104 _compasSentryExport . metrics . increment ( "compas.route.name" , 1 , {
101105 tags : {
102106 compasRouteName,
@@ -105,8 +109,14 @@ export function logMiddleware(app, options) {
105109 } ) ;
106110 }
107111
108- const span = _compasSentryExport . getActiveSpan ( ) ;
109112 if ( span ) {
113+ if ( ! isMatchedRoute ) {
114+ // @ts -expect-error Private property?
115+ //
116+ // Discard sampled spans which don't match a route.
117+ span . _sampled = false ;
118+ }
119+
110120 span . setStatus (
111121 _compasSentryExport . getSpanStatusFromHttpCode ( ctx . status ) ,
112122 ) ;
0 commit comments