Skip to content

fix: otel attr for http client address - #4535

Merged
chrisgacsal merged 1 commit into
mainfrom
fix/otel-client-ip
Jun 17, 2026
Merged

chrisgacsal merged 1 commit into
mainfrom
fix/otel-client-ip

Conversation

@chrisgacsal

@chrisgacsal chrisgacsal commented Jun 17, 2026 •

Copy link
Copy Markdown
Collaborator

Overview

Fix OTel attribute used for attaching Client IP to spans.

Fixes #(issue)

Notes for reviewer

Summary by CodeRabbit

  • Chores
    • Enhanced network telemetry data collection by improving request attribute handling and OpenTelemetry peer address population.

@chrisgacsal
chrisgacsal requested review from tothandras and turip June 17, 2026 16:07
@chrisgacsal chrisgacsal self-assigned this Jun 17, 2026
@chrisgacsal
chrisgacsal requested a review from a team as a code owner June 17, 2026 16:07
@coderabbitai

coderabbitai Bot commented Jun 17, 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

Run ID: 94808f87-0dfa-41c8-9c6c-571bb0a0011d

📥 Commits

Reviewing files that changed from the base of the PR and between 5b4ce3d and 10ee16c.

📒 Files selected for processing (1)
  • pkg/server/attributes.go

📝 Walkthrough

Walkthrough

GetRequestAttributes in pkg/server/attributes.go is updated so that r.RemoteAddr is always parsed to set the OpenTelemetry network peer address and peer port, and when middleware.GetClientIPAddr(ctx) is valid, it now populates ClientAddressKey instead of the peer address key.

Changes

Network Attribute Population Fix

Layer / File(s) Summary
Peer vs. client address attribute split
pkg/server/attributes.go
Replaces the old GetClientIPAddr-or-SplitHostPort fallback with two independent steps: unconditional r.RemoteAddr parsing for peer address/port, and ClientAddressKey assignment (instead of the peer address key) when GetClientIPAddr is valid.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ 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 'fix: otel attr for http client address' directly addresses the main change: fixing OpenTelemetry attribute configuration for HTTP client addresses, matching the PR's core objective.
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 fix/otel-client-ip

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@greptile-apps

greptile-apps Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR corrects the OTel semantic convention attributes used when recording HTTP request client address information on spans. The previous code stored the client IP (from X-Forwarded-For or similar headers) under network.peer.address, which is semantically wrong — that key should hold the direct TCP peer's address, not the logical client.

  • network.peer.address and network.peer.port are now always populated from r.RemoteAddr (the actual TCP connection peer), which is the correct usage per the OTel HTTP span spec.
  • The logical client address (resolved via middleware.GetClientIPAddr) is now stored under client.address, matching the OTel spec example where client.address represents the originating client and network.peer.address represents an intermediate proxy.

Confidence Score: 5/5

Safe to merge — the change is a targeted, one-file correction to OTel attribute naming with no logic, auth, or data-path impact.

The fix correctly separates the logical client IP (client.address via GetClientIPAddr) from the direct TCP peer (network.peer.address / network.peer.port via r.RemoteAddr), aligning exactly with the OTel HTTP span specification example. The old if/else that overwrote network.peer.address with the proxied client IP is gone; both attributes are now independently populated, which is additive and non-breaking.

No files require special attention — the change is confined to a single helper function that only affects span attributes.

Important Files Changed

Filename Overview
pkg/server/attributes.go Correct OTel attribute fix: client.address now used for the logical client IP, network.peer.address for the direct TCP peer; both attributes are now populated independently rather than via an if/else.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Client as Originating Client
    participant Proxy as Reverse Proxy / LB
    participant Server as HTTP Server

    Client->>Proxy: "TCP connection (client.address = Client IP)"
    Proxy->>Server: "TCP connection (network.peer.address = Proxy IP)"
    Note over Proxy,Server: X-Forwarded-For: Client IP

    Server->>Server: r.RemoteAddr → network.peer.address + network.peer.port
    Server->>Server: GetClientIPAddr() → client.address (from X-Forwarded-For)
    Server->>Server: Attach both attrs to OTel span
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant Client as Originating Client
    participant Proxy as Reverse Proxy / LB
    participant Server as HTTP Server

    Client->>Proxy: "TCP connection (client.address = Client IP)"
    Proxy->>Server: "TCP connection (network.peer.address = Proxy IP)"
    Note over Proxy,Server: X-Forwarded-For: Client IP

    Server->>Server: r.RemoteAddr → network.peer.address + network.peer.port
    Server->>Server: GetClientIPAddr() → client.address (from X-Forwarded-For)
    Server->>Server: Attach both attrs to OTel span
Loading

Reviews (1): Last reviewed commit: "fix: otel attr for http client address" | Re-trigger Greptile

@chrisgacsal chrisgacsal added the release-note/bug-fix Release note: Bug Fixes label Jun 17, 2026
@chrisgacsal
chrisgacsal enabled auto-merge (squash) June 17, 2026 16:10
@chrisgacsal
chrisgacsal merged commit 2ab8cd0 into main Jun 17, 2026
25 of 27 checks passed
@chrisgacsal
chrisgacsal deleted the fix/otel-client-ip branch June 17, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/bug-fix Release note: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants