Migrate Node.js LangChain sample to GA packages and Microsoft.OpenTelemetry distro#309
Open
biswapm wants to merge 2 commits into
Open
Migrate Node.js LangChain sample to GA packages and Microsoft.OpenTelemetry distro#309biswapm wants to merge 2 commits into
biswapm wants to merge 2 commits into
Conversation
…emetry distro
- Upgrade @microsoft/agents-a365-{notifications,tooling,tooling-extensions-langchain,runtime}
from preview (0.2.0-preview.x) to GA (^1.0.0)
- Drop @microsoft/agents-a365-observability and -observability-hosting; their exports
(InferenceScope, BaggageBuilder, BaggageBuilderUtils, AgenticTokenCacheInstance)
are now re-exported from @microsoft/opentelemetry
- Rename Request type import to A365Request to avoid clashing with DOM Request
- Use refreshObservabilityToken (lowercase) per GA naming; drop scopes arg
(singleton ships with the A365 observability scope as default)
- Cast TurnContext / Authorization to satisfy stricter TurnContextLike /
AuthorizationLike shapes in GA
- Use real AZURE_OPENAI_DEPLOYMENT and aggregate usage_metadata across React-loop
AI messages in the manual InferenceScope (was hardcoded gpt-4o-mini / 45 / 78)
- Switch AzureChatOpenAI to azureOpenAIBasePath so cognitiveservices.azure.com
endpoints work (previous endpoint-parsing only handled openai.azure.com)
- Enable enableConsoleExporters in useMicrosoftOpenTelemetry so spans are visible
alongside the Agent365 backend export
- Add AZURE_OPENAI_API_VERSION to env/.env.playground.user template and map it
in m365agents.playground.yml
Dependency ReviewThe following issues were found:
License Issuesnodejs/langchain/sample-agent/package.json
OpenSSF Scorecard
Scanned Files
|
- Add Environment Settings block (NODE_ENV, PORT) with production-mode note - Add agent365Observability__* placeholders (stamped by a365 setup all) - Add connections__service_connection__settings__scopes placeholder - Add agentic_connectionName placeholder; switch agentic_scopes to graph default - Drop redundant ENABLE_A365_OBSERVABILITY_EXPORTER and A365_OBSERVABILITY_LOG_LEVEL (sample passes a365.enabled programmatically; distro internal logging is rarely needed in a sample) - Drop unused legacy vars (DEBUG, AZURE_EXPERIMENTAL_*, AZURE_TRACING_*, OPENAI_AGENTS_DISABLE_TRACING, OTEL_SDK_DISABLED, CONNECTION_STRING, USE_AGENTIC_AUTH) - Keep LLM, MCP Tooling, and MCPPlatform Configuration blocks unchanged
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Node.js LangChain sample agent to use the GA @microsoft/agents-a365-* packages and the @microsoft/opentelemetry distro, while improving manual InferenceScope telemetry accuracy (real deployment/model + aggregated token usage) and expanding Azure OpenAI endpoint compatibility.
Changes:
- Migrate observability APIs (
InferenceScope, baggage helpers,AgenticTokenCacheInstance) to@microsoft/opentelemetryand update API-shape changes (e.g.,A365Request,refreshObservabilityToken). - Improve manual inference telemetry by aggregating
usage_metadataacross LangChain React-loop messages and recording deployment/model dynamically. - Switch Azure OpenAI client configuration to
azureOpenAIBasePathand wireAZURE_OPENAI_API_VERSIONthrough playground env templates.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| nodejs/langchain/sample-agent/src/index.ts | Switches to @microsoft/opentelemetry exports and enables console exporters in the OpenTelemetry distro config. |
| nodejs/langchain/sample-agent/src/client.ts | Updates observability imports/types, switches Azure OpenAI config, and fixes manual InferenceScope model + token usage recording. |
| nodejs/langchain/sample-agent/src/agent.ts | Moves baggage/token-cache observability helpers to @microsoft/opentelemetry and updates token refresh API call. |
| nodejs/langchain/sample-agent/package.json | Upgrades Agent365 packages to GA and removes preview observability packages. |
| nodejs/langchain/sample-agent/m365agents.playground.yml | Adds AZURE_OPENAI_API_VERSION env mapping for Playground runs. |
| nodejs/langchain/sample-agent/env/.env.playground.user | Adds AZURE_OPENAI_API_VERSION placeholder to the user env template. |
Comment on lines
15
to
17
| useMicrosoftOpenTelemetry({ | ||
| enableConsoleExporters: true, | ||
| a365: { |
Comment on lines
151
to
+158
| /** | ||
| * Sends a user message to the LangChain agent and returns the AI's response. | ||
| * Handles streaming results and error reporting. | ||
| * | ||
| * @param {string} userMessage - The message or prompt to send to the agent. | ||
| * @returns {Promise<string>} The response from the agent, or an error message if the query fails. | ||
| */ | ||
| async invokeAgent(userMessage: string): Promise<string> { | ||
| async invokeAgent(userMessage: string): Promise<{ content: string; inputTokens: number; outputTokens: number; finishReason: string }> { |
Comment on lines
199
to
204
| async invokeInferenceScope(prompt: string) { | ||
| const model = process.env.AZURE_OPENAI_DEPLOYMENT || process.env.OPENAI_MODEL || 'unknown'; | ||
| const inferenceDetails: InferenceDetails = { | ||
| operationName: InferenceOperationType.CHAT, | ||
| model: "gpt-4o-mini", | ||
| model, | ||
| }; |
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.
Summary
@microsoft/agents-a365-*packages from preview (0.2.0-preview.x) to GA (^1.0.0); drop the now-folded-inagents-a365-observabilityandagents-a365-observability-hostingpackages — their public surface (InferenceScope,BaggageBuilder,BaggageBuilderUtils,AgenticTokenCacheInstance) is now re-exported from@microsoft/opentelemetryInferenceScopeto record the real Azure OpenAI deployment + aggregatedusage_metadataacross the React-loop AI messages (was hardcodedgpt-4o-mini/ 45 / 78)AzureChatOpenAItoazureOpenAIBasePathso the client works against*.cognitiveservices.azure.comendpoints, not just*.openai.azure.comenableConsoleExportersinuseMicrosoftOpenTelemetry()so spans are observable in console alongside the Agent365 backend exportAZURE_OPENAI_API_VERSIONtoenv/.env.playground.usertemplate and the matchingm365agents.playground.ymlenv mappingAPI shape changes accommodated
Requesttype renamed →A365Request(avoids DOMRequestclash)RefreshObservabilityToken→refreshObservabilityToken(camelCase)refreshObservabilityTokenno longer requires explicitscopesarg (singleton ships A365 observability scope)getObservabilityAuthenticationScope()callTurnContextLike/AuthorizationLikeare stricter thanagents-hostingtypesas anycasts at the two call sitesTest plan
npm run build✓npm run dev:teamsfx:playground) — gen_ai spans forchat(azure) andinvoke_agent(langchain) emit with full Microsoft baggage (tenant, user, conversation)npm run devwith NODE_ENV=production +.envstamped bya365 setup all --aiteammate) — Teams traffic via devtunnel passes JWT middleware;Chatmanual scope now shows real model (gpt-5.4) and real token usageagents.auth.token.durationhistogram populated foragentic_instanceandagentic_usermethods)