theogravity / loglayer

Standardizes logging across multiple Javascript logging libraries, providing a consistent way to specify context, metadata, and errors.
MIT License
76 stars 3 forks source link

Add OpenTelemetry logging support #45

Open BryanHuntNV opened 1 week ago

BryanHuntNV commented 1 week ago

Could we get OpenTelemetry supported as a logger?

theogravity commented 1 week ago

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.

BryanHuntNV commented 1 week ago

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.

theogravity commented 1 week ago

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 commented 1 week ago

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.

BryanHuntNV commented 1 week ago

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

BryanHuntNV commented 1 week ago

I'd be ok closing the request.

theogravity commented 1 week ago

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 commented 1 week ago

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.

BryanHuntNV commented 1 week ago

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

BryanHuntNV commented 1 week ago

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

theogravity commented 1 week ago

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 commented 1 week ago

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 commented 1 week ago

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!