question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Request: Attach log messages to Activity.Events

See original GitHub issue

[This came out of a discussion on gitter with @jchannon.]

Feature Request

OpenTracing.Contrib.NetCore will register an ILoggerProvider\ILogger which will attach log messages to a span and these are exported to Jaeger.

The ask is to have a similar mechanism in OpenTelemetry .NET.

Design

Our JaegerExporter is already coded to convert ActivityEvents into JaegerLogs: https://github.com/open-telemetry/opentelemetry-dotnet/blob/6fe93f8d79725d696e01090ab531585881636850/src/OpenTelemetry.Exporter.Jaeger/Implementation/JaegerActivityExtensions.cs#L158-L175

Given that behavior, the idea is to add a BaseProcessor<LogRecord> which will convert log messages written through ILogger into ActivityEvents and add them to Activity.Current.Events. Presumably only when Activity.IsAllDataRequested = true but this could be configurable.

This will be something you will have to explicitly turn on because it is expensive.

Proposed API

Coming soon…

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:12
  • Comments:19 (7 by maintainers)

github_iconTop GitHub Comments

5reactions
iSeiryucommented, Feb 11, 2021

@CodeBlanch Something like this? https://github.com/iSeiryu/opentelemetry-dotnet/commit/c13208510f8139bdeac966298fd911db31170dcd

Since there is no proper example for classes like that (the only existing one is for Console and it uses BaseExporter<LogRecord> instead of BaseProcessor<LogRecord>) I probably messed up some naming conventions.

I tested it on local and it works. It logs general system and custom logs as well as the exceptions. I left the options empty but I’m sure it would require some configuration.

image

5reactions
CodeBlanchcommented, Feb 11, 2021

The logging code in 1.0 registers an ILoggerProvider which will create ILoggers that call this line:

https://github.com/open-telemetry/opentelemetry-dotnet/blob/3239e5b02f639779d93b22427fece7370579432b/src/OpenTelemetry/Logs/OpenTelemetryLogger.cs#L52

Any time a log message is written, the registered BaseProcessor<LogRecord> will be called. The problem is, there’s no BaseProcessor<LogRecord> implementation in there. If you build your own, you can make it work.

That’s exactly what I’m going to do for this issue/feature. I’m going to create a BaseProcessor<LogRecord> that adds the log messages to Activity.Events so they will export to Jaeger. Now that 1.0 is out, I’ll get back to that. But if you want to give it a shot feel free 😄

Also, if I’m using Serilog in an ASP.NET Core application, will this still work?

Only if you are using serilog-extensions-logging which will write through ILogger before Serilog’s custom logger.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Log events | Google Analytics for Firebase
This guide shows you how to log events in your app. Events provide insight on what is happening in your app, such as...
Read more >
Send activity feed notifications to users in Microsoft Teams
This example shows how you can send an activity feed notification to all team members. This example notifies the team members about a...
Read more >
Azure Monitor activity log
View the Azure Monitor activity log and send it to Azure Monitor Logs, Azure Event Hubs, and Azure Storage.
Read more >
View logs with Logcat | Android Studio
Learn how to display system messages with the Logcat window in Android Studio. ... To view the log messages for your app, do...
Read more >
Logcat command-line tool | Android Studio
Logcat is a command-line tool that dumps a log of system messages including messages that you have written from your app with the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found