marcdel / open_telemetry_decorator

A function decorator for OpenTelemetry traces.
https://hex.pm/packages/open_telemetry_decorator
38 stars 21 forks source link

Feature Request: `with_event` decorator #147

Open ktayah opened 4 months ago

ktayah commented 4 months ago

What are the thoughts on adding a new decorator alongside the main with_span decorator that handles adding a span event?

In our use of OpenTelemetry we noticed that we have some functions that we would like to trace, but only when it is called while in an already started span. We did not want to create a new span and introduce noise (in our situation). A with_event or with_span_event decorator that utilizes some of the same attribute parsing logic seems useful and makes sense to add into this library. I wouldn't mind implementing this as well.

Thoughts?

marcdel commented 3 months ago

Hey @ktayah I've made changes to o11y to support this feature and am workin on it now. The assumption I'm making (since this will wrap a function) is that the event should only be emitted if the function completes successfully. Does that seem reasonable?

ktayah commented 2 months ago

@marcdel My thought was it emits when the function gets called. I imagine one could use the metadata from this event to help them debug their code. I don't have super strong feelings about this, maybe this is something the client of the library can decide.