pyro.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package common
  2. import (
  3. "os"
  4. "runtime"
  5. "github.com/grafana/pyroscope-go"
  6. )
  7. func StartPyroScope() error {
  8. pyroscopeUrl := os.Getenv("PYROSCOPE_URL")
  9. if pyroscopeUrl == "" {
  10. return nil
  11. }
  12. // These 2 lines are only required if you're using mutex or block profiling
  13. // Read the explanation below for how to set these rates:
  14. runtime.SetMutexProfileFraction(5)
  15. runtime.SetBlockProfileRate(5)
  16. _, err := pyroscope.Start(pyroscope.Config{
  17. ApplicationName: SystemName,
  18. ServerAddress: pyroscopeUrl,
  19. Logger: nil,
  20. Tags: map[string]string{"hostname": GetEnvOrDefaultString("HOSTNAME", "new-api")},
  21. ProfileTypes: []pyroscope.ProfileType{
  22. pyroscope.ProfileCPU,
  23. pyroscope.ProfileAllocObjects,
  24. pyroscope.ProfileAllocSpace,
  25. pyroscope.ProfileInuseObjects,
  26. pyroscope.ProfileInuseSpace,
  27. pyroscope.ProfileGoroutines,
  28. pyroscope.ProfileMutexCount,
  29. pyroscope.ProfileMutexDuration,
  30. pyroscope.ProfileBlockCount,
  31. pyroscope.ProfileBlockDuration,
  32. },
  33. })
  34. if err != nil {
  35. return err
  36. }
  37. return nil
  38. }