Skip to content
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] Skip tagging traces when running on .NET 9+ #2314

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
ec51d6f
change Instrumentation.Http to fall back in case of NET9. update unit…
TimothyMothra Nov 12, 2024
3c11ae7
cleanup
TimothyMothra Nov 12, 2024
1a07eca
Merge branch 'main' into 2029_httpinstrumentation_net9
TimothyMothra Nov 12, 2024
8c01b21
fix line endings
TimothyMothra Nov 12, 2024
c25344f
Merge branch '2029_httpinstrumentation_net9' of https://github.com/Ti…
TimothyMothra Nov 12, 2024
1f76f2b
dotnet format
TimothyMothra Nov 12, 2024
339499b
fix access modifiers
TimothyMothra Nov 12, 2024
5aa0e76
fix: add missing cases to switch expression
TimothyMothra Nov 12, 2024
39330f6
fix: test class must be public
TimothyMothra Nov 12, 2024
6fe41be
fix line endings
TimothyMothra Nov 12, 2024
dd3e7f5
testing downgrading the AnalysisLevel.
TimothyMothra Nov 12, 2024
d8d4748
fix: Use pattern matching
TimothyMothra Nov 12, 2024
35a4082
fix: unused variable
TimothyMothra Nov 12, 2024
37563a9
testing changes for Net9 GA
TimothyMothra Nov 12, 2024
c7a06ac
Revert "testing changes for Net9 GA"
TimothyMothra Nov 13, 2024
228bf66
Revert "fix: unused variable"
TimothyMothra Nov 13, 2024
2ce6d41
Revert "testing downgrading the AnalysisLevel."
TimothyMothra Nov 13, 2024
a5aeac9
merge main and resolve conflicts
TimothyMothra Nov 13, 2024
f706e80
testing update to CI
TimothyMothra Nov 13, 2024
27477b6
fix test
TimothyMothra Nov 13, 2024
60b2f5a
add TODO
TimothyMothra Nov 13, 2024
a35941e
cleanup csproj
TimothyMothra Nov 13, 2024
7075153
cleanup extra whitespace
TimothyMothra Nov 13, 2024
8b339ed
fix line endings
TimothyMothra Nov 13, 2024
3022333
cleanup comments. link to tracking issue
TimothyMothra Nov 14, 2024
f9fa4f3
Merge branch 'main' into 2029_httpinstrumentation_net9
TimothyMothra Nov 14, 2024
ff8ff91
fix line endings
TimothyMothra Nov 14, 2024
3b55505
Merge branch 'main' into 2029_httpinstrumentation_net9
TimothyMothra Nov 14, 2024
ce50ec8
remove net9 framework changes. change was made in different pr
TimothyMothra Nov 14, 2024
e6ff071
cleanup
TimothyMothra Nov 15, 2024
c5dc2c9
update changelog
TimothyMothra Nov 15, 2024
8b3eaab
Merge branch 'main' into 2029_httpinstrumentation_net9
TimothyMothra Nov 15, 2024
292c915
Merge branch 'main' into 2029_httpinstrumentation_net9
TimothyMothra Nov 15, 2024
f6f28f6
cleanup static var
TimothyMothra Nov 15, 2024
8fc7f6b
Merge branch '2029_httpinstrumentation_net9' of https://github.com/Ti…
TimothyMothra Nov 15, 2024
03ad8a9
Update src/OpenTelemetry.Instrumentation.Http/CHANGELOG.md
TimothyMothra Nov 16, 2024
8150955
fix line endings
TimothyMothra Nov 16, 2024
8aa7da5
Merge branch 'main' into 2029_httpinstrumentation_net9
TimothyMothra Nov 22, 2024
8456bfc
fix variable name
TimothyMothra Nov 22, 2024
b4fc4b0
Merge branch 'main' into 2029_httpinstrumentation_net9
TimothyMothra Nov 22, 2024
1966f13
cleanup
TimothyMothra Nov 22, 2024
c1bc5e6
Merge branch '2029_httpinstrumentation_net9' of https://github.com/Ti…
TimothyMothra Nov 22, 2024
39afd82
Merge branch 'main' into 2029_httpinstrumentation_net9
TimothyMothra Nov 22, 2024
663d6ce
Merge branch 'main' into 2029_httpinstrumentation_net9
TimothyMothra Nov 25, 2024
af8c7a7
revert change to Metrics
TimothyMothra Nov 25, 2024
894fb19
cleanup
TimothyMothra Nov 25, 2024
cecbf1e
pr feedback
TimothyMothra Nov 25, 2024
72440bb
Merge branch 'main' into 2029_httpinstrumentation_net9
TimothyMothra Nov 25, 2024
7af3591
fix line endings
TimothyMothra Nov 25, 2024
be0b745
update changelog and readme
TimothyMothra Nov 27, 2024
3b9427d
readme
TimothyMothra Nov 27, 2024
d65b138
pr feedback
TimothyMothra Nov 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"rollForward": "latestFeature",
"version": "8.0.100"
"version": "9.0.100-rc.2.24474.11"
TimothyMothra marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
private static readonly PropertyFetcher<HttpResponseMessage> StopResponseFetcher = new("Response");
private static readonly PropertyFetcher<Exception> StopExceptionFetcher = new("Exception");
private static readonly PropertyFetcher<TaskStatus> StopRequestStatusFetcher = new("RequestTaskStatus");
private static readonly bool Net9orGreater = Environment.Version.Major >= 9;

