nodejs/autonomous/github-trending: support Foundry endpoints + accept canonical CLI env-var names#323
Open
Yogeshp-MSFT wants to merge 2 commits into
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 both classic Azure OpenAI and Foundry/AI Services endpoints, while making Agent 365 observability configurable via feature flags and updated environment variable conventions.
Changes:
- Add configurable
AZURE_OPENAI_API_VERSIONand pass it into the trending service. - Support Foundry
/openai/v1endpoints by normalizing the endpoint and switching client construction based on host. - Add observability feature flags and accept canonical
agent365Observability__*env vars with legacy fallbacks.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| nodejs/autonomous/github-trending/src/index.ts | Adds API version plumb-through and observability flags/env-var fallbacks. |
| nodejs/autonomous/github-trending/src/github-trending-service.ts | Creates OpenAI client differently for Foundry vs classic Azure OpenAI; normalizes endpoint. |
| nodejs/autonomous/github-trending/README.md | Documents new env vars, flags, and Foundry endpoint support. |
| nodejs/autonomous/github-trending/.env.template | Updates template with canonical A365 env var names, flags, and Azure OpenAI API version. |
… canonical CLI env-var names
Adds three improvements to the Node.js github-trending sample:
1. Foundry / AI Services endpoint support
- Detect *.services.ai.azure.com / *.cognitiveservices.azure.com hosts and
use a plain OpenAI client at <host>/openai/v1 with an api-key default
header (the /openai/v1 path rejects the api-version query parameter that
AzureOpenAI would otherwise append).
- Strip any path the user pasted from the Foundry portal (e.g.
/api/projects/<name>, /openai/v1, /openai/v1/responses) so the endpoint
normalizes to scheme + host before client construction.
- Classic *.openai.azure.com endpoints continue to use AzureOpenAI with
apiVersion (existing behavior).
- Make AZURE_OPENAI_API_VERSION configurable via env (default 2024-10-21);
was previously hard-coded to 2024-12-01-preview.
2. Accept canonical agent365Observability__* env-var names
- The Agent 365 CLI (a365 setup all) auto-stamps these into .env.
- Read them first, fall back to legacy AGENT365_* names for backward
compatibility with hand-edited or older .env files.
3. Optional observability feature flags (parity with Python sample)
- ENABLE_A365_OBSERVABILITY (default true) — master switch; false skips
useMicrosoftOpenTelemetry() entirely.
- ENABLE_A365_OBSERVABILITY_EXPORTER (default false) — when false, spans
are produced but go only to the console exporter; set to true to upload
to the A365 observability backend.
.env.template and README.md are updated to document Foundry support, both
canonical and legacy env-var names side-by-side, and the observability flags.
Validation:
- End-to-end run against a Foundry account with a fresh agent identity:
- chat.completions returned HTTP 200 (Foundry path /openai/v1).
- 3-hop FMI token chain registered initial + refresh tokens.
- Span tree invoke_agent -> Chat -> execute_tool with matching traceId.
- A365 backend export succeeded (correlation IDs captured).
- HTTP /api/health returns 200, / returns 200, /nonexistent returns 404.
- Heartbeat fires every 60 s; SIGINT triggers graceful shutdown.
- Legacy AGENT365_* env-var fallback verified by removing canonical names.
- No secrets, GUIDs, or API keys land in the diff (.env and a365.*config.json
are in root .gitignore).
d4c9434 to
e666c80
Compare
Addresses the 4 review comments on PR microsoft#323: 1. URL parsing safety — wrap `new URL(config.endpoint)` in try/catch and validate that the parsed URL has an http(s) scheme and a host. Misconfigured values now produce a clear "must be an absolute URL" error instead of a confusing TypeError at startup. 2. Drop the `^preview$` apiVersion sentinel — it never matched the documented examples (`2024-08-01-preview`, `2025-01-01-preview`). Foundry detection now relies entirely on the endpoint hostname, which is the documented and predictable signal. 3. Make `apiVersion` optional in `TrendingServiceConfig` — defaults to `2024-10-21` inside `startTrendingService()` so the exported interface is no longer a breaking change for external callers, while preserving the environment-driven override path through `src/index.ts`. 4. Document why the Foundry path passes the API key via both `apiKey` and `defaultHeaders["api-key"]` — the SDK requires `apiKey` on construction; Foundry uses the `api-key` header for auth and ignores the resulting `Authorization: Bearer` header. 5. Flip `.env.template` `ENABLE_A365_OBSERVABILITY_EXPORTER` default to `false` to match the runtime default and the README. Added a comment pointing users at `true` as the explicit opt-in once credentials are configured, so copying the template no longer silently uploads traces.
ecac9e4 to
659a62e
Compare
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
src/github-trending-service.ts*.services.ai.azure.com/*.cognitiveservices.azure.com→ plainOpenAIclient withbaseURL=<host>/openai/v1andapi-keydefault header.*.openai.azure.com→ existingAzureOpenAIclient withapiVersionquery string./,/api/projects/<name>,/openai/v1,/openai/v1/responsesand still get a working endpoint.apiVersiontoTrendingServiceConfig(was hard-coded to2024-12-01-preview).src/index.tsagent365Observability__*env-var names with fallback to legacyAGENT365_*aliases.ENABLE_A365_OBSERVABILITYandENABLE_A365_OBSERVABILITY_EXPORTERas opt-in flags for parity with the Python sample.AZURE_OPENAI_API_VERSIONthrough to the trending service..env.templateandREADME.mdagent365Observability__*placeholder keys.Why
400 BadRequest — api-version query parameter is not allowed when using /v1 path, blocking the sample for users on a Foundry / AI Services account..envwithagent365Observability__*keys, but the upstream code only readAGENT365_*— leading to silent fallback to placeholder values.AZURE_OPENAI_API_VERSIONis now configurable so users can pin to whichever GA/preview version their classic Azure OpenAI resource supports.Validation
End-to-end runs against a Foundry account with a fresh Agent 365 identity (
a365 setup all --agent-name Github-trending-nodejs):npm run devstartupObservability configured (a365_exporter=true, credentials_present=true)/openai/v1/chat/completionschat.completionsagainst Foundry endpointinvoke_agent→Chat→execute_toolwith matchingtraceId[EVENT]: agent365-export succeeded — All spans exported successfullyAGENT365_*env names/api/health,/,/nonexistent