@@ -2,12 +2,14 @@ package traceandtracego
22
33import (
44 "io"
5+ "log"
56 logger "log"
67 "net/http"
78 "os"
89 "strconv"
910
1011 opentracing "github.com/opentracing/opentracing-go"
12+ "github.com/opentracing/opentracing-go/ext"
1113 spanLog "github.com/opentracing/opentracing-go/log"
1214 jaeger "github.com/uber/jaeger-client-go"
1315 jaegercfg "github.com/uber/jaeger-client-go/config"
@@ -96,6 +98,84 @@ func AddTracer(svcName string,
9698 spanLog .String (k , v ),
9799 )
98100 }
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+
99179 //注入span (用于传递)
100180 if err := opentracing .GlobalTracer ().Inject (
101181 sp .Context (),
0 commit comments