11import {
22 captureException ,
33 continueTrace ,
4- getCurrentHub ,
4+ getClient ,
55 getCurrentScope ,
66 runWithAsyncContext ,
77 startSpan ,
88} from '@sentry/node' ;
9- import type { Hub , Span } from '@sentry/types' ;
9+ import type { Client , Scope , Span } from '@sentry/types' ;
1010import { addNonEnumerableProperty , objectify , stripUrlQueryAndFragment } from '@sentry/utils' ;
1111import type { APIContext , MiddlewareResponseHandler } from 'astro' ;
1212
@@ -69,7 +69,7 @@ export const handleRequest: (options?: MiddlewareOptions) => MiddlewareResponseH
6969 // if there is an active span, we know that this handle call is nested and hence
7070 // we don't create a new domain for it. If we created one, nested server calls would
7171 // create new transactions instead of adding a child span to the currently active span.
72- if ( getCurrentHub ( ) . getScope ( ) . getSpan ( ) ) {
72+ if ( getCurrentScope ( ) . getSpan ( ) ) {
7373 return instrumentRequest ( ctx , next , handlerOptions ) ;
7474 }
7575 return runWithAsyncContext ( ( ) => {
@@ -139,8 +139,8 @@ async function instrumentRequest(
139139 span . setHttpStatus ( originalResponse . status ) ;
140140 }
141141
142- const hub = getCurrentHub ( ) ;
143- const client = hub . getClient ( ) ;
142+ const scope = getCurrentScope ( ) ;
143+ const client = getClient ( ) ;
144144 const contentType = originalResponse . headers . get ( 'content-type' ) ;
145145
146146 const isPageloadRequest = contentType && contentType . startsWith ( 'text/html' ) ;
@@ -163,7 +163,7 @@ async function instrumentRequest(
163163 start : async controller => {
164164 for await ( const chunk of originalBody ) {
165165 const html = typeof chunk === 'string' ? chunk : decoder . decode ( chunk ) ;
166- const modifiedHtml = addMetaTagToHead ( html , hub , span ) ;
166+ const modifiedHtml = addMetaTagToHead ( html , scope , client , span ) ;
167167 controller . enqueue ( new TextEncoder ( ) . encode ( modifiedHtml ) ) ;
168168 }
169169 controller . close ( ) ;
@@ -185,12 +185,12 @@ async function instrumentRequest(
185185 * This function optimistically assumes that the HTML coming in chunks will not be split
186186 * within the <head> tag. If this still happens, we simply won't replace anything.
187187 */
188- function addMetaTagToHead ( htmlChunk : string , hub : Hub , span ?: Span ) : string {
188+ function addMetaTagToHead ( htmlChunk : string , scope : Scope , client : Client , span ?: Span ) : string {
189189 if ( typeof htmlChunk !== 'string' ) {
190190 return htmlChunk ;
191191 }
192192
193- const { sentryTrace, baggage } = getTracingMetaTags ( span , hub ) ;
193+ const { sentryTrace, baggage } = getTracingMetaTags ( span , scope , client ) ;
194194 const content = `<head>\n${ sentryTrace } \n${ baggage } \n` ;
195195 return htmlChunk . replace ( '<head>' , content ) ;
196196}
0 commit comments