krakend / krakend-otel

KrakenD component for OpenTelemetry
Apache License 2.0
8 stars 10 forks source link

Support sending OTEL metrics and spans from KrakenD plugins #21

Open adigiorgi-clickup opened 5 months ago

adigiorgi-clickup commented 5 months ago

Hi! I have a request modifier plugin that uses go-redis, and I'd like to instrument it via https://pkg.go.dev/github.com/redis/go-redis/extra/redisotel/v9.

To be able to send custom metrics and spans from a plugin, I need access to the OTEL meter and tracer providers, but AFAIK krakend-otel never calls https://pkg.go.dev/go.opentelemetry.io/otel#SetMeterProvider and https://pkg.go.dev/go.opentelemetry.io/otel#SetTracerProvider, which means the only way to get them from a plugin is to import github.com/krakend/krakend-otel/state and call state.GlobalState().

This works, but I think it would be better if plugins didn't have to depend on krakend-otel directly 😄

I can prepare a PR to make these calls in https://github.com/krakend/krakend-otel/blob/main/state/global.go, if you want. Thanks!

rassmate commented 5 months ago

Good suggestion! We would also like to use this feature. We have hijacked the metrics call to achieve this but this approach would be way better.

I've prepared a different pr for adding custom labels to already created metrics but I think it is not appropriate in your case.

But it is in the same area of customizing metrics so it would be good to do the above!