-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add WithHostHeader
config option to override Host header in opentelemetry requests
#4780
base: main
Are you sure you want to change the base?
Conversation
Why can't you use the "WithHeaders" config? |
Opentelemetry client uses net.http.Request to make http requests and this library doesn't override This is a reason why I added a separate configuration for Host to be consistent with the I can alternatively check if |
Thank you for the details. You could use a different Host than the one set when we create the http request with a custom transport which would modify the request accordingly and call the proper parent transport to make the request accordingly. |
5f00ebe
to
16a4d10
Compare
Hi, @dmathieu I didn't understand where you meant calling parent transport protocol, can you please clarify what you meant by that? In the meantime I changed preparation request place to check header name and set it to request where we copy headers. Please check if it is ok |
My apologies. I thought the otlp exporter allowed specifying a custom RoundTripper, which would have been more extensible, as it would have allowed you to modify anything within the request. Between both of your solutions, however, I think an option is better than reusing the |
I agree, let me revert my last commit |
bba2573
to
99f34b3
Compare
WithHostHeader
config option to override Host header in opentelemetry requests
@dmathieu I reverted to the WithHostHeader version |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4780 +/- ##
=====================================
Coverage 83.4% 83.4%
=====================================
Files 238 238
Lines 15745 15779 +34
=====================================
+ Hits 13143 13174 +31
- Misses 2314 2317 +3
Partials 288 288
|
@dmathieu fixed Lint + rebase |
You can run lints on your own machine. You do not need to rely on GH CI to check them for you. |
which command should I use to run locally? I tried but it gives ablotulely different result from what I see in CI, I run |
|
I actually cannot make it work Updating intra-repository dependencies in all go modules
go mod tidy in .
go mod tidy in ./bridge/opencensus
go: downloading github.com/kr/text v0.1.0
go mod tidy in ./bridge/opencensus/test
go mod tidy in ./bridge/opentracing
go mod tidy in ./bridge/opentracing/test
go mod tidy in ./example/dice
go mod tidy in ./example/namedtracer
go mod tidy in ./example/opencensus
go mod tidy in ./example/otel-collector
go mod tidy in ./example/passthrough
go mod tidy in ./example/prometheus
go mod tidy in ./example/zipkin
go mod tidy in ./exporters/otlp/otlpmetric/otlpmetricgrpc
go mod tidy in ./exporters/otlp/otlpmetric/otlpmetrichttp
go mod tidy in ./exporters/otlp/otlptrace
go mod tidy in ./exporters/otlp/otlptrace/otlptracegrpc
go mod tidy in ./exporters/otlp/otlptrace/otlptracehttp
go mod tidy in ./exporters/prometheus
go mod tidy in ./exporters/stdout/stdoutmetric
go mod tidy in ./exporters/stdout/stdouttrace
go mod tidy in ./exporters/zipkin
go mod tidy in ./internal/tools
go: downloading github.com/cloudflare/circl v1.3.7
go mod tidy in ./metric
go mod tidy in ./schema
go mod tidy in ./sdk
go mod tidy in ./sdk/metric
go mod tidy in ./trace
golangci-lint .
golangci-lint ./bridge/opencensus
golangci-lint ./bridge/opencensus/test
golangci-lint ./bridge/opentracing
golangci-lint ./bridge/opentracing/test
ERRO [linters_context] typechecking error: pattern ./...: directory prefix . does not contain modules listed in go.work or their selected dependencies
make: *** [golangci-lint/./bridge/opentracing/test] Error 7``` |
I have a bunch of things which probably work not in the way they are supposed to
I don't where the problem is, maybe versions of something do not match.. |
Ok, found that I used go 1.21, and on 1.20 it is fine |
c622bb7
to
e18a523
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think we should add another option when we already have WithHeaders
. This will only add confusion (how are conflicts resolved; which is the recommended option to use?).
Why not parse the headers passed to WithHeaders
and set the Host
field if it is passed there?
I actually agree with you now, it will be consistent with how i did open-telemetry/opentelemetry-collector#9411 |
I suggested not using |
I think we should add I don't think there is any confusion if you already use the I made a gist to demonstrate the behavior: https://gist.github.com/MadVikingGod/16a92daebf61c67a7ff7d846b11d93c4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it only affects HTTP. I'm ok with where it is.
If we were to use this kind of option for GRPC, a space which I'm less familiar with, would this be exposed in a similar way, or would we take a different approach?
// config.WithEndpoint("myenvoyhost") | ||
// | ||
// .WithHostHeader("mytargetotelcollectorhost") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look correctly formatted to be rendered as code nor does it look valid. WithHostHeader
is an argument passed to a config new function, this makes it look like a method being called.
// WithHostHeader allows one to tell the driver to override HTTP host header. | ||
// If value is unset Endpoint's host is used as Host header. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment differs from the metric one. They should be unified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, It looks good, but the comments @MrAlias mentioned should be resolved.
@enuret, bump. |
Adding configuration option to override
Host
header. This header is not overriding by providing it as part of overrided Headers and a separate field "Host
" in Request is used.https://pkg.go.dev/net/http#Request
Host header is used by some load balancers, for example, envoy uses it for routing requests.
The similar change is planned to be made in otelcollector
Use case:
My go client sends otel data via envoy
go client -> envoy -> otel collector
Since envoy performs routing is based on "
Host
" header , it has to be added into request.