Skip to content

Fix: OpenAI sample agent - propagate tenantId and fix service name in observability config#278

Open
Akshit0022 wants to merge 1 commit intomicrosoft:mainfrom
Akshit0022:fix/add-tenant-id-to-agent-details
Open

Fix: OpenAI sample agent - propagate tenantId and fix service name in observability config#278
Akshit0022 wants to merge 1 commit intomicrosoft:mainfrom
Akshit0022:fix/add-tenant-id-to-agent-details

Conversation

@Akshit0022
Copy link
Copy Markdown

Summary

Updates the nodejs/openai/sample-agent to propagate tenant context through the observability pipeline and fixes an incorrect service name that was a copy-paste artifact from the Claude sample.

Changes

src/client.ts

• L42: Changed observability service name from 'TypeScript Claude Sample Agent' to 'TypeScript OpenAI Sample Agent'
Reason: Copy-paste artifact from the Claude sample caused this agent's telemetry to be misattributed.

• L73: Added tenantId extraction from turnContext.activity.recipient.tenantId with fallback to connections__service_connection__settings__tenantId env var
Reason: Tenant context is needed downstream for observability span correlation in multi-tenant deployments.

• L107: Updated new OpenAIClient(agent) to new OpenAIClient(agent, tenantId)
Reason: Threads the resolved tenant ID into the client instance so it can be included in AgentDetails.

• L114–L118: Added tenantId: string field and updated OpenAIClient constructor to accept it
Reason: The client needs to hold the tenant ID for use when creating observability scopes.

• L157: Added tenantId: this.tenantId to AgentDetails in invokeAgentWithScope()
Reason: Without tenantId on AgentDetails, InferenceScope traces lack tenant context, making it impossible to filter and correlate traces per tenant.

@Akshit0022 Akshit0022 requested a review from a team as a code owner April 20, 2026 09:13
Copilot AI review requested due to automatic review settings April 20, 2026 09:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Node.js OpenAI sample agent to (1) correct its observability service name and (2) propagate tenantId into observability scope metadata to support multi-tenant trace correlation.

Changes:

  • Fixes the observability service name to “TypeScript OpenAI Sample Agent”.
  • Extracts tenantId from turnContext.activity.recipient.tenantId with an env var fallback and threads it into OpenAIClient.
  • Adds tenantId onto AgentDetails passed to InferenceScope.start().

Comment on lines 71 to +73
export async function getClient(authorization: Authorization, authHandlerName: string, turnContext: TurnContext, displayName = 'unknown'): Promise<Client> {
const modelName = getModelName();
const tenantId = turnContext?.activity?.recipient?.tenantId ?? process.env.connections__service_connection__settings__tenantId ?? '';
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tenantId resolution here can become inconsistent with the tenant ID used during observability token preloading in src/agent.ts (which currently derives tenantId only from turnContext.activity.recipient.tenantId). In local/Playground scenarios where recipient.tenantId is missing, this code will fall back to the connections__...__tenantId env var, but the preloaded token may have been cached under an empty-tenant key; the exporter/tokenResolver will then look up a different key and fail to resolve a token. Consider centralizing tenantId resolution (and treating empty string as missing) so both token preloading and AgentDetails.tenantId use the exact same value.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants