-
Notifications
You must be signed in to change notification settings - Fork 773
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Instrumentation.Http][Instrumentation.AspNetCore] Fix
url.full
and…
… `url.query` attribute values (#5532)
- Loading branch information
1 parent
0bbebb5
commit e222ecb
Showing
22 changed files
with
359 additions
and
15 deletions.
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.