Skip to content

Commit 21a7083

Browse files
CopilotnikhilNavanikhilc-microsoft
authored
Default a365_exporter endpoint to agent365.svc.cloud.microsoft (#184)
* Initial plan * Default a365_exporter endpoint to agent365.svc.cloud.microsoft with IL tenant fallback Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com> * Address code review feedback: rename test and improve docstring Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com> * remove island tenant reference * update comments --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com> Co-authored-by: Nikhil Chitlur Navakiran (from Dev Box) <nikhilc@microsoft.com>
1 parent 25ed4b9 commit 21a7083

3 files changed

Lines changed: 301 additions & 310 deletions

File tree

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

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
import time
1212
from collections.abc import Callable, Sequence
1313
from typing import Any, final
14-
from urllib.parse import urlparse
1514

1615
import requests
17-
from microsoft_agents_a365.runtime.power_platform_api_discovery import PowerPlatformApiDiscovery
1816
from opentelemetry.sdk.trace import ReadableSpan
1917
from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult
2018
from opentelemetry.trace import StatusCode
@@ -25,6 +23,7 @@
2523
INVOKE_AGENT_OPERATION_NAME,
2624
)
2725
from .utils import (
26+
build_export_url,
2827
get_validated_domain_override,
2928
hex_span_id,
3029
hex_trace_id,
@@ -39,6 +38,7 @@
3938
# Hardcoded constants - not configurable
4039
DEFAULT_HTTP_TIMEOUT_SECONDS = 30.0
4140
DEFAULT_MAX_RETRIES = 3
41+
DEFAULT_ENDPOINT_URL = "https://agent365.svc.cloud.microsoft"
4242

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

100-
# Resolve endpoint + token
100+
# Resolve endpoint: domain override > default URL
101101
if self._domain_override:
102102
endpoint = self._domain_override
103103
else:
104-
discovery = PowerPlatformApiDiscovery(self._cluster_category)
105-
endpoint = discovery.get_tenant_island_cluster_endpoint(tenant_id)
104+
endpoint = DEFAULT_ENDPOINT_URL
106105

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"
106+
url = build_export_url(endpoint, agent_id, tenant_id, self._use_s2s_endpoint)
124107

125108
# Debug: Log endpoint being used
126109
logger.info(
@@ -146,6 +129,7 @@ def export(self, spans: Sequence[ReadableSpan]) -> SpanExportResult:
146129

147130
# Basic retry loop
148131
ok = self._post_with_retries(url, body, headers)
132+
149133
if not ok:
150134
any_failure = True
151135

@@ -169,8 +153,6 @@ def shutdown(self) -> None:
169153
def force_flush(self, timeout_millis: int = 30000) -> bool:
170154
return True
171155

172-
# ------------- Helper methods -------------------
173-
174156
# ------------- HTTP helper ----------------------
175157

176158
@staticmethod

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,32 @@ def get_validated_domain_override() -> str | None:
197197
return domain_override
198198

199199

200+
def build_export_url(
201+
endpoint: str, agent_id: str, tenant_id: str, use_s2s_endpoint: bool = False
202+
) -> str:
203+
"""Construct the full export URL from endpoint and agent ID.
204+
205+
Args:
206+
endpoint: Base endpoint URL or domain.
207+
agent_id: The agent identifier to include in the URL path.
208+
tenant_id: The tenant identifier to include in the URL path.
209+
use_s2s_endpoint: Whether to use the S2S endpoint path format.
210+
211+
Returns:
212+
The fully constructed export URL with path and query parameters.
213+
"""
214+
endpoint_path = (
215+
f"/observabilityService/tenants/{tenant_id}/agents/{agent_id}/traces"
216+
if use_s2s_endpoint
217+
else f"/observability/tenants/{tenant_id}/agents/{agent_id}/traces"
218+
)
219+
220+
parsed = urlparse(endpoint)
221+
if parsed.scheme and "://" in endpoint:
222+
return f"{endpoint}{endpoint_path}?api-version=1"
223+
return f"https://{endpoint}{endpoint_path}?api-version=1"
224+
225+
200226
def is_agent365_exporter_enabled() -> bool:
201227
"""Check if Agent 365 exporter is enabled."""
202228
# Check environment variable

0 commit comments

Comments
 (0)