Skip to content

Hoist activity fields to the logging scope #11211

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
merged 6 commits into from
Jun 17, 2019

Conversation

davidfowl
Copy link
Member

  • Expose SpanId, TraceId and ParentId to logging scope properties
  • Added tests to verify the Hierarchical ID format

Fixes #9491

PS: I need to spend some time looking at allocations before I merge this.

cc @benaadams

cc @lmolkova @SergeyKanzhelev for review

- Expose SpanId, TraceId and ParentId to logging scope properties
- Added tests to verify the Hierarchical ID format
@benaadams
Copy link
Member

Do you need to capture the fields to HostingLogScope directly? Is it safe to capture the Activity then output the values from that when needed?

@davidfowl
Copy link
Member Author

Do you need to capture the fields to HostingLogScope directly? Is it safe to capture the Activity then output the values from that when needed?

I was going to but storing the async local felt strange. I'll need to experiment with that.

@benaadams
Copy link
Member

I was going to but storing the async local felt strange.

That's just a tangental bit of Activity? Hosting creates the Scope, Activity and starts it; as well as Disposing the Scope and ending the Activity, and the Activity doesn't get reused, so should be ok?

// Arrange

// Generate an id we can use for the request id header (in the correct format)
var activity = new Activity("IncomingRequest");
Copy link
Member Author

Choose a reason for hiding this comment

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

BTW @lmolkova this why I'd like this feature https://github.com/dotnet/corefx/issues/36999. It's makes unit testing possible.

@davidfowl
Copy link
Member Author

That's just a tangental bit of Activity? Hosting creates the Scope, Activity and starts it; as well as Disposing the Scope and ending the Activity, and the Activity doesn't get reused, so should be ok?

Yes, you're right, it would just be storing the activity object on 2 async locals (Activity.Current and the logging scope). It does mean it would have similar issues to holding onto the HttpContext but maybe it won't be as big a problem since not much is stored on the activity currently.

@davidfowl
Copy link
Member Author

🆙 📅

@davidfowl davidfowl merged commit f7a2d3c into master Jun 17, 2019
@ghost ghost deleted the davidfowl/activity-log-scope branch June 17, 2019 22:17
shirhatti added a commit that referenced this pull request May 29, 2020
shirhatti added a commit that referenced this pull request Jun 1, 2020
shirhatti added a commit that referenced this pull request Jun 3, 2020
shirhatti added a commit that referenced this pull request Jun 3, 2020
shirhatti added a commit that referenced this pull request Jun 22, 2020
* Revert "Hoist activity fields to the logging scope (#11211)"

This reverts commit f7a2d3c.

* Remove tests with Activity

* Remove ActivityId from HostingLogScope

* Enable propogation in CreateDefaultBuilder

* Clean up

* s/logging/loggingBuilder

* Enable Activity propogation for generichost

* Replace with runtime/pull/37892
@amcasey amcasey added the area-hosting Includes Hosting label Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-hosting Includes Hosting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider tracing span id and trace id separately in the log
6 participants