@@ -42,6 +42,7 @@ describe('httpContextIntegration', () => {
4242 [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'http.client' ,
4343 'http.request.header.referer' : [ 'https://example.com' ] ,
4444 'user_agent.original' : USER_AGENT ,
45+ 'sentry.is_localhost' : false ,
4546 } ) ;
4647 } ) ;
4748
@@ -63,6 +64,7 @@ describe('httpContextIntegration', () => {
6364 [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'pageload' ,
6465 'http.request.header.referer' : [ 'https://example.com' ] ,
6566 'user_agent.original' : USER_AGENT ,
67+ 'sentry.is_localhost' : false ,
6668 'url.full' : 'https://example.com' ,
6769 } ) ;
6870 } ) ;
@@ -81,6 +83,7 @@ describe('httpContextIntegration', () => {
8183 expect ( span . attributes ) . toEqual ( {
8284 [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'ui.click' ,
8385 'user_agent.original' : USER_AGENT ,
86+ 'sentry.is_localhost' : false ,
8487 } ) ;
8588 } ) ;
8689
@@ -165,6 +168,7 @@ describe('httpContextIntegration', () => {
165168
166169 expect ( span . attributes ) . toEqual ( {
167170 [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'pageload' ,
171+ 'sentry.is_localhost' : false ,
168172 'url.full' : 'https://example.com' ,
169173 } ) ;
170174 } ) ;
@@ -185,7 +189,45 @@ describe('httpContextIntegration', () => {
185189 'url.full' : 'https://example.com' ,
186190 'http.request.header.referer' : [ '[Filtered]' ] ,
187191 'user_agent.original' : USER_AGENT ,
192+ 'sentry.is_localhost' : false ,
188193 } ) ;
189194 } ) ;
190195 } ) ;
196+
197+ describe ( 'sentry.is_localhost' , ( ) => {
198+ function processSpanWithLocation ( location : Partial < Location > ) : StreamedSpanJSON [ 'attributes' ] {
199+ const original = globalThis . location ;
200+ globalThis . location = location as Location ;
201+
202+ try {
203+ const span : Partial < StreamedSpanJSON > = { attributes : { } } ;
204+ httpContextIntegration ( ) . processSpan ! (
205+ span as StreamedSpanJSON ,
206+ new BrowserClient ( getDefaultBrowserClientOptions ( ) ) ,
207+ ) ;
208+ return span . attributes ;
209+ } finally {
210+ globalThis . location = original ;
211+ }
212+ }
213+
214+ it . each ( [
215+ { protocol : 'http:' , hostname : 'localhost' } ,
216+ { protocol : 'http:' , hostname : '127.0.0.1' } ,
217+ { protocol : 'http:' , hostname : 'foo.localhost' } ,
218+ { protocol : 'http:' , hostname : 'foo.bar.localhost' } ,
219+ { protocol : 'file:' , hostname : '' } ,
220+ ] ) ( 'is true for $protocol//$hostname' , location => {
221+ expect ( processSpanWithLocation ( location ) ) . toMatchObject ( { 'sentry.is_localhost' : true } ) ;
222+ } ) ;
223+
224+ it . each ( [
225+ { protocol : 'https:' , hostname : 'example.com' } ,
226+ { protocol : 'https:' , hostname : 'localhost.com' } ,
227+ { protocol : 'https:' , hostname : 'foolocalhost' } ,
228+ { protocol : 'https:' , hostname : '127.0.0.2' } ,
229+ ] ) ( 'is false for $protocol//$hostname' , location => {
230+ expect ( processSpanWithLocation ( location ) ) . toMatchObject ( { 'sentry.is_localhost' : false } ) ;
231+ } ) ;
232+ } ) ;
191233} ) ;
0 commit comments