forked from reyhanfahlevi/pkg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
type.go
92 lines (73 loc) · 1.6 KB
/
type.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package tracer
import (
"context"
"net/http"
"github.com/ennobelprakoso/pkg/go/tracer/nr"
)
// Config config
type Config struct {
Appname string
IsEnableJaeger bool
IsEnableNewRelic bool
NewRelic NewRelicConfig
}
// NewRelicConfig is a newrelic's config
type NewRelicConfig struct {
SecretKey string
LogLevel string
}
// Transaction bg transaction - at http handlers
type Transaction struct {
ctx context.Context
// md contains the metadata for a transaction
md http.Header
}
// Finish finishing a span / transaction
func (s *Transaction) Finish(err ...*error) {
if len(err) > 0 && *err[0] != nil {
_ = nr.Error(s.ctx, *err[0]) // notice error
}
nr.EndTransaction(s.ctx)
}
type ISegment interface {
End()
}
// Span bg at funcs
type Span struct {
ctx context.Context
nrSegment ISegment
// md contains the metadata for a transaction
md http.Header
}
func (s *Span) Finish() {
if s.nrSegment != nil {
s.nrSegment.End()
}
}
type DBConInfo struct {
Name string
Host string
Port string
}
type sqlExtraArgs struct {
DBConInfo
Query string
}
// Options is options for span
type Options struct {
SpanType int
ExtraArgs interface{}
ExtraParam map[string]interface{}
}
const (
// SpanTypeSQL is span as SQL span
SpanTypeSQL int = 101
// SpanTypeRedis is span as Redis call span
SpanTypeRedis int = 102
// SpanTypeHTTPCall is span as HTTP call span
SpanTypeHTTPCall int = 103
// SpanTypeNSQPublish is a span as Message Broker NSQ Publish
SpanTypeNSQPublish int = 104
// SpanTypeElasticsearch is span as Elasticsarch call span
SpanTypeElasticsearch int = 105
)