forked from remind101/newrelic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracer_newrelic_enabled.go
64 lines (58 loc) · 2.11 KB
/
tracer_newrelic_enabled.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
59
60
61
62
63
64
// +build newrelic_enabled
// The new relic agent sdk currently only support linux (https://docs.newrelic.com/docs/agents/agent-sdk/getting-started/new-relic-agent-sdk)
package newrelic
import (
"fmt"
"github.com/remind101/newrelic/sdk"
)
// Init initializes the embedded newrelic agent with the given app name and license key.
func Init(app, key string) {
if _, err := sdk.InitEmbeddedMode(key, app); err != nil {
panic(err)
}
}
// NRTxTracer implements the TxTracer interface. It wraps the newrelic package.
type NRTxTracer struct{}
func (t *NRTxTracer) BeginTransaction() (int64, error) {
return sdk.TransactionBegin()
}
func (t *NRTxTracer) SetTransactionName(txnID int64, name string) error {
_, err := sdk.TransactionSetName(txnID, name)
return err
}
func (t *NRTxTracer) BeginGenericSegment(txnID, parentID int64, name string) (int64, error) {
return sdk.SegmentGenericBegin(txnID, parentID, name)
}
func (t *NRTxTracer) BeginDatastoreSegment(txnID, parentID int64, table, operation, sql, rollupName string) (int64, error) {
return sdk.SegmentDatastoreBegin(txnID, parentID, table, operation, sql, rollupName)
}
func (t *NRTxTracer) BeginExternalSegment(txnID, parentID int64, host, name string) (int64, error) {
return sdk.SegmentExternalBegin(txnID, parentID, host, name)
}
func (t *NRTxTracer) EndSegment(txnID, parentID int64) error {
_, err := sdk.SegmentEnd(txnID, parentID)
return err
}
func (t *NRTxTracer) SetTransactionRequestURL(txnID int64, url string) error {
_, err := sdk.TransactionSetRequestURL(txnID, url)
return err
}
func (t *NRTxTracer) SetTransactionType(txnID int64, txnType TransactionType) (err error) {
switch txnType {
case WebTransaction:
_, err = sdk.TransactionSetTypeWeb(txnID)
case OtherTransaction:
_, err = sdk.TransactionSetTypeOther(txnID)
default:
err = fmt.Errorf("unknown transaction type: %#v", txnType)
}
return err
}
func (t *NRTxTracer) SetTransactionCategory(txnID int64, category string) error {
_, err := sdk.TransactionSetCategory(txnID, category)
return err
}
func (t *NRTxTracer) EndTransaction(txnID int64) error {
_, err := sdk.TransactionEnd(txnID)
return err
}