1
1
import {
2
2
captureException ,
3
3
continueTrace ,
4
- getCurrentHub ,
4
+ getClient ,
5
5
getCurrentScope ,
6
6
runWithAsyncContext ,
7
7
startSpan ,
8
8
} from '@sentry/node' ;
9
- import type { Hub , Span } from '@sentry/types' ;
9
+ import type { Client , Scope , Span } from '@sentry/types' ;
10
10
import { addNonEnumerableProperty , objectify , stripUrlQueryAndFragment } from '@sentry/utils' ;
11
11
import type { APIContext , MiddlewareResponseHandler } from 'astro' ;
12
12
@@ -69,7 +69,7 @@ export const handleRequest: (options?: MiddlewareOptions) => MiddlewareResponseH
69
69
// if there is an active span, we know that this handle call is nested and hence
70
70
// we don't create a new domain for it. If we created one, nested server calls would
71
71
// create new transactions instead of adding a child span to the currently active span.
72
- if ( getCurrentHub ( ) . getScope ( ) . getSpan ( ) ) {
72
+ if ( getCurrentScope ( ) . getSpan ( ) ) {
73
73
return instrumentRequest ( ctx , next , handlerOptions ) ;
74
74
}
75
75
return runWithAsyncContext ( ( ) => {
@@ -139,8 +139,8 @@ async function instrumentRequest(
139
139
span . setHttpStatus ( originalResponse . status ) ;
140
140
}
141
141
142
- const hub = getCurrentHub ( ) ;
143
- const client = hub . getClient ( ) ;
142
+ const scope = getCurrentScope ( ) ;
143
+ const client = getClient ( ) ;
144
144
const contentType = originalResponse . headers . get ( 'content-type' ) ;
145
145
146
146
const isPageloadRequest = contentType && contentType . startsWith ( 'text/html' ) ;
@@ -163,7 +163,7 @@ async function instrumentRequest(
163
163
start : async controller => {
164
164
for await ( const chunk of originalBody ) {
165
165
const html = typeof chunk === 'string' ? chunk : decoder . decode ( chunk ) ;
166
- const modifiedHtml = addMetaTagToHead ( html , hub , span ) ;
166
+ const modifiedHtml = addMetaTagToHead ( html , scope , client , span ) ;
167
167
controller . enqueue ( new TextEncoder ( ) . encode ( modifiedHtml ) ) ;
168
168
}
169
169
controller . close ( ) ;
@@ -185,12 +185,12 @@ async function instrumentRequest(
185
185
* This function optimistically assumes that the HTML coming in chunks will not be split
186
186
* within the <head> tag. If this still happens, we simply won't replace anything.
187
187
*/
188
- function addMetaTagToHead ( htmlChunk : string , hub : Hub , span ?: Span ) : string {
188
+ function addMetaTagToHead ( htmlChunk : string , scope : Scope , client : Client , span ?: Span ) : string {
189
189
if ( typeof htmlChunk !== 'string' ) {
190
190
return htmlChunk ;
191
191
}
192
192
193
- const { sentryTrace, baggage } = getTracingMetaTags ( span , hub ) ;
193
+ const { sentryTrace, baggage } = getTracingMetaTags ( span , scope , client ) ;
194
194
const content = `<head>\n${ sentryTrace } \n${ baggage } \n` ;
195
195
return htmlChunk . replace ( '<head>' , content ) ;
196
196
}
0 commit comments