-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
feat: informative user-agent for otlp exporters #3970
Changes from 10 commits
3d72c7b
fa5942c
13ad211
8fd2bd7
c945d07
efd1fc1
672b7f6
0a86588
33bc09f
386a70b
ab6adb1
0b44ddf
511b636
f5bddaf
b201e25
e232439
0ac32d6
a8bd4ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ type exporter struct { | |
metricsURL string | ||
logsURL string | ||
logger *zap.Logger | ||
buildInfo component.BuildInfo | ||
} | ||
|
||
const ( | ||
|
@@ -57,7 +58,7 @@ const ( | |
) | ||
|
||
// Crete new exporter. | ||
func newExporter(cfg config.Exporter, logger *zap.Logger) (*exporter, error) { | ||
func newExporter(cfg config.Exporter, logger *zap.Logger, buildInfo component.BuildInfo) (*exporter, error) { | ||
oCfg := cfg.(*Config) | ||
|
||
if oCfg.Endpoint != "" { | ||
|
@@ -69,8 +70,9 @@ func newExporter(cfg config.Exporter, logger *zap.Logger) (*exporter, error) { | |
|
||
// client construction is deferred to start | ||
return &exporter{ | ||
config: oCfg, | ||
logger: logger, | ||
config: oCfg, | ||
logger: logger, | ||
buildInfo: buildInfo, | ||
}, nil | ||
} | ||
|
||
|
@@ -82,6 +84,8 @@ func (e *exporter) start(_ context.Context, host component.Host) error { | |
return err | ||
} | ||
|
||
client.Transport = NewUserAgentRoundTripper(client.Transport, exporterhelper.DefaultUserAgent(e.buildInfo)) | ||
jpkrohling marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can configure "CustomRoundTripper" which is not a user config. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noted, that sounds like exactly what I want here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
if e.config.Compression != "" { | ||
if strings.ToLower(e.config.Compression) == configgrpc.CompressionGzip { | ||
client.Transport = middleware.NewCompressRoundTripper(client.Transport) | ||
|
@@ -213,3 +217,20 @@ func readResponse(resp *http.Response) *status.Status { | |
|
||
return respStatus | ||
} | ||
|
||
type UserAgentRoundTripper struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why public? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This type will be removed in favor of CustomRoundTripper There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Turns out I did need this as a receiver still -- but it is private now |
||
next http.RoundTripper | ||
userAgent string | ||
} | ||
|
||
func NewUserAgentRoundTripper(next http.RoundTripper, userAgent string) *UserAgentRoundTripper { | ||
return &UserAgentRoundTripper{ | ||
next, | ||
userAgent, | ||
} | ||
} | ||
|
||
func (r *UserAgentRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { | ||
req.Header.Set("User-Agent", r.userAgent) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You cannot do this, https://pkg.go.dev/net/http#RoundTripper There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you referring to the request modification? This is exactly what the HTTP client is doing currently: https://github.com/open-telemetry/opentelemetry-collector/blob/main/config/confighttp/confighttp.go#L124 (not to say that it makes it valid) The compression roundtripper (same method, below) makes a copy of the request, then modifies the body and headers. Would that be acceptable here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
return r.next.RoundTrip(req) | ||
} |
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.
let's move this to otlpexporter for the moment or an internal package. Prefer to limit the public API.
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.
✅ Moved to each exporter f5bddaf