From 2cd7a0931a982156281ba695f40c6c714cfa80d2 Mon Sep 17 00:00:00 2001 From: Peng Fan Date: Wed, 13 May 2026 14:25:15 -0700 Subject: [PATCH 1/2] Revert "Fix getCallerBaggagePairs: resolve userId across all channels (#250)" This reverts commit 1711b6590e84895198c28dee11677354f7a8589c. --- .../src/utils/TurnContextUtils.ts | 4 +- tests/jest.config.cjs | 1 - .../hosting/BaggageBuilderUtils.test.ts | 2 +- .../hosting/TurnContextUtils.test.ts | 52 ------------------- 4 files changed, 3 insertions(+), 56 deletions(-) diff --git a/packages/agents-a365-observability-hosting/src/utils/TurnContextUtils.ts b/packages/agents-a365-observability-hosting/src/utils/TurnContextUtils.ts index 88dcc36b..f6fda162 100644 --- a/packages/agents-a365-observability-hosting/src/utils/TurnContextUtils.ts +++ b/packages/agents-a365-observability-hosting/src/utils/TurnContextUtils.ts @@ -27,10 +27,10 @@ export function getCallerBaggagePairs(turnContext: TurnContext): Array<[string, return []; } const from = turnContext.activity.from; - + const upn = from.agenticUserId; const pairs: Array<[string, string | undefined]> = [ - [OpenTelemetryConstants.USER_ID_KEY, from.aadObjectId || from.agenticUserId || from.id], + [OpenTelemetryConstants.USER_ID_KEY, from.aadObjectId], [OpenTelemetryConstants.USER_NAME_KEY, from.name], [OpenTelemetryConstants.USER_EMAIL_KEY, upn], [OpenTelemetryConstants.GEN_AI_CALLER_AGENT_APPLICATION_ID_KEY, from.agenticAppBlueprintId] diff --git a/tests/jest.config.cjs b/tests/jest.config.cjs index be68efed..3627b5ff 100644 --- a/tests/jest.config.cjs +++ b/tests/jest.config.cjs @@ -71,7 +71,6 @@ module.exports = { '^@microsoft/agents-a365-observability$': '/packages/agents-a365-observability/src', '^@microsoft/agents-a365-observability-extensions-langchain$': '/packages/agents-a365-observability-extensions-langchain/src', '^@microsoft/agents-a365-observability-extensions-openai$': '/packages/agents-a365-observability-extensions-openai/src', - '^@microsoft/agents-a365-observability-hosting$': '/packages/agents-a365-observability-hosting/src', '^@microsoft/agents-a365-observability-tokencache$': '/packages/agents-a365-observability-tokencache/src', '^@microsoft/agents-a365-tooling$': '/packages/agents-a365-tooling/src', '^@microsoft/agents-a365-tooling-extensions-claude$': '/packages/agents-a365-tooling-extensions-claude/src', diff --git a/tests/observability/extension/hosting/BaggageBuilderUtils.test.ts b/tests/observability/extension/hosting/BaggageBuilderUtils.test.ts index 23983744..023d2d03 100644 --- a/tests/observability/extension/hosting/BaggageBuilderUtils.test.ts +++ b/tests/observability/extension/hosting/BaggageBuilderUtils.test.ts @@ -45,7 +45,7 @@ describe('BaggageBuilderUtils', () => { expect(result).toBe(builder); // Validate every expected OpenTelemetry baggage key and value const asObj = Object.fromEntries(capturedPairs); - expect(asObj[OpenTelemetryConstants.USER_ID_KEY]).toBe('agentic-user-1'); + expect(asObj[OpenTelemetryConstants.USER_ID_KEY]).toBeUndefined(); expect(asObj[OpenTelemetryConstants.USER_NAME_KEY]).toBe('User One'); expect(asObj[OpenTelemetryConstants.USER_EMAIL_KEY]).toBe('agentic-user-1'); expect(asObj[OpenTelemetryConstants.GEN_AI_AGENT_ID_KEY]).toBe('agent-app-1'); diff --git a/tests/observability/extension/hosting/TurnContextUtils.test.ts b/tests/observability/extension/hosting/TurnContextUtils.test.ts index 8d811c0a..675c01ce 100644 --- a/tests/observability/extension/hosting/TurnContextUtils.test.ts +++ b/tests/observability/extension/hosting/TurnContextUtils.test.ts @@ -32,58 +32,6 @@ describe('TurnContextUtils', () => { expect(pairs.length).toBeGreaterThan(0); }); - it('should fall back to from.id for userId when aadObjectId is undefined (non-Teams channel)', () => { - const ctx = { - activity: { - from: { id: 'user1', name: 'User One' }, - recipient: { id: 'agent1', name: 'Agent One' }, - conversation: { id: 'conv-1' }, - }, - } as any; - const pairs = getCallerBaggagePairs(ctx); - const obj = Object.fromEntries(pairs); - expect(obj[OpenTelemetryConstants.USER_ID_KEY]).toBe('user1'); - }); - - it('should fall back to agenticUserId for userId when aadObjectId is undefined (A2A)', () => { - const ctx = { - activity: { - from: { id: 'user1', name: 'User One', agenticUserId: 'agentic-user-1' }, - recipient: { id: 'agent1', name: 'Agent One' }, - conversation: { id: 'conv-1' }, - }, - } as any; - const pairs = getCallerBaggagePairs(ctx); - const obj = Object.fromEntries(pairs); - expect(obj[OpenTelemetryConstants.USER_ID_KEY]).toBe('agentic-user-1'); - }); - - it('should prefer aadObjectId for userId when all three fields are set', () => { - const ctx = { - activity: { - from: { id: 'user1', name: 'User One', aadObjectId: 'aad-123', agenticUserId: 'agentic-user-1' }, - recipient: { id: 'agent1', name: 'Agent One' }, - conversation: { id: 'conv-1' }, - }, - } as any; - const pairs = getCallerBaggagePairs(ctx); - const obj = Object.fromEntries(pairs); - expect(obj[OpenTelemetryConstants.USER_ID_KEY]).toBe('aad-123'); - }); - - it('should resolve userId to agenticUserId when it is a GUID (A2A with GUID agenticUserId)', () => { - const ctx = { - activity: { - from: { id: 'user1', name: 'User One', agenticUserId: 'bef730f4-d6f5-4ffb-b759-26ffa449ed7e' }, - recipient: { id: 'agent1', name: 'Agent One' }, - conversation: { id: 'conv-1' }, - }, - } as any; - const pairs = getCallerBaggagePairs(ctx); - const obj = Object.fromEntries(pairs); - expect(obj[OpenTelemetryConstants.USER_ID_KEY]).toBe('bef730f4-d6f5-4ffb-b759-26ffa449ed7e'); - }); - it('should get target agent baggage pairs', () => { const pairs = getTargetAgentBaggagePairs(mockTurnContext); expect(Array.isArray(pairs)).toBe(true); From d3e0ce006540ff8810a0f2a2246f966928df2d4b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 13 May 2026 22:36:31 +0000 Subject: [PATCH 2/2] fix: remove trailing whitespace in TurnContextUtils Agent-Logs-Url: https://github.com/microsoft/Agent365-nodejs/sessions/6d50d8d4-7449-4f9d-9fb0-5a42e75c19af Co-authored-by: fpfp100 <126631706+fpfp100@users.noreply.github.com> --- .../src/utils/TurnContextUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/agents-a365-observability-hosting/src/utils/TurnContextUtils.ts b/packages/agents-a365-observability-hosting/src/utils/TurnContextUtils.ts index f6fda162..0710034d 100644 --- a/packages/agents-a365-observability-hosting/src/utils/TurnContextUtils.ts +++ b/packages/agents-a365-observability-hosting/src/utils/TurnContextUtils.ts @@ -27,7 +27,7 @@ export function getCallerBaggagePairs(turnContext: TurnContext): Array<[string, return []; } const from = turnContext.activity.from; - + const upn = from.agenticUserId; const pairs: Array<[string, string | undefined]> = [ [OpenTelemetryConstants.USER_ID_KEY, from.aadObjectId],