mtth / tracing

Distributed tracing
https://hackage.haskell.org/package/tracing
BSD 3-Clause "New" or "Revised" License
24 stars 11 forks source link

Provide better support for a "root-producer-span"? #11

Closed alaendle closed 3 years ago

alaendle commented 3 years ago

If I have some software that's main purpose is to generate and ingest events, I believe something like a "root-producer-span" is useful. However implementing this is already possible with the current state of the library:

TC.rootSpanWith (ZPK.addTag "z.k" "PRODUCER") TC.alwaysSampled name $ do
      spn <- TC.activeSpan
      error "use B3 here" $ fmap b3FromSpan spn

The downside is that you need to copy b3FromSpan (also implies parentID) and use the 'magic' values "z.k" and "PRODUCER". So I wonder if it is worth to provide a convenience function in the library? Your thoughts? Could an additional function be an improvement? Or maybe it's better to just expose more internals like b3FromSpan so that client code is empowered to directly implement such things?

mtth commented 3 years ago

Sounds like a reasonable thing to support. How about adding a function similar to:

producer = addTag "z.k" "PRODUCER"

Can you elaborate on the downside of b3FromSpan? AFAICT the span is copied as-is, no parent/child relationship is added.

alaendle commented 3 years ago

I'm still not sure if this corner-case justifies an expansion of the API. Nonetheless the linked PR adds an addProducerTag method (that is needed to hide magic values) and exports the b3FromSpan method (that is needed by the client to extract and forward the b3 identifier). I guess that this is the minimal change that is necessary to support the creation of a "root producer". Another way would be the addition of explicit rootProducerSpan/rootProducerSpanWith methods.

Regarding the b3FromSpan downside I think we talked past each other. The only downside of this function was that it is needed to extract and forward the b3 information, but it wasn't exported by the module.

As always, just let me know what you think 😃

mtth commented 3 years ago

Fixed in #15 and released as 0.0.7.1.