@@ -126,7 +126,7 @@ describe('Agent365Exporter', () => {
126126 expect ( fetchCalls . length ) . toBe ( 1 ) ;
127127 const urlArg = fetchCalls [ 0 ] [ 0 ] ;
128128 const headersArg = fetchCalls [ 0 ] [ 1 ] . headers ;
129- expect ( urlArg ) . toBe ( expectedUrl ) ;
129+ expect ( urlArg ) . toBe ( ` ${ expectedUrl } /maven/agent365/agents/ ${ agentId } /traces?api-version=1` ) ;
130130 expect ( headersArg [ 'x-ms-tenant-id' ] ) . toBe ( tenantId ) ;
131131 expect ( headersArg [ 'authorization' ] ) . toBe ( `Bearer ${ token } ` ) ;
132132 } ) ;
@@ -164,4 +164,61 @@ describe('Agent365Exporter', () => {
164164 // Intentionally omit tokenResolver
165165 expect ( ( ) => new Agent365Exporter ( opts ) ) . toThrow ( / t o k e n R e s o l v e r m u s t b e p r o v i d e d / ) ;
166166 } ) ;
167+ it ( 'uses S2S endpoint path when useS2SEndpoint is true (discovery flow)' , async ( ) => {
168+ mockFetchSequence ( [ 200 ] ) ;
169+ const token = 'tok-s2s' ;
170+ const opts = new Agent365ExporterOptions ( ) ;
171+ opts . clusterCategory = 'prod' ;
172+ opts . tokenResolver = ( ) => token ;
173+ opts . useS2SEndpoint = true ;
174+
175+ const exporter = new Agent365Exporter ( opts ) ;
176+ const spans = [
177+ makeSpan ( {
178+ [ OpenTelemetryConstants . TENANT_ID_KEY ] : tenantId ,
179+ [ OpenTelemetryConstants . GEN_AI_AGENT_ID_KEY ] : agentId
180+ } , 's2s-span' )
181+ ] ;
182+
183+ const callback = jest . fn ( ) ;
184+ await exporter . export ( spans , callback ) ;
185+
186+ expect ( callback ) . toHaveBeenCalledWith ( { code : ExportResultCode . SUCCESS } ) ;
187+ const fetchCalls = ( global . fetch as unknown as { mock : { calls : any [ ] } } ) . mock . calls ;
188+ expect ( fetchCalls . length ) . toBe ( 1 ) ;
189+
190+ const urlArg = fetchCalls [ 0 ] [ 0 ] as string ;
191+ expect ( urlArg ) . toMatch ( `/maven/agent365/service/agents/${ agentId } /traces?api-version=1` ) ;
192+ const headersArg = fetchCalls [ 0 ] [ 1 ] . headers as Record < string , string > ;
193+ expect ( headersArg [ 'authorization' ] ) . toBe ( `Bearer ${ token } ` ) ;
194+ } ) ;
195+
196+ it ( 'uses S2S endpoint path with custom domain and sets x-ms-tenant-id' , async ( ) => {
197+ mockFetchSequence ( [ 200 ] ) ;
198+ process . env . A365_OBSERVABILITY_USE_CUSTOM_DOMAIN = 'true' ;
199+ const token = 'tok-s2s-custom' ;
200+ const opts = new Agent365ExporterOptions ( ) ;
201+ opts . clusterCategory = 'prod' ;
202+ opts . tokenResolver = ( ) => token ;
203+ opts . useS2SEndpoint = true ;
204+
205+ const exporter = new Agent365Exporter ( opts ) ;
206+ const spans = [
207+ makeSpan ( {
208+ [ OpenTelemetryConstants . TENANT_ID_KEY ] : tenantId ,
209+ [ OpenTelemetryConstants . GEN_AI_AGENT_ID_KEY ] : agentId
210+ } , 's2s-custom-span' )
211+ ] ;
212+
213+ const callback = jest . fn ( ) ;
214+ await exporter . export ( spans , callback ) ;
215+
216+ const fetchCalls = ( global . fetch as unknown as { mock : { calls : any [ ] } } ) . mock . calls ;
217+ expect ( fetchCalls . length ) . toBe ( 1 ) ;
218+ const urlArg = fetchCalls [ 0 ] [ 0 ] as string ;
219+ expect ( urlArg ) . toMatch ( `/maven/agent365/service/agents/${ agentId } /traces?api-version=1` ) ;
220+ const headersArg = fetchCalls [ 0 ] [ 1 ] . headers as Record < string , string > ;
221+ expect ( headersArg [ 'authorization' ] ) . toBe ( `Bearer ${ token } ` ) ;
222+ expect ( headersArg [ 'x-ms-tenant-id' ] ) . toBe ( tenantId ) ;
223+ } )
167224} ) ;
0 commit comments