Skip to content

Conversation

@fpfp100
Copy link
Contributor

@fpfp100 fpfp100 commented Feb 12, 2026

Summary

Improve PerRequestSpanProcessor to allow set export token at later stage. Introduces updateExportToken() to allow refreshing the per-request export token within the active OTel async context. This is needed for long-running requests where the original token may expire before the trace is flushed.

Changes

  • token-context.ts: Introduce TokenHolder interface so the token is stored as a mutable object reference in OTel Context (which is itself immutable). Add updateExportToken() to refresh the token in-place. Update getExportToken() with backward compatibility for raw string values from older callers.
  • index.ts: Export updateExportToken from the package public API.
  • PerRequestSpanProcessor.test.ts: Add e2e test verifying the refreshed token is used at export time under AsyncLocalStorageContextManager.

@fpfp100 fpfp100 requested a review from a team as a code owner February 12, 2026 01:11
Copilot AI review requested due to automatic review settings February 12, 2026 01:11
@fpfp100 fpfp100 changed the title add updateExportToken for mutable per-request token refresh Improve PerRequestSpanProcessor to allow set export token at later stage Feb 12, 2026
Copy link
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 introduces mutable token refresh capability for per-request observability exports by wrapping the token in a mutable TokenHolder object stored within the immutable OpenTelemetry Context. This enables long-running requests to refresh expired tokens before trace export without creating new contexts.

Changes:

  • Introduced TokenHolder interface and updateExportToken() function to enable in-place token refresh within active OTel context
  • Modified runWithExportToken() to store tokens in a TokenHolder wrapper instead of raw strings
  • Enhanced getExportToken() with backward compatibility for legacy raw string values
  • Exported updateExportToken() from the package public API
  • Added integration test verifying refreshed tokens are used at export time

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/agents-a365-observability/src/tracing/context/token-context.ts Implements TokenHolder pattern for mutable token storage; adds updateExportToken() function; maintains backward compatibility in getExportToken()
packages/agents-a365-observability/src/index.ts Exports new updateExportToken function from package public API
tests/observability/core/PerRequestSpanProcessor.test.ts Adds integration test verifying token refresh works end-to-end with AsyncLocalStorageContextManager

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.

5 participants