python/autonomous/github-trending: support Foundry endpoints + wire observability flags#322
Open
Yogeshp-MSFT wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for Azure AI Foundry/OpenAI-compatible endpoints and makes Agent 365 observability configuration more flexible via canonical env vars and feature flags.
Changes:
- Add Foundry vs classic Azure OpenAI client selection based on endpoint domain, and strip pasted portal paths.
- Introduce
AZURE_OPENAI_API_VERSIONconfig for classic Azure OpenAI while avoidingapi-versionfor Foundry/openai/v1. - Add canonical
AGENT365OBSERVABILITY__*env var support plus observability/exporter feature flags and improved logging.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| python/autonomous/github-trending/main.py | Adds endpoint parsing and client selection (Foundry vs classic) and refactors observability setup with feature flags + canonical env vars. |
| python/autonomous/github-trending/README.md | Documents the new endpoint compatibility, API version behavior, canonical env vars, and observability flags. |
| python/autonomous/github-trending/.env.template | Updates template to include AZURE_OPENAI_API_VERSION, canonical A365 keys, and revised observability flag comments. |
…bservability flags
* Auto-detect Azure OpenAI vs Foundry endpoints in main.py:
- services.ai.azure.com / cognitiveservices.azure.com -> AsyncOpenAI
with base_url=<host>/openai/v1 and api-key header (no api-version)
- openai.azure.com -> AsyncAzureOpenAI with api_version (existing)
- Strips paths users may paste from the Foundry portal (e.g.
/api/projects/<name>/openai/v1/responses) so any shape works.
* Wire ENABLE_A365_OBSERVABILITY and ENABLE_A365_OBSERVABILITY_EXPORTER
flags as the README documents. Previously the code ignored both,
so docs and runtime behavior diverged.
* Accept canonical AGENT365OBSERVABILITY__* env-var names (what
`a365 setup all` writes to .env on CLI v1.1.206+) with fallback
to legacy AGENT365_* aliases for backward compatibility.
* Add AZURE_OPENAI_API_VERSION env var (default 2024-10-21) so users
on classic Azure OpenAI can pin a specific version. Foundry ignores
this value.
* Update README configuration table and Quick-Start to document
Foundry support, both env-var conventions side-by-side, and
observability flag semantics.
Validation: end-to-end run against a Foundry account with a fresh
Agent 365 identity. chat.completions returned 200 OK, full A365
span tree (invoke_agent -> Chat -> execute_tool) generated and
exported to the A365 backend; HTTP /api/health and / endpoints,
heartbeat, and graceful shutdown all verified.
700448a to
a2684fe
Compare
Three small fixes from the Copilot AI review on PR microsoft#322: 1. Validate AZURE_OPENAI_ENDPOINT scheme + host - urlparse() silently produces empty scheme/netloc on input like "your-resource.openai.azure.com" (no https://), which would cascade into a malformed resource_endpoint such as "://". - Add an explicit check after urlparse() and raise SystemExit with a clear example URL so the failure mode is obvious. 2. Stop sending two conflicting auth headers to Foundry endpoints - The previous Foundry branch passed api_key=AZURE_OPENAI_API_KEY (which the OpenAI SDK turns into Authorization: Bearer ...) AND default_headers={"api-key": AZURE_OPENAI_API_KEY}, sending both headers on every request. - Foundry's /openai/v1 path expects the api-key header, so keep default_headers and pass a placeholder string for api_key (the SDK requires it to be set; Foundry ignores the placeholder Bearer token). 3. Drop the dead apiVersion=="preview" detection branch - The ^preview$ sentinel never matched documented values like 2024-08-01-preview and was never triggered in practice. Host detection alone is sufficient. 4. Align .env.template default with the README - README documents ENABLE_A365_OBSERVABILITY_EXPORTER default as false. - Template was set to true, which would silently start uploading traces when a user copies the template and fills in credentials. - Flip template default to false; users explicitly opt in by changing it. No functional change for users on classic Azure OpenAI endpoints.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was changed
main.pyAZURE_OPENAI_ENDPOINT, strips any path the user pasted from the Foundry portal (e.g./api/projects/<name>/openai/v1/responses), and selects the right OpenAI client:*.services.ai.azure.com/*.cognitiveservices.azure.com→AsyncOpenAIwithbase_url=<host>/openai/v1andapi-keyheader (noapi-versionquery, which the/openai/v1path rejects).*.openai.azure.com→AsyncAzureOpenAIwithazure_endpointandapi-version(existing behavior).ENABLE_A365_OBSERVABILITYandENABLE_A365_OBSERVABILITY_EXPORTERas the README documents. Previously the code silently ignored both flags.ENABLE_A365_OBSERVABILITY=falsenow skipsuse_microsoft_opentelemetry()entirely;ENABLE_A365_OBSERVABILITY_EXPORTER=falseproduces spans on the console but does not upload them.AGENT365OBSERVABILITY__*env-var names (whata365 setup allwrites to.env) with fallback to the legacyAGENT365_*aliases.AZURE_OPENAI_API_VERSIONenv var (default2024-10-21) so users on classic Azure OpenAI can pin to a specific GA/preview version. Foundry endpoints ignore it..env.templateandREADME.mdAGENT365OBSERVABILITY__*) and legacy (AGENT365_*) env-var names side-by-side.AZURE_OPENAI_API_VERSIONand the runtime semantics of both observability flags.Why
*.openai.azure.comresources. With a Foundry endpoint,chat.completions.create()failed with400 BadRequest — api-version query parameter is not allowed when using /v1 path.ENABLE_A365_OBSERVABILITY[_EXPORTER]as required, but the code wasn't actually reading them — runtime behavior didn't match the docs.a365 setup all(CLI v1.1.206+) auto-stamps.envwithAGENT365OBSERVABILITY__*keys, but the upstream code only read the legacyAGENT365_*names. Users following the recommended CLI path got "credentials not configured" warnings even with a fully-stamped.env.Validation
End-to-end runs against a Foundry account with a fresh Agent 365 identity:
python main.pystartupObservability configured (a365_exporter=true, credentials_present=true)chat.completionsagainst Foundry endpointget_trending_repositories)Observability token registered(initial + 50-min refresh)invoke_agent→Chat gpt-4o→execute_toolwith matchingtraceIdENABLE_A365_OBSERVABILITY_EXPORTER=falsetoggleAGENT365_*env-var names/api/healthand/