-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[extension/headers_setter] Add headers_setter extension. #12892
[extension/headers_setter] Add headers_setter extension. #12892
Conversation
e019470
to
2b4c73f
Compare
@kovrus, please open an issue proposing this new component (see the contributing guidelines). I'm willing to sponsor this one. |
2b4c73f
to
ad435a5
Compare
e5bd4cd
to
048306d
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.
Looks almost perfect, thanks!
extension/headerssetter/config.go
Outdated
if headerCfg.Key == nil || *headerCfg.Key == "" { | ||
return errMissingHeader | ||
} | ||
if headerCfg.FromContext == nil && headerCfg.Value == nil { |
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.
If FromContext is empty, what would happen?
}, | ||
}, | ||
expectedHeaders: map[string]string{ | ||
"header_name": "", |
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 guess this answers the question I had earlier about empty FromContext values.
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.
The semantic is following:
from_context: "key" -> if key is missing from context then header value set to ""
from_context: "key" -> if key from context is "" then header value set to ""
value: "" -> header value set to ""
I was thinking of not setting headers at all if their value is "" but then decided to make it arguably more explicit. Also, "" is a valid header value.
2f4e8b8
to
a5ade8e
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.
LGTM, just double-check the go version we are using in other modules, which might have been changed since this PR was opened.
The `headers_setter` extension implements `ClientAuthenticator` and is used to set request headers in gRPC / HTTP exporters with values provided via the extension configuration or request metatdata (context).
a5ade8e
to
123666f
Compare
Description:
Resolves #12922
The
headers_setter
extension implementsClientAuthenticator
and is used to set request headers in gRPC / HTTP exporters with values provided
via the extension configuration or request metadata (context).
Use cases include but are not limited to enabling multi-tenancy for observability
backends such as
Tempo
,Mimir
,Loki
and others by setting theX-Scope-OrgID
header to the value extracted from the context.
Link to tracking Issue:
This change potentially can address the following issues related to multi-tenancy use cases:
OTEL Exporter - multi-tenancy support based on labels opentelemetry-collector#5733
[prometheusremotewriteexporter] multi-tenancy support based on labels #7945
Auth-context available for use in export-config opentelemetry-collector#4814
Access headers in OTLP exporter opentelemetry-collector#5264
We can drop specific multi-tenant implementation in
Loki
exporter/loki
: handle multi-tenant use-cases #12415Open discussion:
auth
andauthenticator
config to be enabled which might be confusing. One option could be renamingauth
->interception
andauthenticator
->interceptor
cc: @jpkrohlingAlternatives:
It is also possible to implement the same functionality (setting header values from context) in opentelemetry-collector by implementing a round tripper and interceptor that will set in confighttp.go and configgrpc.go and changing the headers configuration of HTTP / gRPC client settings. This approach seems to be more complex and might impact some exporters in pentelemetry-collector-contrib
Testing:
Documentation:
See
README.md
in the newheaders_setter
extension.