Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gin exporter: support reading Client IP from custom headers (and make sure proxy is trusted) #6095

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

ItalyPaleAle
Copy link

@ItalyPaleAle ItalyPaleAle commented Sep 8, 2024

With Gin, it's possible to configure the server to read the Client IP from custom headers; examples include X-Real-Ip or CF-Connecting-IP. This PR makes it possible to set as span attribute the same IP that Gin reads.

Additionally, it makes sure that headers such as "X-Forwarded-For" are used only if Gin is configured to trust the upstream server

… sure proxy is trusted)

With Gin, it's possible to configure the server to read the Client IP from custom headers; examples include `X-Real-Ip` or `CF-Connecting-IP`. This PR makes it possible to set as span attribute the same IP that Gin reads.

Additionally, it makes sure that headers such as "X-Forwarded-For" are used only if Gin is configured to trust the upstream server

PS: Also fixed unit tests, where there were assertions inside handlers, which are executed in separate goroutines
Copy link

linux-foundation-easycla bot commented Sep 8, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@dmathieu
Copy link
Member

dmathieu commented Sep 9, 2024

PS: Also fixed unit tests, where there were assertions inside handlers, which are executed in separate goroutines

Could you split that into another PR, to make things easier to review?

@ItalyPaleAle
Copy link
Author

PS: Also fixed unit tests, where there were assertions inside handlers, which are executed in separate goroutines

Could you split that into another PR, to make things easier to review?

Done

Copy link

codecov bot commented Sep 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 65.8%. Comparing base (a6c3927) to head (9149000).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #6095     +/-   ##
=======================================
+ Coverage   65.7%   65.8%   +0.1%     
=======================================
  Files        204     204             
  Lines      13088   13121     +33     
=======================================
+ Hits        8608    8643     +35     
+ Misses      4216    4215      -1     
+ Partials     264     263      -1     
Files with missing lines Coverage Δ
...stful/otelrestful/internal/semconvutil/httpconv.go 96.1% <100.0%> (+<0.1%) ⬆️
...hub.com/emicklei/go-restful/otelrestful/restful.go 100.0% <100.0%> (ø)
...ation/github.com/gin-gonic/gin/otelgin/gintrace.go 82.6% <100.0%> (+0.4%) ⬆️
...gonic/gin/otelgin/internal/semconvutil/httpconv.go 96.1% <100.0%> (+<0.1%) ⬆️
...rilla/mux/otelmux/internal/semconvutil/httpconv.go 96.1% <100.0%> (+<0.1%) ⬆️
...trumentation/github.com/gorilla/mux/otelmux/mux.go 89.4% <100.0%> (ø)
...entation/github.com/labstack/echo/otelecho/echo.go 100.0% <100.0%> (ø)
...ack/echo/otelecho/internal/semconvutil/httpconv.go 96.1% <100.0%> (+<0.1%) ⬆️
...on.v1/otelmacaron/internal/semconvutil/httpconv.go 96.1% <100.0%> (+<0.1%) ⬆️
...ntation/gopkg.in/macaron.v1/otelmacaron/macaron.go 92.3% <100.0%> (ø)
... and 4 more

... and 1 file with indirect coverage changes

Copy link
Member

@dmathieu dmathieu left a comment

Choose a reason for hiding this comment

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

This will need a changelog entry.

CHANGELOG.md Outdated Show resolved Hide resolved
@ItalyPaleAle ItalyPaleAle requested a review from a team as a code owner September 20, 2024 14:51
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.

2 participants