1
0

startup.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package sessions
  2. import (
  3. "context"
  4. "net/http"
  5. "os"
  6. "github.com/bugsnag/panicwrap"
  7. )
  8. // SendStartupSession is called by Bugsnag on startup, which will send a
  9. // session to Bugsnag and return a context to represent the session of the main
  10. // goroutine. This is the session associated with any fatal panics that are
  11. // caught by panicwrap.
  12. func SendStartupSession(config *SessionTrackingConfiguration) context.Context {
  13. ctx := context.Background()
  14. session := newSession()
  15. if !config.IsAutoCaptureSessions() || isApplicationProcess() {
  16. return ctx
  17. }
  18. publisher := &publisher{
  19. config: config,
  20. client: &http.Client{Transport: config.Transport},
  21. }
  22. go publisher.publish([]*Session{session})
  23. return context.WithValue(ctx, contextSessionKey, session)
  24. }
  25. // Checks to see if this is the application process, as opposed to the process
  26. // that monitors for panics
  27. func isApplicationProcess() bool {
  28. // Application process is run first, and this will only have been set when
  29. // the monitoring process runs
  30. return "" == os.Getenv(panicwrap.DEFAULT_COOKIE_KEY)
  31. }