launchdarkly / go-server-sdk

LaunchDarkly Server-side SDK for Go
Other
41 stars 18 forks source link

context.Context and/or evaluation hooks #63

Closed nelzkiddom closed 4 months ago

nelzkiddom commented 2 years ago

Is your feature request related to a problem? Please describe. I would like my feature flag evaluations to participate in my telemetry collection

Describe the solution you'd like I'd like to see new XXXVariation and XXXVariationDetails functions that take a context.Context as a first parameter. Then, also the ability to configure a hook/"observable" style function that takes the context.Context and the ldreason.EvaluationDetail so that I can emit this information to my telemetry system.

Describe alternatives you've considered I've thought about writing an extension of the SDK to provide context-aware extensions, but that just seems like I'd always be chasing the current implementation, and it is probably in LD's interests to provide flexible post-evaluation hooks, possibly with provided default hook implementations that work with OpenTelemetry.

bwoskow-ld commented 2 years ago

Hi @nelzkiddom,

Thanks for the suggestion! We've actually already had internal discussions about the idea of adding evaluation hooks to our suite of SDKs. The main use case we've considered is to be able to accumulate flag metrics for observability purposes. Unfortunately we haven't yet made progress on implementing this feature in our SDKs.

In the meantime, one thing you could consider doing is implementing a wrapper layer around the LaunchDarkly SDK. The wrapper would accept a context and would just decorate the LaunchDarkly SDK while also accumulating data into the context. As long as you keep the wrapper lightweight and minimal then I don't expect it to cause much extra lift to your team, but that's up to you.

nelzkiddom commented 2 years ago

FYI, I tried my hand at a first pass, will probably serve us for now: https://github.com/nelz9999/goldhook

cwaldren-ld commented 4 months ago

Hi @nelzkiddom , this is actually supported now using the new ldotel package in this repo.