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

Fix OpenTracing shim under legacy AspNetCore activities #3506

Merged

Conversation

pjanotti
Copy link
Contributor

@pjanotti pjanotti commented Jul 29, 2022

Changes

Fixes OpenTracing spans under the legacy Activity "Microsoft.AspNetCore.Hosting.HttpRequestIn" (enabled by AspNetCore instrumentation package). The OpenTracing spans under the legacy Activity can be missing, having broken parent/active span relationships and cause the premature termination of the legacy activity.

The special handling for "Microsoft.AspNetCore.Hosting.HttpRequestIn" on the OpenTracing shim was present since the first version of the shim, see #197. It got its current behavior on #994. However, that behavior makes the first OT span under the legacy activity to not be created, the legacy activity to be stopped where the first OT span finishes, and any subsequent OT span to be created under the context of the legacy activity parent (which typically means creating a new trace).

The OpenTracing spans should be integrated with OpenTelemetry traces, consider the case of third-party libraries instrumented with OpenTracing. The fix simply consists in removing the special case for "Microsoft.AspNetCore.Hosting.HttpRequestIn".

  • Appropriate CHANGELOG.md updated for non-trivial changes

@pjanotti pjanotti requested a review from a team July 29, 2022 23:53
@codecov
Copy link

codecov bot commented Jul 30, 2022

Codecov Report

Merging #3506 (47dc8cc) into main (2821898) will increase coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3506      +/-   ##
==========================================
+ Coverage   86.67%   86.72%   +0.04%     
==========================================
  Files         275      275              
  Lines        9958     9950       -8     
==========================================
- Hits         8631     8629       -2     
+ Misses       1327     1321       -6     
Impacted Files Coverage Δ
...OpenTelemetry.Shims.OpenTracing/SpanBuilderShim.cs 95.34% <100.00%> (+3.85%) ⬆️
...Listener/Internal/PrometheusExporterEventSource.cs 16.66% <0.00%> (-11.12%) ⬇️
...emetry.Api/Internal/OpenTelemetryApiEventSource.cs 73.52% <0.00%> (-8.83%) ⬇️
src/OpenTelemetry/Logs/OpenTelemetryLogger.cs 86.66% <0.00%> (-4.45%) ⬇️
....Prometheus.HttpListener/PrometheusHttpListener.cs 78.66% <0.00%> (-4.00%) ⬇️
src/OpenTelemetry/BatchExportProcessor.cs 82.24% <0.00%> (-1.87%) ⬇️
...metryProtocol/Implementation/ActivityExtensions.cs 94.50% <0.00%> (+3.29%) ⬆️
...xporter.OpenTelemetryProtocol/OtlpTraceExporter.cs 77.27% <0.00%> (+18.18%) ⬆️
...entation/ExportClient/OtlpGrpcTraceExportClient.cs 78.57% <0.00%> (+28.57%) ⬆️

@pjanotti
Copy link
Contributor Author

pjanotti commented Aug 2, 2022

@open-telemetry/dotnet-approvers I'm planning to join the SIG meeting today in case you have any Q about this PR.

@rwkarg
Copy link

rwkarg commented Aug 2, 2022

@open-telemetry/dotnet-approvers I'm planning to join the SIG meeting today in case you have any Q about this PR.

Can't make the SIG, but we're running a local fork with this PR and it's resolved the broken trace issues we previously had when using the shim.

Copy link
Member

@alanwest alanwest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving since this PR seems to take things in the right direction. It might even resolve #2257.

Though there's a lot about this shim that seems kinda rough. For starters, it wraps the OpenTelemetry shim API which in turn wraps the Activity API. Probably would make more sense to use the Activity API directly.

@@ -330,5 +330,29 @@ public void Start()
Assert.NotNull(span);
Assert.Equal("foo", span.Span.Activity.OperationName);
}

[Fact]
public void Start_UnderAspNetCoreInstrumentation()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test would have passed before this PR. Is it testing a scenario that was not already covered?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old code fails on the assert at line 350

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also on 355 if check of 350 was removed.

@pjanotti
Copy link
Contributor Author

pjanotti commented Aug 2, 2022

@alanwest

Though there's a lot about this shim that seems kinda rough. For starters, it wraps the OpenTelemetry shim API which in turn wraps the Activity API. Probably would make more sense to use the Activity API directly.

Yeah, I think that reviewing the whole shim seems a good idea.

@pjanotti
Copy link
Contributor Author

pjanotti commented Aug 3, 2022

It might even resolve #2257

Yes, this PR should fix #2257 and #2787 too.

@cijothomas cijothomas merged commit 3929727 into open-telemetry:main Aug 3, 2022
@pjanotti pjanotti deleted the ot-shim-under-aspnetcore-instr branch August 3, 2022 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants