grafana / pyroscope

Continuous Profiling Platform. Debug performance issues down to a single line of code
https://grafana.com/oss/pyroscope/
GNU Affero General Public License v3.0
10.13k stars 614 forks source link

feat: k6 middleware #3580

Closed bryanhuhta closed 1 month ago

bryanhuhta commented 2 months ago

This is a continuation on work done in collaboration with the k6 team. This PR adds a new configuration option to Pyroscope

-self-profiling.use-k6-middleware
      Read k6 labels from request headers and set them as dynamic profile tags.

which enables an http middleware to tag profiles with k6-specific labels parsed from the request baggage. By default this is disabled.

Go SDK PR: https://github.com/grafana/pyroscope-go/pull/99 k6 PR: https://github.com/grafana/grafana-k6-app/pull/1151

kolesnikovae commented 2 months ago

How are these labels being propagated down the communication stream?

bryanhuhta commented 1 month ago

How are these labels being propagated down the communication stream?

😅 I missed that critical part. I made a few more changes, part of them are dependent on this https://github.com/grafana/pyroscope-go/pull/131.

In https://github.com/grafana/pyroscope/pull/3580/commits/c7940449419ff642343e6778b82a672397237bfc, I added a mechanism to propagate baggage found in the context as an http header when making a request. This should send the baggage all the way down the call chain when resolving a query.

In the pryoscope-go PR, I modified the middleware to add the OTEL baggage to the request context if it didn't already exist.

With these two changes, any incoming baggage will get read, labeled, and propagated along network calls. Of course, if a service doesn't have self_profiling.use_k6_middleware enabled, the baggage will stop being propagated.