Skip to content

Commit 5e773ae

Browse files
CopilotnikhilNava
andcommitted
Default a365_exporter endpoint to agent365.svc.cloud.microsoft with IL tenant fallback
Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com>
1 parent 9963902 commit 5e773ae

File tree

2 files changed

+261
-198
lines changed

2 files changed

+261
-198
lines changed

libraries/microsoft-agents-a365-observability-core/microsoft_agents_a365/observability/core/exporters/agent365_exporter.py

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
# Hardcoded constants - not configurable
4040
DEFAULT_HTTP_TIMEOUT_SECONDS = 30.0
4141
DEFAULT_MAX_RETRIES = 3
42+
DEFAULT_ENDPOINT_URL = "https://agent365.svc.cloud.microsoft"
4243

4344
# Create logger for this module - inherits from 'microsoft_agents_a365.observability.core'
4445
logger = logging.getLogger(__name__)
@@ -97,30 +98,13 @@ def export(self, spans: Sequence[ReadableSpan]) -> SpanExportResult:
9798
payload = self._build_export_request(activities)
9899
body = json.dumps(payload, separators=(",", ":"), ensure_ascii=False)
99100

100-
# Resolve endpoint + token
101+
# Resolve endpoint: domain override > default URL > IL tenant fallback
101102
if self._domain_override:
102103
endpoint = self._domain_override
103104
else:
104-
discovery = PowerPlatformApiDiscovery(self._cluster_category)
105-
endpoint = discovery.get_tenant_island_cluster_endpoint(tenant_id)
105+
endpoint = DEFAULT_ENDPOINT_URL
106106

107-
endpoint_path = (
108-
f"/maven/agent365/service/agents/{agent_id}/traces"
109-
if self._use_s2s_endpoint
110-
else f"/maven/agent365/agents/{agent_id}/traces"
111-
)
112-
113-
# Construct URL - if endpoint has a scheme (http:// or https://), use it as-is
114-
# Otherwise, prepend https://
115-
# Note: Check for "://" to distinguish between real protocols and domain:port format
116-
# (urlparse treats "example.com:8080" as having scheme="example.com")
117-
parsed = urlparse(endpoint)
118-
if parsed.scheme and "://" in endpoint:
119-
# Endpoint is a full URL, append path
120-
url = f"{endpoint}{endpoint_path}?api-version=1"
121-
else:
122-
# Endpoint is just a domain (possibly with port), prepend https://
123-
url = f"https://{endpoint}{endpoint_path}?api-version=1"
107+
url = self._build_url(endpoint, agent_id)
124108

125109
# Debug: Log endpoint being used
126110
logger.info(
@@ -146,6 +130,19 @@ def export(self, spans: Sequence[ReadableSpan]) -> SpanExportResult:
146130

147131
# Basic retry loop
148132
ok = self._post_with_retries(url, body, headers)
133+
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+
149146
if not ok:
150147
any_failure = True
151148

@@ -171,6 +168,23 @@ def force_flush(self, timeout_millis: int = 30000) -> bool:
171168

172169
# ------------- Helper methods -------------------
173170

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+
endpoint_path = (
178+
f"/maven/agent365/service/agents/{agent_id}/traces"
179+
if self._use_s2s_endpoint
180+
else f"/maven/agent365/agents/{agent_id}/traces"
181+
)
182+
183+
parsed = urlparse(endpoint)
184+
if parsed.scheme and "://" in endpoint:
185+
return f"{endpoint}{endpoint_path}?api-version=1"
186+
return f"https://{endpoint}{endpoint_path}?api-version=1"
187+
174188
# ------------- HTTP helper ----------------------
175189

176190
@staticmethod

0 commit comments

Comments
 (0)