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

Remove ActivitySourceAdapter from AspNetCore #1654

Closed
wants to merge 2 commits into from
Closed

Remove ActivitySourceAdapter from AspNetCore #1654

wants to merge 2 commits into from

Conversation

eddynaka
Copy link
Contributor

Refs #1585

Changes

Please provide a brief description of the changes here.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Design discussion issue #
  • Changes in public API reviewed

@@ -81,36 +79,37 @@ public override void OnStartActivity(Activity activity, object payload)
return;
}

ActivityContext activityContext = default;
Copy link
Member

Choose a reason for hiding this comment

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

rename to parentActivityContextOfOriginalActivity if you don't mind looong names.

@cijothomas
Copy link
Member

Not for merging now. Just to demonstrate the concept. We can borrow this approach for other instrumentation and see if it can a good alternative, than exposing ActivitySourceAdapter.
Either way, the correct fix would to modify the libraries to switch to ActivitySource itself, to avoid any hacks elsewhere.

@ejsmith
Copy link
Contributor

ejsmith commented Dec 15, 2020

Not for merging now. Just to demonstrate the concept. We can borrow this approach for other instrumentation and see if it can a good alternative, than exposing ActivitySourceAdapter.
Either way, the correct fix would to modify the libraries to switch to ActivitySource itself, to avoid any hacks elsewhere.

  1. we don't have control over a lot of these libraries that we would like to add instrumentation to that works with OTel.
  2. even if we do, changing them to be ActivitySource probably means they won't work for older tools that were being used to monitor them. So that doesn't really seem like a good option.

@@ -208,8 +207,6 @@ public override void OnStopActivity(Activity activity, object payload)
// the one created by the instrumentation.
// And retrieve it here, and set it to Current.
}

this.activitySource.Stop(activity);
Copy link
Member

Choose a reason for hiding this comment

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

It looks like AspNetCore hosting keeps a reference to the Activity it started and that's the one it will stop:

https://github.com/dotnet/aspnetcore/blob/4a7ed303fff26e4070e02e385fb22df484f6b81f/src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs#L134-L139

So my question is: Does the Activity we create in this approach actually get stopped?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@CodeBlanch , when you say "this approach", that means the old approach or this new one? For the new one, we are replacing the activity, but, if aspnetcore has a reference there, we might be creating a new one that would never be stopped.
@cijothomas to comment as well :)

Copy link
Member

Choose a reason for hiding this comment

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

@eddynaka I meant the new approach sorry 😄

For the new one, we are replacing the activity, but, if aspnetcore has a reference there, we might be creating a new one that would never be stopped.

Ya, exactly. That would be a problem!

Copy link
Member

Choose a reason for hiding this comment

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

we are stopping our own activity. aspnet core stops their activity. check line 197 for our activity being stopped.

(This is a diff. issue in AspNet, as it relies on Activity.Current, so we need to restore it for AspNet, but for AspNetCore we dont. But agree - this is a bit flaky design, and will fall apart if aspnetcore changes their implementation. We'll need to revisit this in .NET6, when they are expected to do some changes.)

Copy link
Member

Choose a reason for hiding this comment

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

@eddynaka Can you verify the one we're creating is stopped correctly? I see the activity.Stop on LN197 but we're stopping the same activity passed in OnStopActivity so it should already be stopped? 🤷

Copy link
Member

Choose a reason for hiding this comment

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

OnStopActivity gets Activity.Current, which should be the one we created, right?

Copy link
Member

Choose a reason for hiding this comment

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

Ya you're right it works fine. Just took it for a spin to verify.

@cijothomas
Copy link
Member

Not for merging now. Just to demonstrate the concept. We can borrow this approach for other instrumentation and see if it can a good alternative, than exposing ActivitySourceAdapter.
Either way, the correct fix would to modify the libraries to switch to ActivitySource itself, to avoid any hacks elsewhere.

  1. we don't have control over a lot of these libraries that we would like to add instrumentation to that works with OTel.
  2. even if we do, changing them to be ActivitySource probably means they won't work for older tools that were being used to monitor them. So that doesn't really seem like a good option.

This is already known. Even if .NET libraries (or any library) move to ActivitySource, it'll only be for new version only. For older version, use the approach demo-ed in this PR. After 1.0.0 is out, we'll revisit ActivitySourceAdapter approach.

@eddynaka eddynaka changed the base branch from master to main January 27, 2021 22:15
@cijothomas
Copy link
Member

Closing as this PR was meant to demo an concept only.

@cijothomas cijothomas closed this Feb 5, 2021
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.

4 participants