private readonly HttpClientTraceInstrumentationOptions options;

public HttpHandlerDiagnosticListener(HttpClientTraceInstrumentationOptions options)
Expand Down Expand Up @@ -135,10 +137,13 @@
ActivityInstrumentationHelper.SetKindProperty(activity, ActivityKind.Client);
}

// see the spec https://github.com/open-telemetry/semantic-conventions/blob/v1.23.0/docs/http/http-spans.md
HttpTagHelper.RequestDataHelper.SetHttpMethodTag(activity, request.Method.Method);
if (!Net9orGreater)
{
// see the spec https://github.com/open-telemetry/semantic-conventions/blob/v1.23.0/docs/http/http-spans.md
HttpTagHelper.RequestDataHelper.SetHttpMethodTag(activity, request.Method.Method);
}

if (request.RequestUri != null)
if (!Net9orGreater && request.RequestUri != null)
{
activity.SetTag(SemanticConventions.AttributeServerAddress, request.RequestUri.Host);
activity.SetTag(SemanticConventions.AttributeServerPort, request.RequestUri.Port);
Expand Down Expand Up @@ -199,16 +204,19 @@

if (TryFetchResponse(payload, out var response))
{
if (currentStatusCode == ActivityStatusCode.Unset)
if (!Net9orGreater)
{
activity.SetStatus(SpanHelper.ResolveActivityStatusForHttpStatusCode(activity.Kind, (int)response.StatusCode));
}
if (currentStatusCode == ActivityStatusCode.Unset)
{
activity.SetStatus(SpanHelper.ResolveActivityStatusForHttpStatusCode(activity.Kind, (int)response.StatusCode));
}

activity.SetTag(SemanticConventions.AttributeNetworkProtocolVersion, RequestDataHelper.GetHttpProtocolVersion(response.Version));
activity.SetTag(SemanticConventions.AttributeHttpResponseStatusCode, TelemetryHelper.GetBoxedStatusCode(response.StatusCode));
if (activity.Status == ActivityStatusCode.Error)
{
activity.SetTag(SemanticConventions.AttributeErrorType, TelemetryHelper.GetStatusCodeString(response.StatusCode));
activity.SetTag(SemanticConventions.AttributeNetworkProtocolVersion, RequestDataHelper.GetHttpProtocolVersion(response.Version));
activity.SetTag(SemanticConventions.AttributeHttpResponseStatusCode, TelemetryHelper.GetBoxedStatusCode(response.StatusCode));
if (activity.Status == ActivityStatusCode.Error)
{
activity.SetTag(SemanticConventions.AttributeErrorType, TelemetryHelper.GetStatusCodeString(response.StatusCode));
}
}

try
Expand Down Expand Up @@ -302,7 +310,7 @@
// https://learn.microsoft.com/dotnet/api/system.net.http.httprequesterror?view=net-8.0
if (exc is HttpRequestException httpRequestException)
{
return httpRequestException.HttpRequestError switch

Check failure on line 313 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-instrumentation-http / build-test (windows-latest, net462)

Populate switch (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0072)

Check failure on line 313 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-instrumentation-http / build-test (windows-latest, net462)

Populate switch (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0072)

Check failure on line 313 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-instrumentation-http / build-test (windows-latest, net462)

Populate switch (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0072)

Check failure on line 313 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-instrumentation-http / build-test (windows-latest, net8.0)

Populate switch (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0072)

Check failure on line 313 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-instrumentation-http / build-test (windows-latest, net8.0)

Populate switch (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0072)

Check failure on line 313 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-instrumentation-http / build-test (windows-latest, net8.0)

Populate switch (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0072)

Check failure on line 313 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-instrumentation-http / build-test (ubuntu-latest, net8.0)

Populate switch (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0072)

Check failure on line 313 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-instrumentation-http / build-test (ubuntu-latest, net8.0)

Populate switch (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0072)

Check failure on line 313 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-instrumentation-http / build-test (ubuntu-latest, net8.0)

Populate switch (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0072)

Check failure on line 313 in src/OpenTelemetry.Instrumentation.Http/Implementation/HttpHandlerDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-instrumentation-http / build-test (ubuntu-latest, net8.0)

Populate switch (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0072)
{
HttpRequestError.NameResolutionError => "name_resolution_error",
HttpRequestError.ConnectionError => "connection_error",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ internal sealed class HttpHandlerMetricsDiagnosticListener : ListenerHandler
private static readonly PropertyFetcher<HttpResponseMessage> StopResponseFetcher = new("Response");
private static readonly PropertyFetcher<Exception> StopExceptionFetcher = new("Exception");
private static readonly PropertyFetcher<HttpRequestMessage> RequestFetcher = new("Request");
private static readonly bool Net9orGreater = Environment.Version.Major >= 9;
#if NET
private static readonly HttpRequestOptionsKey<string?> HttpRequestOptionsErrorKey = new(SemanticConventions.AttributeErrorType);
#endif
Expand All @@ -39,7 +40,7 @@ public HttpHandlerMetricsDiagnosticListener(string name)

public static void OnStopEventWritten(Activity activity, object? payload)
{
if (TryFetchRequest(payload, out var request))
if (!Net9orGreater && TryFetchRequest(payload, out var request))
{
// see the spec https://github.com/open-telemetry/semantic-conventions/blob/v1.23.0/docs/http/http-metrics.md
TagList tags = default;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(NetMinimumSupportedVersion);$(NetStandardMinimumSupportedVersion)</TargetFrameworks>
<TargetFrameworks>net9.0;$(NetMinimumSupportedVersion);$(NetStandardMinimumSupportedVersion)</TargetFrameworks>
TimothyMothra marked this conversation as resolved.
Show resolved Hide resolved
<TargetFrameworks Condition="$(OS) == 'Windows_NT'">$(TargetFrameworks);$(NetFrameworkMinimumSupportedVersion)</TargetFrameworks>
<Description>Http instrumentation for OpenTelemetry .NET.</Description>
<PackageTags>$(PackageTags);distributed-tracing</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,18 @@ public async Task HttpRequestMethodIsSetOnActivityAsPerSpec(string originalMetho
}

Assert.Equal(expectedMethod, activity.GetTagValue(SemanticConventions.AttributeHttpRequestMethod));

#if NET9_0_OR_GREATER
TimothyMothra marked this conversation as resolved.
Show resolved Hide resolved
if (expectedOriginalMethod != null && expectedOriginalMethod != "CUSTOM")
{
// TODO: NEED TO REVIEW THE SPEC.
// "http.request.method_original" is only set when the HTTP Method is not a standard HTTP method.

// Our implementation expects HTTP Methods to be in uppercase. "GET" is known but "Get" is unknown.
// In contrast, NET9 is case-insensitive. "GET" and "Get" are both known.
expectedOriginalMethod = null;
}
#endif
Assert.Equal(expectedOriginalMethod, activity.GetTagValue(SemanticConventions.AttributeHttpRequestMethodOriginal));
}

Expand Down Expand Up @@ -727,7 +739,17 @@ public async Task ValidateUrlQueryRedaction(string urlQuery, string expectedUrlQ
var activity = exportedItems[0];

var expectedUrl = $"{this.url}path{expectedUrlQuery}";

#if NET9_0_OR_GREATER

// TODO: NEED TO UPDATE THIS TEST TO USE .NET'S SETTING TO DISABLE REDACTION.
// CURRENTLY THIS DOESN'T WORK WITH OUR TESTS WHICH RUN IN PARALLEL.
// https://github.com/dotnet/docs/issues/42792
expectedUrl = $"{this.url}path?*";
Assert.Equal(expectedUrl, activity.GetTagValue(SemanticConventions.AttributeUrlFull));
#else
Assert.Equal(expectedUrl, activity.GetTagValue(SemanticConventions.AttributeUrlFull));
#endif
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,21 @@ private static async Task HttpOutCallsAreCollectedSuccessfullyBodyAsync(
Assert.Contains(normalizedAttributes, kvp => kvp.Key == SemanticConventions.AttributeHttpRequestMethod && kvp.Value?.ToString() == normalizedAttributesTestCase[SemanticConventions.AttributeHttpRequestMethod]);
Assert.Contains(normalizedAttributes, kvp => kvp.Key == SemanticConventions.AttributeServerAddress && kvp.Value?.ToString() == normalizedAttributesTestCase[SemanticConventions.AttributeServerAddress]);
Assert.Contains(normalizedAttributes, kvp => kvp.Key == SemanticConventions.AttributeServerPort && kvp.Value?.ToString() == normalizedAttributesTestCase[SemanticConventions.AttributeServerPort]);

#if NET9_0_OR_GREATER
// NET9 does not record the URL Fragment Identifier.
var expected = normalizedAttributesTestCase[SemanticConventions.AttributeUrlFull];
if (expected.EndsWith("#fragment", StringComparison.Ordinal))
{
// remove fragment from expected value
expected = expected.Substring(0, expected.Length - "#fragment".Length);
}

Assert.Contains(normalizedAttributes, kvp => kvp.Key == SemanticConventions.AttributeUrlFull && kvp.Value?.ToString() == expected);
#else
Assert.Contains(normalizedAttributes, kvp => kvp.Key == SemanticConventions.AttributeUrlFull && kvp.Value?.ToString() == normalizedAttributesTestCase[SemanticConventions.AttributeUrlFull]);
#endif

if (tc.ResponseExpected)
{
Assert.Contains(normalizedAttributes, kvp => kvp.Key == SemanticConventions.AttributeNetworkProtocolVersion && kvp.Value?.ToString() == normalizedAttributesTestCase[SemanticConventions.AttributeNetworkProtocolVersion]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(SupportedNetTargets)</TargetFrameworks>
<TargetFrameworks>net9.0;$(SupportedNetTargets)</TargetFrameworks>
TimothyMothra marked this conversation as resolved.
Show resolved Hide resolved
<TargetFrameworks Condition="$(OS) == 'Windows_NT'">$(TargetFrameworks);$(NetFrameworkMinimumSupportedVersion)</TargetFrameworks>
<Description>Unit test project for OpenTelemetry HTTP instrumentations.</Description>
</PropertyGroup>
Expand Down
Loading