Skip to content

feat: adds business unit & user names & ids to tracing - #4562

Merged
akshaydeo merged 1 commit into
devfrom
06-19-feat_adds_business_unit_user_names_ids_to_tracing
Jun 19, 2026
Merged

feat: adds business unit & user names & ids to tracing#4562
akshaydeo merged 1 commit into
devfrom
06-19-feat_adds_business_unit_user_names_ids_to_tracing

Conversation

@roroghost17

@roroghost17 roroghost17 commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds tracing support for business_unit and user context attributes, enabling these governance-related identifiers to be captured in spans alongside the existing team and customer attributes.

Changes

  • Added AttrBifrostBusinessUnitID, AttrBifrostBusinessUnitName, AttrBifrostUserID, and AttrBifrostUserName trace attribute constants to core/schemas/trace.go
  • Updated PopulateContextAttributes in framework/tracing/llmspan.go to accept and emit businessUnitID, businessUnitName, userID, and userName parameters when non-empty
  • Updated executeRequestWithRetries in core/bifrost.go to read BifrostContextKeyGovernanceBusinessUnitID, BifrostContextKeyGovernanceBusinessUnitName, BifrostContextKeyUserID, and BifrostContextKeyUserName from context and set them as span attributes

Type of change

  • Bug fix
  • Feature
  • Refactor
  • Documentation
  • Chore/CI

Affected areas

  • Core (Go)
  • Transports (HTTP)
  • Providers/Integrations
  • Plugins
  • UI (React)
  • Docs

How to test

Populate the relevant context keys (BifrostContextKeyGovernanceBusinessUnitID, BifrostContextKeyGovernanceBusinessUnitName, BifrostContextKeyUserID, BifrostContextKeyUserName) on a request context and verify the corresponding bifrost.business_unit.id, bifrost.business_unit.name, bifrost.user.id, and bifrost.user.name attributes appear on the resulting trace span.

go test ./...

Breaking changes

  • Yes
  • No

Security considerations

userID and userName values sourced from request context will be written to trace spans. Ensure that any user-identifying data emitted here complies with your data retention and PII policies for your tracing backend.

Checklist

  • I read docs/contributing/README.md and followed the guidelines
  • I added/updated tests where appropriate
  • I updated documentation where needed
  • I verified builds succeed (Go and UI)
  • I verified the CI pipeline passes locally if applicable

@CLAassistant

CLAassistant commented Jun 19, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 30fc7cd6-173a-45ee-9ff1-a22c5d9cb71a

📥 Commits

Reviewing files that changed from the base of the PR and between 70ed897 and 6060b08.

📒 Files selected for processing (3)
  • core/bifrost.go
  • core/schemas/trace.go
  • framework/tracing/llmspan.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • framework/tracing/llmspan.go
  • core/bifrost.go
  • core/schemas/trace.go

📝 Walkthrough

Summary by CodeRabbit

  • Observability
    • Enhanced distributed tracing by adding business unit and user identity attributes to LLM-related span context (emitted when values are present).
    • Enriched per-attempt retry spans with business unit and user identity metadata for clearer end-to-end request tracking.
    • Added trace attribute constants for business unit and user ID/name to support consistent instrumentation.

Walkthrough

Four new bifrost.business_unit.* and bifrost.user.* span attribute constants are added to core/schemas/trace.go. PopulateContextAttributes in framework/tracing/llmspan.go is extended with corresponding parameters and conditionally emits those attributes. executeRequestWithRetries in core/bifrost.go reads these values from BifrostContext and passes them to the updated function.

Changes

Business unit and user identity tracing

Layer / File(s) Summary
Trace attribute constants and PopulateContextAttributes signature
core/schemas/trace.go, framework/tracing/llmspan.go
Four new exported constants (AttrBifrostBusinessUnitID, AttrBifrostBusinessUnitName, AttrBifrostUserID, AttrBifrostUserName) are defined under bifrost.business_unit.* and bifrost.user.*. PopulateContextAttributes signature gains businessUnitID, businessUnitName, userID, userName parameters.
PopulateContextAttributes implementation and retry span emission
framework/tracing/llmspan.go, core/bifrost.go
PopulateContextAttributes conditionally emits the four new Bifrost-scoped attributes when the corresponding IDs are non-empty. executeRequestWithRetries reads businessUnitID/businessUnitName and userID/userName from BifrostContext and passes them to the updated function for per-attempt retry span instrumentation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • maximhq/bifrost#3730: Also modifies executeRequestWithRetries to enrich per-attempt OTEL span attributes in core/bifrost.go, adding extra header attributes with optional redaction.
  • maximhq/bifrost#3732: Refactors the same executeRequestWithRetries/PopulateContextAttributes code paths and bifrost.* constant definitions that this PR extends with business unit and user identity attributes.

Suggested reviewers

  • akshaydeo
  • danpiths

