-
Notifications
You must be signed in to change notification settings - Fork 958
Redact query string values for http client spans #13114
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
Merged
trask
merged 22 commits into
open-telemetry:main
from
jeanbisutti:redact-query-string-values
Feb 27, 2025
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
c8a5c14
Redact query string values
jeanbisutti 641260e
Update instrumentation-api/src/main/java/io/opentelemetry/instrumenta…
jeanbisutti e65eb6a
Add comments
jeanbisutti 417df19
Update instrumentation-api/src/main/java/io/opentelemetry/instrumenta…
jeanbisutti 65f0a33
Move configuration from the stable API
jeanbisutti 951b0f4
Only use HttpClientAttributesExtractor and rename configuration
jeanbisutti febf108
Fix JSON metadata
jeanbisutti 53a7a0b
Fix Spring metadata
jeanbisutti be63270
Enable query redaction by default and clean up
jeanbisutti da85a5e
Instance variable set to true to avoid confusion
jeanbisutti fa98de3
Re-apply feedback
jeanbisutti 4fc1c2d
make experimental option setting for redacted query params similar to…
laurit dd05fbb
Re-apply feedback
jeanbisutti a5760ba
Simplify
trask f37ab6d
Update instrumentation-api/src/main/java/io/opentelemetry/instrumenta…
jeanbisutti 9ef64ab
test method naming
jeanbisutti 4911e83
merge
jeanbisutti 5164fe5
Add scenarios with parameters without values
jeanbisutti ef736e1
Alternative version
jeanbisutti bbed3b3
fix typo
jeanbisutti 1f20468
Update instrumentation-api/src/main/java/io/opentelemetry/instrumenta…
trask 0195b2a
spotless
jeanbisutti 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 hidden or 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 hidden or 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
36 changes: 36 additions & 0 deletions
36
...ntation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/Experimental.java
This file contains hidden or 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,36 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.api.internal; | ||
|
||
import io.opentelemetry.instrumentation.api.semconv.http.HttpClientAttributesExtractorBuilder; | ||
import java.util.function.BiConsumer; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* This class is internal and is hence not for public use. Its APIs are unstable and can change at | ||
* any time. | ||
*/ | ||
public final class Experimental { | ||
|
||
@Nullable | ||
private static volatile BiConsumer<HttpClientAttributesExtractorBuilder<?, ?>, Boolean> | ||
redactHttpClientQueryParameters; | ||
|
||
private Experimental() {} | ||
|
||
public static void setRedactQueryParameters( | ||
HttpClientAttributesExtractorBuilder<?, ?> builder, boolean redactQueryParameters) { | ||
if (redactHttpClientQueryParameters != null) { | ||
redactHttpClientQueryParameters.accept(builder, redactQueryParameters); | ||
} | ||
} | ||
|
||
public static void internalSetRedactHttpClientQueryParameters( | ||
BiConsumer<HttpClientAttributesExtractorBuilder<?, ?>, Boolean> | ||
redactHttpClientQueryParameters) { | ||
Experimental.redactHttpClientQueryParameters = redactHttpClientQueryParameters; | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -23,22 +23,28 @@ | |
import static java.util.Collections.emptyMap; | ||
import static java.util.Collections.singletonList; | ||
import static org.assertj.core.api.Assertions.entry; | ||
import static org.junit.jupiter.params.provider.Arguments.arguments; | ||
|
||
import io.opentelemetry.api.common.AttributeKey; | ||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.api.common.AttributesBuilder; | ||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; | ||
import io.opentelemetry.instrumentation.api.internal.Experimental; | ||
import io.opentelemetry.instrumentation.api.internal.HttpConstants; | ||
import java.net.ConnectException; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.ToIntFunction; | ||
import java.util.stream.Stream; | ||
import javax.annotation.Nullable; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.ArgumentsProvider; | ||
import org.junit.jupiter.params.provider.ArgumentsSource; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
|
@@ -200,6 +206,93 @@ void normal() { | |
entry(NETWORK_PEER_PORT, 456L)); | ||
} | ||
|
||
@ParameterizedTest | ||
@ArgumentsSource(UrlSourceToRedact.class) | ||
void shouldRedactUserInfoAndQueryParameters(String url, String expectedResult) { | ||
Map<String, String> request = new HashMap<>(); | ||
request.put("urlFull", url); | ||
|
||
HttpClientAttributesExtractorBuilder<Map<String, String>, Map<String, String>> builder = | ||
HttpClientAttributesExtractor.builder(new TestHttpClientAttributesGetter()); | ||
Experimental.setRedactQueryParameters(builder, true); | ||
AttributesExtractor<Map<String, String>, Map<String, String>> extractor = builder.build(); | ||
|
||
AttributesBuilder attributes = Attributes.builder(); | ||
extractor.onStart(attributes, Context.root(), request); | ||
|
||
assertThat(attributes.build()).containsOnly(entry(URL_FULL, expectedResult)); | ||
} | ||
|
||
static final class UrlSourceToRedact implements ArgumentsProvider { | ||
|
||
@Override | ||
public Stream<? extends Arguments> provideArguments(ExtensionContext context) { | ||
return Stream.of( | ||
arguments("https://user1:[email protected]", "https://REDACTED:[email protected]"), | ||
arguments( | ||
"https://user1:[email protected]/path/", | ||
"https://REDACTED:[email protected]/path/"), | ||
arguments( | ||
"https://user1:[email protected]#test.html", | ||
"https://REDACTED:[email protected]#test.html"), | ||
arguments( | ||
"https://user1:[email protected]?foo=b@r", | ||
"https://REDACTED:[email protected]?foo=b@r"), | ||
arguments( | ||
"https://user1:[email protected]/p@th?foo=b@r", | ||
"https://REDACTED:[email protected]/p@th?foo=b@r"), | ||
arguments("https://github.com/p@th?foo=b@r", "https://github.com/p@th?foo=b@r"), | ||
arguments("https://github.com#[email protected]", "https://github.com#[email protected]"), | ||
arguments("user1:[email protected]", "user1:[email protected]"), | ||
arguments("https://github.com@", "https://github.com@"), | ||
arguments( | ||
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 test was (probably inadvertly) removed in #9925. The test is added again with new test cases. |
||
"https://service.com?paramA=valA¶mB=valB", | ||
"https://service.com?paramA=valA¶mB=valB"), | ||
arguments( | ||
"https://service.com?AWSAccessKeyId=AKIAIOSFODNN7", | ||
jeanbisutti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"https://service.com?AWSAccessKeyId=REDACTED"), | ||
arguments( | ||
"https://service.com?Signature=39Up9jzHkxhuIhFE9594DJxe7w6cIRCg0V6ICGS0%3A377", | ||
"https://service.com?Signature=REDACTED"), | ||
arguments( | ||
"https://service.com?sig=39Up9jzHkxhuIhFE9594DJxe7w6cIRCg0V6ICGS0", | ||
"https://service.com?sig=REDACTED"), | ||
arguments( | ||
"https://service.com?X-Goog-Signature=39Up9jzHkxhuIhFE9594DJxe7w6cIRCg0V6ICGS0", | ||
"https://service.com?X-Goog-Signature=REDACTED"), | ||
arguments( | ||
"https://service.com?paramA=valA&AWSAccessKeyId=AKIAIOSFODNN7¶mB=valB", | ||
"https://service.com?paramA=valA&AWSAccessKeyId=REDACTED¶mB=valB"), | ||
arguments( | ||
"https://service.com?AWSAccessKeyId=AKIAIOSFODNN7¶mA=valA", | ||
"https://service.com?AWSAccessKeyId=REDACTED¶mA=valA"), | ||
arguments( | ||
"https://service.com?paramA=valA&AWSAccessKeyId=AKIAIOSFODNN7", | ||
"https://service.com?paramA=valA&AWSAccessKeyId=REDACTED"), | ||
arguments( | ||
"https://service.com?AWSAccessKeyId=AKIAIOSFODNN7&AWSAccessKeyId=ZGIAIOSFODNN7", | ||
"https://service.com?AWSAccessKeyId=REDACTED&AWSAccessKeyId=REDACTED"), | ||
arguments( | ||
"https://service.com?AWSAccessKeyId=AKIAIOSFODNN7#ref", | ||
"https://service.com?AWSAccessKeyId=REDACTED#ref"), | ||
arguments( | ||
"https://service.com?AWSAccessKeyId=AKIAIOSFODNN7&aa&bb", | ||
"https://service.com?AWSAccessKeyId=REDACTED&aa&bb"), | ||
arguments( | ||
"https://service.com?aa&bb&AWSAccessKeyId=AKIAIOSFODNN7", | ||
"https://service.com?aa&bb&AWSAccessKeyId=REDACTED"), | ||
arguments( | ||
"https://service.com?AWSAccessKeyId=AKIAIOSFODNN7&&", | ||
"https://service.com?AWSAccessKeyId=REDACTED&&"), | ||
arguments( | ||
"https://service.com?&&AWSAccessKeyId=AKIAIOSFODNN7", | ||
"https://service.com?&&AWSAccessKeyId=REDACTED"), | ||
arguments( | ||
"https://service.com?AWSAccessKeyId=AKIAIOSFODNN7&a&b#fragment", | ||
"https://service.com?AWSAccessKeyId=REDACTED&a&b#fragment")); | ||
} | ||
} | ||
|
||
@ParameterizedTest | ||
@ArgumentsSource(ValidRequestMethodsProvider.class) | ||
void shouldExtractKnownMethods(String requestMethod) { | ||
|
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.