Closed paymog closed 8 months ago
IIUC, there's four distinct requests here:
Runtime.install
;name: activity
or name: workflow
).@paymog Anything missing?
I guess so? I'm still wrapping my head around how logging works in temporal. My understanding is that if Runtime.install
supported Pino style logging (item 3) then items 1, 2, and 4 would naturally fall into place because of how the Runtime logger is accessed in workflows and activities.
If Runtime.install
doesn't work for both Workflows and Activities then yes, items 1, 2, and 3 are all separate. Item 4 is super low priority in my opinion because Pino supports child loggers and because the "location" of the log (workflow vs activity) can be inferred from the other metadata/context on the log that gets injected by the worker.
Let me first respond to the feature request.
We discussed this with the team, and we strongly feel that the SDK itself must remain logger-framework agnostic. I can see how the SDK's Logger
interface seems to adhere to Winston's style (same way of naming log levels functions, same order of arguments), but this is pretty much coincidental and only true at a shallow level (e.g. there is no actual import or dependency on Winston; only the simplest call signature is supported; no support for many winston-specific log levels; etc).
The SDK already provides a way to funnel all log messages emitted from Workflow code, Activity code, by the SDK itself and by the underlying Core SDK, through a single upstream logger (i.e. Runtime.logger
). Relaying log messages emitted by any of these subsystems through a specific logging library simply require registration of a log adaptor on Runtime.logger
. Note that even connecting to a Winston upstream logger requires such an adaptor. There's little we can do in the SDK itself to make this part easier while remaining log-framework agnostic.
Regarding the logger interface exposed to activities and workflows, again, there's not that much we can do within the SDK itself to simplify usage of alternate logging APIs. It is simply not possible to expose the logger object directly to workflow code, due to the fact that workflows executes in a sandboxed environment and on a different worker thread. As for exposing your custom logger object directly to activity code, this would technically be possible (actually, it is, already), but then it would be impossible for the SDK to automatically inject contextual metadata on log messages and to automatically emit lifecycle tracing messages. I can't see how that would be an improvement.
Regarding the code you shared on how you connected to Pino, it could have been much simpler.
Here are a few specific things you could have done differently:
ActivityInboundLogInterceptor
(by the way, both ActivityInboundLogInterceptor
and appendDefaultInterceptors
are deprecated since 1.9.0).fatal
log level, or any other custom level, the ingress adaptor could copy the log level name to a metadata field; then, the outgress adaptor could look for that field, and if present, call the corresponding log functions on your upstream Pino logger.Runtime.logger
, you could have used the SDK provided DefaultLogger
class, and then, only provide the generic log
function.I will try to come up with a sample for this.
must remain logger-framework agnostic
Totally agree!
but this is pretty much coincidental and only true at a shallow level
Gotcha
there's not that much we can do within the SDK itself to simplify usage of alternate logging APIs
hmm, can you make two interfaces and use a type union for the base logger?
I will try to come up with a sample for this.
I would love that, thank you!
Is your feature request related to a problem? Please describe.
Support Pino as a logging framework with
Runtime.install
Describe the solution you'd like
Currently, the
Logger
interface is Winston-like. This makes it difficult for teams that use Pino to have a familiar interface when doing workflow AND activity logging. Right now we're forced to eitherLoggerSinks
(which seem to be deprecated) for Pino workflow loggingAdditional context
I've done quite a bit of hacking to get Pino logging for workflows working. Here's what I've done (reduced a bit to make it more legible)