Skip to content

feat(observability): add instance info to trace root span#80

Merged
bzp2010 merged 1 commit into
mainfrom
bzp/feat-o11y-trace-instance-info
May 3, 2026
Merged

feat(observability): add instance info to trace root span#80
bzp2010 merged 1 commit into
mainfrom
bzp/feat-o11y-trace-instance-info

Conversation

@bzp2010
Copy link
Copy Markdown
Collaborator

@bzp2010 bzp2010 commented May 3, 2026

Summary by CodeRabbit

  • Refactor

    • Streamlined initialization sequence and observability configuration setup
    • Instance tracking identifiers now included in distributed traces for enhanced observability and debugging
  • Bug Fixes

    • Enhanced error messages for initialization failures with additional context information

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 3, 2026

📝 Walkthrough

Walkthrough

The PR relocates instance initialization from the library's startup routine to the main program entry point and enhances observability by centralizing resource creation and adding instance identifiers to distributed traces.

Changes

Instance Initialization and Observability Refactor

Layer / File(s) Summary
Observability Resource Centralization
src/utils/observability/mod.rs
A new private get_resource() helper centralizes OpenTelemetry Resource construction with service name. Both trace and metric initialization now call this helper instead of inline construction.
Startup Flow Relocation
src/lib.rs, src/main.rs
instance::init() is removed from lib.rs::run() and moved to main.rs with added error context via anyhow::Context. The import in lib.rs is updated to import only init_observability.
Trace Instrumentation
src/proxy/middlewares/trace.rs
Root span initialization now includes instance-identifying properties (aisix.instance_id and aisix.instance_run_id) fetched from the instance module, supported by a new local attributes module defining span property key constants.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
E2e Test Quality Review ⚠️ Warning PR lacks E2E test coverage for observability feature and introduces safety regression: trace middleware calls functions that panic if instance::init() isn't called, but initialization was moved to binary entrypoint only, breaking library embedders. Add E2E tests for trace spans with instance IDs and ensure library safety by calling instance::init() from library entrypoint or making instance_id()/run_id() return Option with fallbacks.
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately describes the main change: adding instance info to trace root span properties.
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.
Security Check ✅ Passed Pull request adds non-sensitive telemetry identifiers (instance_id, run_id) to OpenTelemetry trace spans and refactors observability code without exposing credentials, secrets, or sensitive data.

✏️ 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 bzp/feat-o11y-trace-instance-info

Review rate limit: 4/5 reviews remaining, refill in 12 minutes.

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/main.rs`:
- Line 9: The library must guarantee instance::init() is called for non-CLI
embedders; update the library entry points (run(), run_with_config(),
run_with_provider() in src/lib.rs) to call aisix::utils::instance::init() (or a
fallible variant) during startup before any request handling, or alternatively
make instance_id()/run_id() return Option/Result instead of panicking when the
OnceLock is uninitialized; ensure the chosen fix references and initializes the
OnceLock used by instance::init() (or changes the getters) so trace middleware
(src/proxy/middlewares/trace.rs) no longer panics for embedder usage.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2ba06659-12b2-4c28-9b6e-a3b83bbef080

📥 Commits

Reviewing files that changed from the base of the PR and between 77bd85e and db4c9d3.

📒 Files selected for processing (4)
  • src/lib.rs
  • src/main.rs
  • src/proxy/middlewares/trace.rs
  • src/utils/observability/mod.rs

Comment thread src/main.rs
@bzp2010 bzp2010 merged commit 4311ae9 into main May 3, 2026
3 checks passed
@bzp2010 bzp2010 deleted the bzp/feat-o11y-trace-instance-info branch May 3, 2026 12:45
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.

1 participant