-
Couldn't load subscription status.
- Fork 354
[Exporter.Geneva] Add httpUrl for HTTP server spans #2818
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
rajkumar-rangaraj
merged 10 commits into
open-telemetry:main
from
xiang17:xiang17/Geneva-MsgPack-HttpUrlMapping
Jun 6, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c5d6e55
Map URL parts to httpUrl for server spans
xiang17 0ab10f3
Add unit tests
xiang17 a03b089
Reuse buffer with ThreadLocal for httpUrlParts
xiang17 ead1320
Use FrozenDictionary for NET
xiang17 58a9870
Add unit test to test MessagePack data blob
xiang17 b5452df
Add changelog
xiang17 faec951
Update PR ID and link
xiang17 d25678e
Remove unstable HTTP semconv
xiang17 c08c1f7
Remove "http.request.method" check in for loop and instead check URL …
xiang17 7333b72
fix stylecop issue
xiang17 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
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
83 changes: 83 additions & 0 deletions
83
test/OpenTelemetry.Exporter.Geneva.Tests/MsgPackTraceExporterTests.cs
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,83 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| using OpenTelemetry.Exporter.Geneva.MsgPack; | ||
| using Xunit; | ||
|
|
||
| namespace OpenTelemetry.Exporter.Geneva.Tests; | ||
|
|
||
| public class MsgPackTraceExporterTests | ||
| { | ||
| [Fact] | ||
| public void CacheIfPartOfHttpUrl_KeyPresent_IndexInRange_SetsValueAndReturnsTrue() | ||
| { | ||
| var entry = new KeyValuePair<string, object?>("url.scheme", "https"); | ||
| var arr = new object?[MsgPackTraceExporter.CS40_PART_B_HTTPURL_MAPPING.Count]; | ||
| var result = MsgPackTraceExporter.CacheIfPartOfHttpUrl(entry, arr); | ||
| Assert.True(result); | ||
| Assert.Equal("https", arr[0]); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CacheIfPartOfHttpUrl_KeyPresent_IndexOutOfRange_ReturnsFalse() | ||
| { | ||
| var entry = new KeyValuePair<string, object?>("url.scheme", "https"); | ||
| var arr = Array.Empty<object?>(); // zero-length array | ||
| var result = MsgPackTraceExporter.CacheIfPartOfHttpUrl(entry, arr); | ||
| Assert.False(result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CacheIfPartOfHttpUrl_KeyNotPresent_ReturnsFalse() | ||
| { | ||
| var entry = new KeyValuePair<string, object?>("not.a.key", "value"); | ||
| var arr = new object?[MsgPackTraceExporter.CS40_PART_B_HTTPURL_MAPPING.Count]; | ||
| var result = MsgPackTraceExporter.CacheIfPartOfHttpUrl(entry, arr); | ||
| Assert.False(result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CacheIfPartOfHttpUrl_NullValue_SetsNull() | ||
| { | ||
| var entry = new KeyValuePair<string, object?>("url.scheme", null); | ||
| var arr = new object?[MsgPackTraceExporter.CS40_PART_B_HTTPURL_MAPPING.Count]; | ||
| var result = MsgPackTraceExporter.CacheIfPartOfHttpUrl(entry, arr); | ||
| Assert.True(result); | ||
| Assert.Null(arr[0]); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData("", "", "", "", null)] | ||
| [InlineData("http", "host", "", "", "http://host")] | ||
| [InlineData("http", "host", "8080", "/x", "http://host:8080/x")] | ||
| [InlineData("https", "server", "443", "/api", "https://server:443/api")] | ||
| [InlineData("http", "host", "", "/x?y=1", "http://host/x?y=1")] | ||
| public void GetHttpUrl_ReturnsExpectedUrl(string scheme, string hostOrAddress, string port, string pathAndQuery, string? expected) | ||
| { | ||
| var arr = new object?[MsgPackTraceExporter.CS40_PART_B_MAPPING_DICTIONARY.Count]; | ||
| arr[0] = scheme; | ||
| arr[1] = hostOrAddress; | ||
| arr[2] = string.IsNullOrEmpty(port) ? null : port; | ||
| if (!string.IsNullOrEmpty(pathAndQuery) && pathAndQuery.Contains('?')) | ||
| { | ||
| var split = pathAndQuery.Split(['?'], 2); | ||
| arr[3] = split[0]; | ||
| arr[4] = split.Length > 1 ? split[1] : null; | ||
| } | ||
| else | ||
| { | ||
| arr[3] = string.IsNullOrEmpty(pathAndQuery) ? null : pathAndQuery; | ||
| } | ||
|
|
||
| var url = MsgPackTraceExporter.GetHttpUrl(arr); | ||
| Assert.Equal(expected, url); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void GetHttpUrl_UnknownMethod_ReturnsNull() | ||
| { | ||
| var arr = new object?[MsgPackTraceExporter.CS40_PART_B_HTTPURL_MAPPING.Count]; | ||
| var url = MsgPackTraceExporter.GetHttpUrl(arr); | ||
| Assert.Null(url); | ||
| } | ||
| } |
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.