forked from remind101/newrelic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
newrelic.go
57 lines (46 loc) · 1.6 KB
/
newrelic.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
package newrelic
import (
"errors"
"time"
)
var ErrTxAlreadyStarted = errors.New("transaction already started")
type TransactionType int
const (
WebTransaction TransactionType = iota
OtherTransaction
)
// TxTracer handles transaction tracing.
type TxTracer interface {
BeginTransaction() (int64, error)
EndTransaction(txnID int64) error
SetTransactionName(txnID int64, name string) error
SetTransactionRequestURL(txnID int64, url string) error
SetTransactionType(txnID int64, txnType TransactionType) error
SetTransactionCategory(txnID int64, category string) error
BeginGenericSegment(txnID int64, parentID int64, name string) (int64, error)
BeginDatastoreSegment(txnID int64, parentID int64, table string, operation string, sql string, rollupName string) (int64, error)
BeginExternalSegment(txnID int64, parentID int64, host string, name string) (int64, error)
EndSegment(txnID int64, parentID int64) error
}
// TxReporter reports the first error that occured during a transaction.
type TxReporter interface {
ReportError(txnID int64, exceptionType, errorMessage, stackTrace, stackFrameDelim string) (int, error)
}
// Recorder handles metrics recording.
type Recorder interface {
Interval() time.Duration
Record() error
}
// RecordMetrics records metrics with the default metric recorder.
func RecordMetrics(interval time.Duration) {
RecordMetricsWithRecorder(newRecorder(interval))
}
// RecordMetricsWithRecorder records metrics with the given recorder.
func RecordMetricsWithRecorder(r Recorder) {
ticker := time.NewTicker(r.Interval())
go func() {
for _ = range ticker.C {
r.Record()
}
}()
}