-
Notifications
You must be signed in to change notification settings - Fork 773
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
[Instrumentation.Http][Instrumentation.AspNetCore] Fix url.full
and url.query
attribute values
#5532
Merged
CodeBlanch
merged 8 commits into
open-telemetry:main
from
vishweshbankwar:vibankwa/redact-http-attributes
Apr 12, 2024
Merged
[Instrumentation.Http][Instrumentation.AspNetCore] Fix url.full
and url.query
attribute values
#5532
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
861b556
redaction
vishweshbankwar 85a5c79
readme updates
vishweshbankwar 76d0ed4
review
vishweshbankwar 2a15b5d
better comment
vishweshbankwar 8db768e
changelog
vishweshbankwar e2d1d7e
Merge branch 'main' into vibankwa/redact-http-attributes
vishweshbankwar 2903ac7
PR link
vishweshbankwar b6fde65
Merge branch 'vibankwa/redact-http-attributes' of https://github.com/…
vishweshbankwar 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
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
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,59 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#nullable enable | ||
|
||
using System.Text; | ||
|
||
namespace OpenTelemetry.Internal; | ||
|
||
internal class RedactionHelper | ||
{ | ||
private static readonly string RedactedText = "Redacted"; | ||
|
||
public static string? GetRedactedQueryString(string query) | ||
{ | ||
int length = query.Length; | ||
int index = 0; | ||
|
||
// Preallocate some size to avoid re-sizing multiple times. | ||
// Since the size will increase, allocating twice as much. | ||
// TODO: Check to see if we can borrow from https://github.com/dotnet/runtime/blob/main/src/libraries/Common/src/System/Text/ValueStringBuilder.cs | ||
// to improve perf. | ||
StringBuilder queryBuilder = new(2 * length); | ||
while (index < query.Length) | ||
{ | ||
// Check if the character is = for redacting value. | ||
if (query[index] == '=') | ||
{ | ||
// Append = | ||
queryBuilder.Append('='); | ||
index++; | ||
|
||
// Append redactedText in place of original value. | ||
queryBuilder.Append(RedactedText); | ||
|
||
// Move until end of this key/value pair. | ||
while (index < length && query[index] != '&') | ||
{ | ||
index++; | ||
} | ||
|
||
// End of key/value. | ||
if (index < length && query[index] == '&') | ||
{ | ||
queryBuilder.Append(query[index]); | ||
} | ||
} | ||
else | ||
{ | ||
// Keep adding to the result | ||
queryBuilder.Append(query[index]); | ||
} | ||
|
||
index++; | ||
} | ||
|
||
return queryBuilder.ToString(); | ||
} | ||
} |
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.
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 changelog is not very clear. Could we make it clear the why here as well?
Also, using the word "tag" may not be obvious that it is referring to "attributes".