Add event hooks to execute code (like forwarding logs to an external service) #2669
-
Perhaps there is already a way to do this that I'm not aware of. Basically, what I would like to do is have a custom layer that can send off http requests to an external logging service like paper trail. As far as I can tell, the only way to accomplish this currently is to hack |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
That being said, I don't really recommend sending logs from within the application if you can avoid it—I think you're significantly better off writing logs to |
Beta Was this translation helpful? Give feedback.
tracing
generally assumes that methods on layers are synchronous, and therefore, free to call from an async context without worrying about blocking. While you are technically correct about changingformat_event
to send logs through an MSPC channel to a Tokio task, we offer two, substantially more paved paths to tackle this issue:MakeWriter
that sends the formatted message over an MSPC channel. Note thattracing-appender
is basically this, except it sends logs to a background thread, not a task.MakeWriter
isn't sufficient for whatever reason, writing your own layer is a decently lightweight option! For a guide, I'd take a look at this blog post: https://burgers.io/…