Poem

🐇 Hoppy little tracer, tagging spans with care,
Business units and users now floating through the air!
Each retry attempt gets a name and an ID,
No request goes unnoticed — observability is key.
The rabbit stamps the metadata, neat and tidy-true,
bifrost.user.name hopping into your Jaeger view! 🎯

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding business unit and user names/IDs to tracing. It is concise, clear, and directly reflects the primary objective of the changeset.
Description check ✅ Passed The description covers all critical sections: it explains the purpose (adding tracing support for governance attributes), details the changes across three files, specifies the feature type, identifies affected areas (Core Go), provides testing instructions, addresses security considerations regarding PII, and confirms no breaking changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 06-19-feat_adds_business_unit_user_names_ids_to_tracing

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@roroghost17
roroghost17 marked this pull request as ready for review June 19, 2026 14:54
@coderabbitai
coderabbitai Bot requested review from akshaydeo and danpiths June 19, 2026 14:55
@greptile-apps

greptile-apps Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The change is additive and isolated to the tracing layer; no existing behavior in the critical request path is altered.

All four new attributes are guarded by independent non-empty checks in both code paths, matching the surrounding team/customer pattern. The refactoring of teamName/customerName guards in PopulateContextAttributes aligns the function with bifrost.go's long-standing independent-guard style. There are no internal callers of PopulateContextAttributes so there is no in-repo regression risk, and the bifrost.go path makes no control-flow changes.

No files require special attention.

Important Files Changed

Filename Overview
core/schemas/trace.go Adds four new bifrost.* trace attribute constants; no legacy namespace mirrors, consistent with the intent to move away from gen_ai.* for new attributes.
core/bifrost.go Adds four independent context-lookup + SetAttribute blocks inside executeRequestWithRetries; guards and style are consistent with the surrounding team/customer blocks.
framework/tracing/llmspan.go Extends the exported PopulateContextAttributes with four new required parameters and decouples teamName/customerName emission from their corresponding ID guards; no callers exist within the repo.

Reviews (2): Last reviewed commit: "feat: adds business unit & user names & ..." | Re-trigger Greptile

Comment thread framework/tracing/llmspan.go

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
framework/tracing/llmspan.go (1)

153-163: ⚡ Quick win

Add table-driven coverage for the new context-attribute permutations.

This change expands behavior via new parameters plus conditional emission; please add focused tests for (id,name) present vs missing cases so regressions are caught quickly.

As per coding guidelines, “Apply standard Go review practices… deterministic tests, and table-driven coverage for behavior changes.”

Also applies to: 198-205

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@framework/tracing/llmspan.go` around lines 153 - 163, The
PopulateContextAttributes function now accepts multiple new (id, name) parameter
pairs but lacks table-driven test coverage for these new permutations. Create a
comprehensive table-driven test that systematically covers scenarios where each
parameter pair (virtualKeyID/virtualKeyName, selectedKeyID/selectedKeyName,
routingRuleID/routingRuleName, teamID/teamName, customerID/customerName,
businessUnitID/businessUnitName, userID/userName) is present, absent, or
partially populated. Ensure the test validates that attributes are correctly
conditionally emitted based on which parameters are provided to catch
regressions in the conditional attribute population logic.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@framework/tracing/llmspan.go`:
- Around line 153-163: The PopulateContextAttributes function now accepts
multiple new (id, name) parameter pairs but lacks table-driven test coverage for
these new permutations. Create a comprehensive table-driven test that
systematically covers scenarios where each parameter pair
(virtualKeyID/virtualKeyName, selectedKeyID/selectedKeyName,
routingRuleID/routingRuleName, teamID/teamName, customerID/customerName,
businessUnitID/businessUnitName, userID/userName) is present, absent, or
partially populated. Ensure the test validates that attributes are correctly
conditionally emitted based on which parameters are provided to catch
regressions in the conditional attribute population logic.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: e0436d4d-9fe3-47d5-97e3-f1bdf2be4194

📥 Commits

Reviewing files that changed from the base of the PR and between cf58ea4 and 70ed897.

📒 Files selected for processing (3)
  • core/bifrost.go
  • core/schemas/trace.go
  • framework/tracing/llmspan.go

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 19, 2026
@roroghost17
roroghost17 force-pushed the 06-19-feat_adds_business_unit_user_names_ids_to_tracing branch from 70ed897 to 6060b08 Compare June 19, 2026 15:07

akshaydeo commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Merge activity

  • Jun 19, 3:13 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jun 19, 3:13 PM UTC: @akshaydeo merged this pull request with Graphite.

@akshaydeo
akshaydeo merged commit 5e7460b into dev Jun 19, 2026
15 of 16 checks passed
@akshaydeo
akshaydeo deleted the 06-19-feat_adds_business_unit_user_names_ids_to_tracing branch June 19, 2026 15:13
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.

3 participants