File tree Expand file tree Collapse file tree
packages/rum/src/domain/profiling Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -47,11 +47,19 @@ describe('checkProfilingQuota', () => {
4747 expect ( result ) . toBe ( 'quota-ok' )
4848 } )
4949
50- it ( 'builds the URL with site, session_id and dd-api-key ' , async ( ) => {
50+ it ( 'builds the URL with site and session_id ' , async ( ) => {
5151 interceptor . withFetch ( DEFAULT_FETCH_MOCK )
5252 await checkProfilingQuota ( mockRumConfiguration ( { site : 'datadoghq.com' , clientToken : 'my-token' } ) , 'session-abc' )
5353 expect ( interceptor . requests [ 0 ] . url ) . toBe (
54- 'https://api.datadoghq.com/api/unstable/profiling/admission?session_id=session-abc&dd-api-key=my-token'
54+ 'https://app.datadoghq.com/api/unstable/profiling/admission?session_id=session-abc'
55+ )
56+ } )
57+
58+ it ( 'uses the dd.datad0g.com base URL for datad0g.com site' , async ( ) => {
59+ interceptor . withFetch ( DEFAULT_FETCH_MOCK )
60+ await checkProfilingQuota ( mockRumConfiguration ( { site : 'datad0g.com' , clientToken : 'my-token' } ) , 'session-abc' )
61+ expect ( interceptor . requests [ 0 ] . url ) . toBe (
62+ 'https://dd.datad0g.com/api/unstable/profiling/admission?session_id=session-abc'
5563 )
5664 } )
5765} )
Original file line number Diff line number Diff line change 11import { fetch , setTimeout , clearTimeout } from '@datadog/browser-core'
22import type { RumConfiguration } from '@datadog/browser-rum-core'
33
4+ const getQuotaBaseURL = ( site : string ) => {
5+ switch ( site ) {
6+ case 'datad0g.com' :
7+ return `https://dd.${ site } `
8+ default :
9+ return `https://app.${ site } `
10+ }
11+ }
12+
413export function checkProfilingQuota (
514 configuration : RumConfiguration ,
615 sessionId : string ,
716 timeoutMs = 5000
817) : Promise < 'quota-ok' | 'quota-exceeded' > {
9- const url = `https://api. ${ configuration . site } /api/unstable/profiling/admission?session_id=${ sessionId } &dd-api-key= ${ configuration . clientToken } `
18+ const url = `${ getQuotaBaseURL ( configuration . site ) } /api/unstable/profiling/admission?session_id=${ sessionId } `
1019 const controller = new AbortController ( )
1120
1221 let timeoutId : ReturnType < typeof setTimeout >
1322
14- const fetchPromise = fetch ( url , { signal : controller . signal } )
23+ const fetchPromise = fetch ( url , {
24+ credentials : 'omit' ,
25+ signal : controller . signal ,
26+ headers : new Headers ( {
27+ 'DD-CLIENT-TOKEN' : configuration . clientToken ,
28+ } ) ,
29+ } )
1530 . then ( ( response ) : 'quota-ok' | 'quota-exceeded' => {
1631 clearTimeout ( timeoutId )
1732 return response . status === 429 ? 'quota-exceeded' : 'quota-ok'
You can’t perform that action at this time.
0 commit comments