forked from SierraSoftworks/sentry-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp_gae_transport.go
56 lines (43 loc) · 969 Bytes
/
http_gae_transport.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package sentry
import (
"context"
"github.com/pkg/errors"
"google.golang.org/appengine/urlfetch"
)
const (
gaeContextClass = "sentry-go.gae-context"
)
type gaeTransport struct {
*httpTransport
}
func NewGAETransport() Transport {
t := newHTTPTransport()
httpT := t.(*httpTransport)
return &gaeTransport{httpT}
}
func (t *gaeTransport) Send(dsn string, p Packet) error {
pp := *p.(*packet)
ctxOpt, ok := pp[gaeContextClass]
if !ok {
return errors.New("missing Google AppEngine context")
}
opt, ok := ctxOpt.(*gaeContextOption)
if !ok {
return errors.New("invalid GAEContext option")
}
delete(pp, gaeContextClass)
t.client = urlfetch.Client(opt.ctx)
return t.Send(dsn, &pp)
}
type gaeContextOption struct {
ctx context.Context
}
func (o *gaeContextOption) Class() string {
return gaeContextClass
}
func (o *gaeContextOption) Omit() bool {
return false
}
func GAEContext(ctx context.Context) Option {
return &gaeContextOption{ctx}
}