1111import time
1212from collections .abc import Callable , Sequence
1313from typing import Any , final
14- from urllib .parse import urlparse
1514
1615import requests
17- from microsoft_agents_a365 .runtime .power_platform_api_discovery import PowerPlatformApiDiscovery
1816from opentelemetry .sdk .trace import ReadableSpan
1917from opentelemetry .sdk .trace .export import SpanExporter , SpanExportResult
2018from opentelemetry .trace import StatusCode
2523 INVOKE_AGENT_OPERATION_NAME ,
2624)
2725from .utils import (
26+ build_export_url ,
2827 get_validated_domain_override ,
2928 hex_span_id ,
3029 hex_trace_id ,
@@ -104,7 +103,7 @@ def export(self, spans: Sequence[ReadableSpan]) -> SpanExportResult:
104103 else :
105104 endpoint = DEFAULT_ENDPOINT_URL
106105
107- url = self . _build_url (endpoint , agent_id )
106+ url = build_export_url (endpoint , agent_id , tenant_id , self . _use_s2s_endpoint )
108107
109108 # Debug: Log endpoint being used
110109 logger .info (
@@ -131,18 +130,6 @@ def export(self, spans: Sequence[ReadableSpan]) -> SpanExportResult:
131130 # Basic retry loop
132131 ok = self ._post_with_retries (url , body , headers )
133132
134- # Fallback to IL tenant endpoint if default endpoint failed
135- # and no domain override was set
136- if not ok and not self ._domain_override :
137- discovery = PowerPlatformApiDiscovery (self ._cluster_category )
138- fallback_endpoint = discovery .get_tenant_island_cluster_endpoint (tenant_id )
139- fallback_url = self ._build_url (fallback_endpoint , agent_id )
140- logger .info (
141- f"Falling back to IL tenant endpoint: { fallback_url } "
142- f"(tenant: { tenant_id } , agent: { agent_id } )"
143- )
144- ok = self ._post_with_retries (fallback_url , body , headers )
145-
146133 if not ok :
147134 any_failure = True
148135
@@ -166,32 +153,6 @@ def shutdown(self) -> None:
166153 def force_flush (self , timeout_millis : int = 30000 ) -> bool :
167154 return True
168155
169- # ------------- Helper methods -------------------
170-
171- def _build_url (self , endpoint : str , agent_id : str ) -> str :
172- """Construct the full export URL from endpoint and agent ID.
173-
174- If the endpoint has a scheme (http:// or https://), use it as-is.
175- Otherwise, prepend https://.
176-
177- Args:
178- endpoint: Base endpoint URL or domain.
179- agent_id: The agent identifier to include in the URL path.
180-
181- Returns:
182- The fully constructed export URL with path and query parameters.
183- """
184- endpoint_path = (
185- f"/maven/agent365/service/agents/{ agent_id } /traces"
186- if self ._use_s2s_endpoint
187- else f"/maven/agent365/agents/{ agent_id } /traces"
188- )
189-
190- parsed = urlparse (endpoint )
191- if parsed .scheme and "://" in endpoint :
192- return f"{ endpoint } { endpoint_path } ?api-version=1"
193- return f"https://{ endpoint } { endpoint_path } ?api-version=1"
194-
195156 # ------------- HTTP helper ----------------------
196157
197158 @staticmethod
0 commit comments