Skip to content

refactor(a365): centralize request context in the base scope - #243

Merged
Nikhil Navakiran (nikhilNava) merged 5 commits into
mainfrom
fix/a365-scope-attribute-precedence
Oct 1, 2026
Merged

Nikhil Navakiran (nikhilNava) merged 5 commits into
mainfrom
fix/a365-scope-attribute-precedence

Conversation

@nikhilNava

@nikhilNava Nikhil Navakiran (nikhilNava) commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • centralize shared request context in OpenTelemetryScope for invoke-agent, inference, execute-tool, output, and guardrail spans
  • map session ID, conversation ID, channel name/link, and operationSource (service.name) consistently across scopes
  • retain full last-write-wins behavior for recordAttributes(), including attributes initially set by the span builder or typed scope methods
  • ensure explicit request values override baggage-populated values and absent request fields leave baggage values intact

Cross-repository alignment

  • ports the live base-scope request cleanup from opentelemetry-distro-dotnet#165
  • follows the .NET live-scope last-write-wins behavior for generic attribute recording
  • intentionally does not adopt Python's recorded/owned-attribute protection

Notable behavior changes

  • Request now supports optional operationSource
  • OutputScope and ApplyGuardrailScope now propagate sessionId through the shared base mapping
  • guardrail-specific input content and all other scope-specific attributes remain handled by their concrete scopes
  • generic recordAttributes() calls may overwrite base, builder, and typed-setter values

Validation

  • npm test -- --run test/internal/unit/a365 — 683 passed
  • npm run build
  • npm run lint — no errors (pre-existing warnings only)
  • npm run format
  • git diff --check

nikhilc-microsoft and others added 2 commits September 30, 2026 14:19
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9ccc29b9-bf5d-4725-be3b-c4276b233c4c
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 9ccc29b9-bf5d-4725-be3b-c4276b233c4c

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The new tests do not cover a key that becomes scope-owned through a typed setter after creation.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

This PR makes A365 scope builders’ populated span attributes take precedence over later recordAttributes() calls.

Changes:

  • Track keys populated by the span builder or typed setters, while leaving absent keys writable.
  • Add precedence tests and a changelog entry.
File Description
test/​internal/​unit/​a365/​scopes.test.ts Tests attribute precedence and generic writes.
src/​a365/​scopes/​OpenTelemetryScope.ts Tracks scope-owned keys and skips generic overwrites.
CHANGELOG.md Documents the fix.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread test/internal/unit/a365/scopes.test.ts
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 9834b6ca-9d85-4b99-aa3d-c346c03485d2
Copilot AI balanced review requested due to automatic review settings September 30, 2026 21:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The focused changes have relevant tests, and the review identified no unresolved issues.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)

@nikhilNava Nikhil Navakiran (nikhilNava) changed the title fix(a365): preserve scope attribute precedence refactor(a365): centralize request context and preserve attribute precedence Sep 30, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 9834b6ca-9d85-4b99-aa3d-c346c03485d2
Copilot AI balanced review requested due to automatic review settings September 30, 2026 21:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The focused refactor has relevant tests and no unresolved review findings.

Review effort: Balanced
Findings: None

Resolved since last review (1)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 9834b6ca-9d85-4b99-aa3d-c346c03485d2
Copilot AI balanced review requested due to automatic review settings September 30, 2026 21:34
@nikhilNava Nikhil Navakiran (nikhilNava) changed the title refactor(a365): centralize request context and preserve attribute precedence refactor(a365): centralize request context in the base scope Sep 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The shared mapping and overwrite behavior match the stated intent, with focused tests and no unresolved findings.

Review effort: Balanced
Findings: None

@alexlu4250 Jianbiao Lu (alexlu4250) left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good to me. Approving with a non blocking note from AI:

The PR intentionally keeps generic recordAttributes() as last-write-wins, which is the right design for the stated contract, but it means future callers can still overwrite builder and typed-setter values. That should be treated as a deliberate API behavior, not a bug; I’d keep it documented in the contract/tests, which the PR already does.

@nikhilNava
Nikhil Navakiran (nikhilNava) merged commit fd879fd into main Oct 1, 2026
8 checks passed
@nikhilNava
Nikhil Navakiran (nikhilNava) deleted the fix/a365-scope-attribute-precedence branch October 1, 2026 16:14
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