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