-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
transport.go
58 lines (48 loc) · 1.55 KB
/
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
57
58
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package sentryexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/sentryexporter"
import (
"context"
"time"
"github.com/getsentry/sentry-go"
)
// transport is used by exporter to send events to Sentry
type transport interface {
SendEvents(events []*sentry.Event)
Configure(options sentry.ClientOptions)
Flush(ctx context.Context) bool
}
type sentryTransport struct {
httpTransport *sentry.HTTPTransport
}
// newSentryTransport returns a new pre-configured instance of sentryTransport.
func newSentryTransport() *sentryTransport {
transport := sentryTransport{
httpTransport: sentry.NewHTTPTransport(),
}
return &transport
}
func (t *sentryTransport) Configure(options sentry.ClientOptions) {
t.httpTransport.Configure(options)
}
func (t *sentryTransport) Flush(ctx context.Context) bool {
deadline, ok := ctx.Deadline()
if ok {
return t.httpTransport.Flush(time.Until(deadline))
}
return t.httpTransport.Flush(time.Second)
}
// sendTransactions uses a Sentry HTTPTransport to send transaction events to Sentry
func (t *sentryTransport) SendEvents(transactions []*sentry.Event) {
bufferCounter := 0
for _, transaction := range transactions {
// We should flush all events when we send transactions equal to the transport
// buffer size so we don't drop transactions.
if bufferCounter == t.httpTransport.BufferSize {
t.httpTransport.Flush(time.Second)
bufferCounter = 0
}
t.httpTransport.SendEvent(transaction)
bufferCounter++
}
}