Repository navigation
Add a365 hosting middleware - #29
Merged
Hector Hernandez (hectorhdzg) merged 9 commits intoApr 22, 2026
Merged
Hector Hernandez (hectorhdzg) merged 9 commits into
Hector Hernandez (hectorhdzg) merged 9 commits into
Conversation
…icrosoft#25)" This reverts commit 7f986ee.
Add hosting-layer middleware adapted from Agent365-nodejs that enables automatic OpenTelemetry instrumentation for agents-hosting compatible adapters using structural typing (no direct dependency on @microsoft/agents-hosting). Hosting middleware: - BaggageMiddleware: propagates OTel baggage (tenant, agent, caller, channel, conversation) from TurnContext; skips ContinueConversation - OutputLoggingMiddleware: creates OutputScope spans for outgoing messages with parent span linking - ObservabilityHostingManager: one-call middleware registration Hosting utilities: - TurnContextUtils: extract baggage pairs from TurnContext activity - ScopeUtils: create InferenceScope/InvokeAgentScope/ExecuteToolScope pre-populated from TurnContext - BaggageBuilderUtils: populate BaggageBuilder from TurnContext Bug fixes (vendored A365 code vs upstream): - Fix S2S exporter endpoint path (add /otlp/ segment) - Fix SDK version constant to read from package version - Add ~15 missing OpenTelemetryConstants from upstream Also includes: - Comprehensive unit tests (6 test files, 62 new tests) - Hosting middleware sample app (a365HostingMiddleware.ts) - Updated samples README
Hector Hernandez (hectorhdzg)
requested review from
Jackson Weber (JacksonWeber),
Nev (MSNev),
Leighton Chen (lzchen) and
Radhika Gupta (rads-1996)
as code owners
April 21, 2026 23:52
Copilot started reviewing on behalf of
Hector Hernandez (hectorhdzg)
April 21, 2026 23:53
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces A365 “hosting-layer” observability helpers (TurnContext-derived baggage extraction, scope population utilities, and adapter middleware) and wires them into the public exports/samples, along with an Agent365 exporter endpoint update.
Changes:
- Added A365 hosting utilities (
TurnContextLiketypes, baggage/scope helpers) and middleware (BaggageMiddleware,OutputLoggingMiddleware,ObservabilityHostingManager). - Re-exported hosting utilities from
src/a365/index.tsand the rootsrc/index.ts, and added a new sample demonstrating usage. - Updated Agent365 trace export URL path to include
/otlp/agents/…and adjusted unit tests accordingly.
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| test/internal/unit/a365/hosting/turnContextUtils.test.ts | Adds unit coverage for TurnContext baggage helpers and token parsing behavior. |
| test/internal/unit/a365/hosting/scopeUtils.test.ts | Adds unit coverage for populating scopes from TurnContext and error paths. |
| test/internal/unit/a365/hosting/outputLoggingMiddleware.test.ts | Adds unit coverage for OutputLoggingMiddleware span creation/linking and error recording. |
| test/internal/unit/a365/hosting/observabilityHostingManager.test.ts | Adds unit coverage for middleware registration behavior and idempotent configure(). |
| test/internal/unit/a365/hosting/baggageMiddleware.test.ts | Adds unit coverage for baggage propagation and ContinueConversation bypass. |
| test/internal/unit/a365/hosting/baggageBuilderUtils.test.ts | Adds unit coverage for building baggage from TurnContext helpers. |
| test/internal/unit/a365/agent365Exporter.test.ts | Updates expectations for the new /otlp/agents/ exporter path. |
| src/index.ts | Re-exports hosting utilities/middleware from the public package entrypoint. |
| src/a365/middleware/BaggageBuilder.ts | Minor edit around setPairs (lint suppression/comment change). |
| src/a365/index.ts | Re-exports hosting utilities/middleware via the A365 sub-entrypoint. |
| src/a365/hosting/types.ts | Introduces minimal structural interfaces for hosting adapters (Activity/TurnContext/Middleware). |
| src/a365/hosting/turnContextUtils.ts | Adds TurnContext-to-baggage extraction utilities + inline JWT claim extraction. |
| src/a365/hosting/scopeUtils.ts | Adds helpers to derive agent/caller/channel details and populate scopes from TurnContext. |
| src/a365/hosting/outputLoggingMiddleware.ts | Adds middleware to create OutputScope spans for outgoing message activities. |
| src/a365/hosting/observabilityHostingManager.ts | Adds a manager to configure/register hosting middleware on an adapter. |
| src/a365/hosting/index.ts | Barrel exports for hosting utilities/middleware/types. |
| src/a365/hosting/baggageMiddleware.ts | Adds middleware to build/run an OTel baggage scope for each turn. |
| src/a365/hosting/baggageBuilderUtils.ts | Adds helper class to populate BaggageBuilder from TurnContext. |
| src/a365/exporter/Agent365Exporter.ts | Updates exporter endpoint construction to include /otlp/agents/. |
| src/a365/constants.ts | Extends A365 constants and sets telemetry SDK version from distro version constant. |
| samples/src/a365HostingMiddleware.ts | New sample demonstrating hosting middleware + scope utilities usage. |
| samples/README.md | Adds the new sample to the samples index. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
Author
|
Copilot address the comments in this PR |
Radhika Gupta (rads-1996)
approved these changes
Apr 22, 2026
Hector Hernandez (hectorhdzg)
merged commit Apr 22, 2026
9497f3c
into
microsoft:main
5 checks passed
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.
No description provided.