-
Notifications
You must be signed in to change notification settings - Fork 881
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 builders for setting optional attributes on HTTP extractors #5347
Merged
mateuszrzeszutek
merged 3 commits into
open-telemetry:main
from
mateuszrzeszutek:http-attribute-extractor-builders
Mar 8, 2022
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...telemetry/instrumentation/api/instrumenter/http/HttpClientAttributesExtractorBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.api.instrumenter.http; | ||
|
||
import io.opentelemetry.instrumentation.api.config.Config; | ||
|
||
/** A builder of {@link HttpClientAttributesExtractor}. */ | ||
public final class HttpClientAttributesExtractorBuilder<REQUEST, RESPONSE> { | ||
|
||
final HttpClientAttributesGetter<REQUEST, RESPONSE> getter; | ||
CapturedHttpHeaders capturedHttpHeaders = CapturedHttpHeaders.client(Config.get()); | ||
|
||
HttpClientAttributesExtractorBuilder(HttpClientAttributesGetter<REQUEST, RESPONSE> getter) { | ||
this.getter = getter; | ||
} | ||
|
||
/** | ||
* Configures the HTTP headers that will be captured as span attributes. | ||
* | ||
* @param capturedHttpHeaders A configuration object specifying which HTTP request and response | ||
* headers should be captured as span attributes. | ||
*/ | ||
public HttpClientAttributesExtractorBuilder<REQUEST, RESPONSE> captureHttpHeaders( | ||
CapturedHttpHeaders capturedHttpHeaders) { | ||
this.capturedHttpHeaders = capturedHttpHeaders; | ||
return this; | ||
} | ||
|
||
/** | ||
* Returns a new {@link HttpClientAttributesExtractor} with the settings of this {@link | ||
* HttpClientAttributesExtractorBuilder}. | ||
*/ | ||
public HttpClientAttributesExtractor<REQUEST, RESPONSE> build() { | ||
return new HttpClientAttributesExtractor<>(getter, capturedHttpHeaders); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...telemetry/instrumentation/api/instrumenter/http/HttpServerAttributesExtractorBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.api.instrumenter.http; | ||
|
||
import io.opentelemetry.instrumentation.api.config.Config; | ||
|
||
/** A builder of {@link HttpServerAttributesExtractor}. */ | ||
public final class HttpServerAttributesExtractorBuilder<REQUEST, RESPONSE> { | ||
|
||
final HttpServerAttributesGetter<REQUEST, RESPONSE> getter; | ||
CapturedHttpHeaders capturedHttpHeaders = CapturedHttpHeaders.server(Config.get()); | ||
|
||
HttpServerAttributesExtractorBuilder(HttpServerAttributesGetter<REQUEST, RESPONSE> getter) { | ||
this.getter = getter; | ||
} | ||
|
||
/** | ||
* Configures the HTTP headers that will be captured as span attributes. | ||
* | ||
* @param capturedHttpHeaders A configuration object specifying which HTTP request and response | ||
* headers should be captured as span attributes. | ||
*/ | ||
public HttpServerAttributesExtractorBuilder<REQUEST, RESPONSE> captureHttpHeaders( | ||
CapturedHttpHeaders capturedHttpHeaders) { | ||
this.capturedHttpHeaders = capturedHttpHeaders; | ||
return this; | ||
} | ||
|
||
/** | ||
* Returns a new {@link HttpServerAttributesExtractor} with the settings of this {@link | ||
* HttpServerAttributesExtractorBuilder}. | ||
*/ | ||
public HttpServerAttributesExtractor<REQUEST, RESPONSE> build() { | ||
return new HttpServerAttributesExtractor<>(getter, capturedHttpHeaders); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
what do you think of hiding
CapturedHttpHeaders
and exposingcaptureHttpRequestHeaders
andcaptureHttpResponseHeaders
on the builders?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 think I'd probably prefer leaving this as it is, it's a bit simpler this way.
If I added
captureHttpRequestHeaders(List<String>)
I'd have to take the following things into account:. captureHttpRequestHeaders(["abc"]).captureHttpRequestHeaders(["def"])
capture["abc", "def"]
or does the second call overwrite the first one?With
captureHttpHeaders(CapturedHttpHeaders)
it's clear (I hope so? 😅 ) that the previous setting is overwritten. (Maybe I should rename it tosetCapturedHttpHeaders
after all...)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.
cc @anuraaga for any API thoughts
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.
How about
setCapturedRequestHeaders
setCapturedResponseHeaders
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'll do that in a separate PR - this requires changing all our HTTP library instrumentations, so the amount of changes will be pretty significant.