opentelemetry-dotnet icon indicating copy to clipboard operation
opentelemetry-dotnet copied to clipboard

Implement Serilog Activity enricher

Open wilsonrivera opened this issue 2 years ago • 5 comments

Fixes #3453.

Changes

Implement a Serilog enricher which adds the SpanId, TraceId, ParentSpanId and ActivityTraceFlags properties to log events when the Activity.Current is not null, otherwise, these properties are not added

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

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

wilsonrivera avatar Aug 04 '22 21:08 wilsonrivera

CLA Signed

The committers listed above are authorized under a signed CLA.

  • :white_check_mark: login: wilsonrivera / name: Wilson (f94968734b94c9ed9384ff57d819b679a68a02a3)

Oh no :/ I made the changes on my 'main' branch and didn't notice until now, I hope it doesn't matter

wilsonrivera avatar Aug 04 '22 23:08 wilsonrivera

Codecov Report

Merging #3546 (ea28962) into main (d1da1d6) will decrease coverage by 0.01%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3546      +/-   ##
==========================================
- Coverage   87.44%   87.43%   -0.02%     
==========================================
  Files         278      279       +1     
  Lines       10087    10098      +11     
==========================================
+ Hits         8821     8829       +8     
- Misses       1266     1269       +3     
Impacted Files Coverage Δ
...Extensions.Serilog/OpenTelemetrySerilogEnricher.cs 100.00% <100.00%> (ø)
...tensions.Serilog/OpenTelemetrySerilogExtensions.cs 100.00% <100.00%> (ø)
src/OpenTelemetry/ProviderExtensions.cs 81.81% <0.00%> (-9.10%) :arrow_down:
...Telemetry/Metrics/PeriodicExportingMetricReader.cs 72.72% <0.00%> (-5.46%) :arrow_down:
src/OpenTelemetry/Logs/Pool/LogRecordSharedPool.cs 97.36% <0.00%> (-2.64%) :arrow_down:
src/OpenTelemetry/BatchExportProcessor.cs 84.11% <0.00%> (+1.86%) :arrow_up:

codecov[bot] avatar Aug 05 '22 03:08 codecov[bot]

@CodeBlanch I am now unsure if this is something OTel repo should provide? Its like a general serilog enricher, for enriching with Activity.Current. This does not have anything to do with sending serilog logs via OTel pipeline 🙌

cijothomas avatar Aug 05 '22 16:08 cijothomas

@CodeBlanch I am now unsure if this is something OTel repo should provide? Its like a general serilog enricher, for enriching with Activity.Current. This does not have anything to do with sending serilog logs via OTel pipeline 🙌

After a small Google search, I found out this https://github.com/RehanSaeed/Serilog.Enrichers.Span project which seems to do exactly just this, could be a better solution in the long run

wilsonrivera avatar Aug 05 '22 17:08 wilsonrivera

This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or Pushing will instruct the bot to automatically remove the label. This bot runs once per day.

github-actions[bot] avatar Aug 13 '22 03:08 github-actions[bot]

@wilsonrivera We should probably update the README a bit to explain the different things offered, use cases, etc. Feel like taking that on?

@cijothomas There is a bit on #3453 about the use case. I think this would be good to have. Why? Just to be helpful 🤣 Once a package with "OpenTelemetry" & "Serilog" exists on NuGet people will just naturally look there for this type of thing and it being from the same repo yields some confidence it will work correctly with everything else. Just my opinion!

CodeBlanch avatar Aug 15 '22 17:08 CodeBlanch

Yeah, I can do that!

wilsonrivera avatar Aug 16 '22 20:08 wilsonrivera

@wilsonrivera An update... we discussed on the weekly .NET SIG call today this PR and we have decided that it is good to be included. Later on we will likely move this project to the "contrib" repo and we might give it a dedicated package at that time, or we might try to contribute to serilog itself, but we don't need to tackle that now. I think we just need to do README updates and then we can get this merged.

CodeBlanch avatar Aug 23 '22 18:08 CodeBlanch

@wilsonrivera An update... we discussed on the weekly .NET SIG call today this PR and we have decided that it is good to be included. Later on we will likely move this project to the "contrib" repo and we might give it a dedicated package at that time, or we might try to contribute to serilog itself, but we don't need to tackle that now. I think we just need to do README updates and then we can get this merged.

Not sure the best place to ask this... but when we should end-users (e.g. myself) expect to get a prerelease NuGet package for OpenTelemetry.Extensions.Serilog? I tried copying the code but it won't build because it uses internal classes. Our project is invested in Serilog, and logging associated with traces is the last thing we need in our OTEL evaluation.

pdonovan avatar Aug 24 '22 03:08 pdonovan

@pdonovan I spun up an issue to track your question: #3602

CodeBlanch avatar Aug 24 '22 16:08 CodeBlanch

This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or Pushing will instruct the bot to automatically remove the label. This bot runs once per day.

github-actions[bot] avatar Sep 01 '22 03:09 github-actions[bot]

Closed as inactive. Feel free to reopen if this PR is still being worked on.

github-actions[bot] avatar Sep 08 '22 03:09 github-actions[bot]

Sorry for the delay, life got in the way but I've wrote a little documentation on how to setup the activity enricher, directly on the Serilog project

wilsonrivera avatar Sep 26 '22 06:09 wilsonrivera

Sorry for the delay, life got in the way but I've wrote a little documentation on how to setup the activity enricher, directly on the Serilog project

Link? I had a quick look around the GitHub serilog pages but couldn't find anything.

pdonovan avatar Sep 26 '22 07:09 pdonovan