loglayer icon indicating copy to clipboard operation
loglayer copied to clipboard

Add OpenTelemetry logging support

Open BryanHuntNV opened this issue 1 year ago • 13 comments

Could we get OpenTelemetry supported as a logger?

BryanHuntNV avatar Oct 17 '24 14:10 BryanHuntNV

Can you write example code that uses open telemetry showing how I would do logging? Docs aren't clear on how to do logging with it.

If you can provide an example I can spend time today looking into it since I have the day off.

theogravity avatar Oct 17 '24 15:10 theogravity

This is the best starting point I can provide right now: https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/opentelemetry-instrumentation-winston/src/instrumentation.ts

It is rather convoluted to read, but hopefully it would take you down the right path. If you don't get anywhere with that code, I can try to dig deeper next week.

BryanHuntNV avatar Oct 17 '24 15:10 BryanHuntNV

Are you using winston? If so, why not just attach it to winston and use winston with loglayer?

My familiarity with these kinds of observational libs is with DataDog / dd-trace and we use pino with loglayer and i use a plugin callback on loglayer to inject the trace id before the log ships to pino.

theogravity avatar Oct 17 '24 15:10 theogravity

I guess a better question is - what is your use case that you wouldn't use a conventional logger and instead try to get an instrumentation lib to do it instead?

Usually instrumentation is separate from logging and where they intersect is maybe you implant the trace id from it into your log entry so the log can be cross-referenced with the trace.

The file you posted generally patches the underlying logging library to auto-stamp the tracing id under the hood.

theogravity avatar Oct 17 '24 15:10 theogravity

I was just trying to reduce my dependency footprint. Maybe this request is not practical.

BryanHuntNV avatar Oct 17 '24 15:10 BryanHuntNV

I'd be ok closing the request.

BryanHuntNV avatar Oct 17 '24 15:10 BryanHuntNV

To me, they're two separate domains which is why I needed an example on how one would do logging with the lib itself, because these libs generally don't do logging, they just patch it to include the trace reference.

theogravity avatar Oct 17 '24 15:10 theogravity

I'd be ok closing the request.

Yeah unfortunately I don't think opentelemetry falls under something that loglayer would support since it's not really a logging lib.

theogravity avatar Oct 17 '24 15:10 theogravity

FWIW: https://www.perplexity.ai/search/can-i-do-direct-logging-in-ope-HFxWqg5jQgKnaYXXwI3edA

BryanHuntNV avatar Oct 17 '24 15:10 BryanHuntNV

I won't have a problem if you close this. Sometimes my ideas are bad.

BryanHuntNV avatar Oct 17 '24 15:10 BryanHuntNV

That is the most messiest API for logging I've seen and it's clear that the lib wasn't meant to do that since it's pretty much conveying the idea of a log entry as an instrumentation event. It's also probably very specific to Perplexity.

If your goal is to reduce dependencies, why install a whole slew of them to just enable logging for it vs using a dedicated logging library?

Is it possible now that you've provided the API? Yes, but it makes me really hesitant to want to do it.

But also gives me ideas on for a next major version of loglayer where i'd expose a plugin system for shipping logs.

theogravity avatar Oct 17 '24 15:10 theogravity

Let's keep this open for now. I do want to work on a new major version that allows for multiple loggers and the ability to write your own shippers.

I don't have a timeline for this unfortunately.

theogravity avatar Oct 17 '24 15:10 theogravity

I won't have a problem if you close this. Sometimes my ideas are bad.

Yeah, it's a bad idea, but you gave some inspiration!

theogravity avatar Oct 17 '24 15:10 theogravity

LogLayer 5.x is now out which should now support adding something like this. You can do it by creating your own Transport where you'd assign the incoming message parameters to the log entry on the OpenTelemetry side.

It's not something I think I'd want to make into an official plugin because it still feels strange as a concept to me, but if you have a working sample, I can def consider adding it for others to use!

theogravity avatar Jan 02 '25 23:01 theogravity

I've added support for OpenTelemetry. See docs for more info.

theogravity avatar Jan 13 '25 08:01 theogravity