Skip to content

Add event hooks to execute code (like forwarding logs to an external service) #2669

Answered by davidbarsky
ewoolsey asked this question in Q&A
Discussion options

You must be logged in to vote

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 changing format_event to send logs through an MSPC channel to a Tokio task, we offer two, substantially more paved paths to tackle this issue:

  • Implement your own MakeWriter that sends the formatted message over an MSPC channel. Note that tracing-appender is basically this, except it sends logs to a background thread, not a task.
  • If 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/…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@ewoolsey
Comment options

@ewoolsey
Comment options

Answer selected by hawkw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2665 on July 25, 2023 14:23.