2

My api is protected via jwt, is it possible to specify a jwt token when fetch profile via go tool pprof ?

Currently, I have to config jwt middleware to bypass the /debug/pprof routes.

Eric
  • 22,183
  • 20
  • 145
  • 196

1 Answers1

2

I couldn't find a way to pass a token via go tool pprof directly, but due to the fact that you can use curl to fetch the profile, there is a simple workaround:

$ curl -o profile.out https://host/debug/pprof -H 'X-Authorization: $TOKEN'
$ go tool pprof profile.out
Cyprian
  • 11,174
  • 1
  • 48
  • 45
  • Cool, this works. BTW, the request will wait 30 seconds by default while the profile is being generated. `wget` works similarly. – Eric Sep 12 '22 at 17:50
  • 1
    Yes, but you can control the time of collecting data through "seconds" parameter, eg.: to reduce the time to 5 seconds: `curl -o profile.out https://host/debug/pprof?seconds=5 -X 'X-Authorization: $TOKEN'` – Cyprian Sep 12 '22 at 18:41
  • 1
    The idea works but you should specify the header with the `-H` flag to `curl` not `-X`. Like this: `$ curl -o profile.out https://host/debug/pprof -H 'X-Authorization: $TOKEN'` – ezileli Feb 11 '23 at 14:36
  • @ezileli you're absolutely right, thanks for pointing out – Cyprian Feb 20 '23 at 08:35