@@ -2,12 +2,14 @@ package traceandtracego
2
2
3
3
import (
4
4
"io"
5
+ "log"
5
6
logger "log"
6
7
"net/http"
7
8
"os"
8
9
"strconv"
9
10
10
11
opentracing "github.com/opentracing/opentracing-go"
12
+ "github.com/opentracing/opentracing-go/ext"
11
13
spanLog "github.com/opentracing/opentracing-go/log"
12
14
jaeger "github.com/uber/jaeger-client-go"
13
15
jaegercfg "github.com/uber/jaeger-client-go/config"
@@ -96,6 +98,84 @@ func AddTracer(svcName string,
96
98
spanLog .String (k , v ),
97
99
)
98
100
}
101
+
102
+ // setting ext
103
+ if _ , exist := tags ["spanKind" ]; exist {
104
+ // enum: client,server,producer,consumer
105
+ ext .SpanKind .Set (sp , ext .SpanKindEnum (tags ["spanKind" ]))
106
+ }
107
+
108
+ if _ , exist := tags ["component" ]; exist {
109
+ ext .Component .Set (sp , tags ["component" ])
110
+ }
111
+
112
+ if _ , exist := tags ["samplingPriority" ]; exist {
113
+ spUint , err := strconv .Atoi (tags ["samplingPriority" ])
114
+ if err != nil {
115
+ log .Fatalf ("sampling priority strconv error %v" , err )
116
+ }
117
+ ext .SamplingPriority .Set (sp , uint16 (spUint ))
118
+ }
119
+
120
+ if _ , exist := tags ["peerService" ]; exist {
121
+ ext .PeerService .Set (sp , tags ["peerService" ])
122
+ }
123
+
124
+ if _ , exist := tags ["peerAddress" ]; exist {
125
+ ext .PeerAddress .Set (sp , tags ["peerAddress" ])
126
+ }
127
+
128
+ if _ , exist := tags ["peerHostname" ]; exist {
129
+ ext .PeerHostname .Set (sp , tags ["peerHostname" ])
130
+ }
131
+
132
+ if _ , exist := tags ["peerIpv4" ]; exist {
133
+ pi , _ := strconv .ParseUint (tags ["peerIpv4" ], 10 , 32 )
134
+ ext .PeerHostIPv4 .Set (sp , uint32 (pi ))
135
+ }
136
+
137
+ if _ , exist := tags ["peerIpv6" ]; exist {
138
+ ext .PeerHostIPv6 .Set (sp , tags ["peerIpv6" ])
139
+ }
140
+
141
+ if _ , exist := tags ["peerPort" ]; exist {
142
+ ppInt , _ := strconv .Atoi (tags ["peerPort" ])
143
+ ext .PeerPort .Set (sp , uint16 (ppInt ))
144
+ }
145
+
146
+ if _ , exist := tags ["httpUrl" ]; exist {
147
+ ext .HTTPUrl .Set (sp , tags ["httpUrl" ])
148
+ }
149
+
150
+ if _ , exist := tags ["httpStatusCode" ]; exist {
151
+ hscInt , _ := strconv .Atoi (tags ["httpStatusCode" ])
152
+ ext .HTTPStatusCode .Set (sp , uint16 (hscInt ))
153
+ }
154
+
155
+ if _ , exist := tags ["dbStatement" ]; exist {
156
+ ext .DBStatement .Set (sp , tags ["dbStatement" ])
157
+ }
158
+
159
+ if _ , exist := tags ["dbInstance" ]; exist {
160
+ ext .DBInstance .Set (sp , tags ["dbInstance" ])
161
+ }
162
+
163
+ if _ , exist := tags ["dbType" ]; exist {
164
+ ext .DBType .Set (sp , tags ["dbType" ])
165
+ }
166
+
167
+ if _ , exist := tags ["httpMethod" ]; exist {
168
+ ext .HTTPMethod .Set (sp , tags ["httpMethod" ])
169
+ }
170
+
171
+ if _ , exist := tags ["dbUser" ]; exist {
172
+ ext .DBUser .Set (sp , tags ["dbUser" ])
173
+ }
174
+
175
+ if _ , exist := tags ["messageBusDestination" ]; exist {
176
+ ext .MessageBusDestination .Set (sp , tags ["messageBusDestination" ])
177
+ }
178
+
99
179
//注入span (用于传递)
100
180
if err := opentracing .GlobalTracer ().Inject (
101
181
sp .Context (),
0 commit comments