Repository navigation
Expand file tree
/
Copy pathdef.go
More file actions
333 lines (272 loc) · 9.11 KB
/
Copy pathdef.go
File metadata and controls
333 lines (272 loc) · 9.11 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
package trace
import (
"context"
"sync/atomic"
_ "unsafe"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/propagation"
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
"go.opentelemetry.io/otel/trace"
)
const (
DEBUG Severity = iota // severity : 0
INFO // severity : 1
NOTICE // severity : 2
WARN // severity : 3
ERR // severity : 4
CRIT // severity : 5
ALERT // severity : 6
EMERG // severity : 7
__severity_minimum__ = DEBUG
__severity_maximum__ = EMERG
__severity_none__ = -1
NONE Severity = -1
)
const (
__STATUS_CODE_ERROR = "error"
PASS ReplyCode = ReplyCode("pass")
FAIL ReplyCode = ReplyCode("fail")
UNSET ReplyCode = ReplyCode("")
)
const (
__ATTR_EVENT attribute.Key = "event"
__ATTR_EVENT_MESSAGE attribute.Key = "event.message"
__ATTR_EVENT_SEVERITY attribute.Key = "event.severity"
__ATTR_EVENT_STATUS_CODE attribute.Key = "event.status_code"
__ATTR_EVENT_STATUS_DESCRIPTION attribute.Key = "event.status_description"
__ATTR_ERROR attribute.Key = "error"
__ATTR_ARGV attribute.Key = "argv"
__ATTR_REPLY attribute.Key = "reply"
__ATTR_VARS attribute.Key = "vars"
__ATTR_ENVIRONMENT attribute.Key = "environment"
__ATTR_OS attribute.Key = "os"
__ATTR_PID attribute.Key = "pid"
__ATTR_SIGNATURE attribute.Key = "signature"
__ATTR_VERSION attribute.Key = "version"
__ATTR_FACILITY attribute.Key = "facility"
__ATTR_SERVICE_NAME attribute.Key = semconv.ServiceNameKey
__ATTR_HTTP_METHOD attribute.Key = "http.method"
__ATTR_HTTP_REQUEST attribute.Key = "http.request"
__ATTR_HTTP_REQUEST_PATH attribute.Key = "http.request_path"
__ATTR_HTTP_RESPONSE attribute.Key = "http.response"
__ATTR_HTTP_STATUS_CODE attribute.Key = "http.status_code"
__ATTR_HTTP_USER_AGENT attribute.Key = "http.user_agent"
__ATTR_BROKER_IP attribute.Key = "broker_ip"
__ATTR_CONSUMER_GROUP attribute.Key = "consumer_group"
__ATTR_MESSAGE_ID attribute.Key = "message_id"
__ATTR_TOPIC attribute.Key = "topic"
__ATTR_STREAM attribute.Key = "stream"
)
const (
// SpanKindUnspecified is an unspecified SpanKind and is not a valid
// SpanKind. SpanKindUnspecified should be replaced with SpanKindInternal
// if it is received.
SpanKindUnspecified = trace.SpanKindUnspecified
// SpanKindInternal is a SpanKind for a Span that represents an internal
// operation within an application.
SpanKindInternal = trace.SpanKindInternal
// SpanKindServer is a SpanKind for a Span that represents the operation
// of handling a request from a client.
SpanKindServer = trace.SpanKindServer
// SpanKindClient is a SpanKind for a Span that represents the operation
// of client making a request to a server.
SpanKindClient = trace.SpanKindClient
// SpanKindProducer is a SpanKind for a Span that represents the operation
// of a producer sending a message to a message broker. Unlike
// SpanKindClient and SpanKindServer, there is often no direct
// relationship between this kind of Span and a SpanKindConsumer kind. A
// SpanKindProducer Span will end once the message is accepted by the
// message broker which might not overlap with the processing of that
// message.
SpanKindProducer = trace.SpanKindProducer
// SpanKindConsumer is a SpanKind for a Span that represents the operation
// of a consumer receiving a message from a message broker. Like
// SpanKindProducer Spans, there is often no direct relationship between
// this Span and the Span that produced the message.
SpanKindConsumer = trace.SpanKindConsumer
)
const (
__CONTEXT_SEVERITY_SPAN_KEY ctxSpanKeyType = 0
// FlagsSampled is a bitmask with the sampled bit set. A SpanContext
// with the sampling bit set means the span is sampled.
FlagsSampled = trace.FlagsSampled
)
type (
ctxSpanKeyType int
KeyValue = attribute.KeyValue
Key = attribute.Key
SpanKind = trace.SpanKind
Link = trace.Link
TraceID = trace.TraceID
SpanID = trace.SpanID
TraceFlags = trace.TraceFlags
ReplyCode string
TracerTagMarshaler interface {
MarshalTracerTag(builder *TracerTagBuilder) error
}
SpanExtractor interface {
Extract(ctx context.Context) *SeveritySpan
}
SpanInjector interface {
Inject(ctx context.Context, span *SeveritySpan) context.Context
}
ValueContext interface {
context.Context
SetValue(key, value any)
}
tracerProviderHolder struct {
v *SeverityTracerProvider
}
spanExtractorHolder struct {
v SpanExtractor
}
spanInjectorHolder struct {
v SpanInjector
}
)
var (
__InvalidKeyValue = attribute.Bool("", false)
globalTracerProvider = defaultTracerProviderValue()
globalSpanExtractor = defaultSpanExtractor()
globalSpanInjector = defaultSpanInjector()
noopSpan = trace.SpanFromContext(context.Background())
)
//go:linkname WithStackTrace go.opentelemetry.io/otel/trace.WithStackTrace
func WithStackTrace(b bool) trace.SpanEndEventOption
//go:linkname WithLinks go.opentelemetry.io/otel/trace.WithLinks
func WithLinks(links ...Link) trace.SpanStartOption
//go:linkname WithNewRoot go.opentelemetry.io/otel/trace.WithNewRoot
func WithNewRoot() trace.SpanStartOption
//go:linkname WithSpanKind go.opentelemetry.io/otel/trace.WithSpanKind
func WithSpanKind(kind SpanKind) trace.SpanStartOption
//go:linkname WithInstrumentationVersion go.opentelemetry.io/otel/trace.WithInstrumentationVersion
func WithInstrumentationVersion(version string) trace.TracerOption
//go:linkname WithSchemaURL go.opentelemetry.io/otel/trace.WithSchemaURL
func WithSchemaURL(schemaURL string) trace.TracerOption
//go:linkname GetTextMapPropagator go.opentelemetry.io/otel.GetTextMapPropagator
func GetTextMapPropagator() propagation.TextMapPropagator
//go:linkname SetTextMapPropagator go.opentelemetry.io/otel.SetTextMapPropagator
func SetTextMapPropagator(propagator propagation.TextMapPropagator)
func GetTracerProvider() *SeverityTracerProvider {
return globalTracerProvider.Load().(tracerProviderHolder).v
}
func SetTracerProvider(tp *SeverityTracerProvider) {
current := GetTracerProvider()
if current != tp {
globalTracerProvider.Store(tracerProviderHolder{
v: tp,
})
}
}
func GetSpanExtractor() SpanExtractor {
return globalSpanExtractor.Load().(spanExtractorHolder).v
}
func SetSpanExtractor(extractor SpanExtractor) {
globalSpanExtractor.Store(spanExtractorHolder{
v: extractor,
})
}
func GetSpanInjector() SpanInjector {
return globalSpanInjector.Load().(spanInjectorHolder).v
}
func SetSpanInjector(injector SpanInjector) {
globalSpanInjector.Store(spanInjectorHolder{
v: injector,
})
}
func Tracer(name string, opts ...trace.TracerOption) *SeverityTracer {
return GetTracerProvider().Tracer(name, opts...)
}
func IsOtelNoopSpan(span trace.Span) bool {
return span == noopSpan
}
func IsNoopSeveritySpan(span *SeveritySpan) bool {
return IsOtelNoopSpan(span.otelSpan())
}
func SpanToContext(ctx context.Context, span *SeveritySpan) context.Context {
if carrier, ok := ctx.(ValueContext); ok {
carrier.SetValue(__CONTEXT_SEVERITY_SPAN_KEY, span)
return ctx
}
var globalSpanInjector = GetSpanInjector()
return globalSpanInjector.Inject(ctx, span)
}
func ContextWithSpan(parent context.Context, span *SeveritySpan) context.Context {
return context.WithValue(parent, __CONTEXT_SEVERITY_SPAN_KEY, span)
}
func SpanFromContext(ctx context.Context, extractors ...SpanExtractor) *SeveritySpan {
var span *SeveritySpan
// extract span from specified extractors
for _, v := range extractors {
span = v.Extract(ctx)
if span != nil {
return span
}
}
// extract span form global
var globalSpanExtractor = GetSpanExtractor()
span = globalSpanExtractor.Extract(ctx)
if span != nil {
return span
}
// extract span from ctx
{
v := ctx.Value(__CONTEXT_SEVERITY_SPAN_KEY)
if v != nil {
if span, ok := v.(*SeveritySpan); ok {
return span
}
}
}
// extract span form otel trace.SpanFromContext()
return &SeveritySpan{
span: trace.SpanFromContext(ctx),
ctx: ctx,
events: make([]SpanEvent, 0, 4),
}
}
func CreateSeverityTracerProvider(provider trace.TracerProvider) *SeverityTracerProvider {
return &SeverityTracerProvider{
provider: provider,
}
}
func CreateSeverityTracer(tr trace.Tracer) *SeverityTracer {
return &SeverityTracer{
tr: tr,
}
}
func CreateSeveritySpan(ctx context.Context) *SeveritySpan {
if ctx == nil {
ctx = context.Background()
}
span := trace.SpanFromContext(ctx)
return &SeveritySpan{
span: span,
ctx: ctx,
events: make([]SpanEvent, 0, 4),
}
}
func defaultTracerProviderValue() *atomic.Value {
v := &atomic.Value{}
v.Store(tracerProviderHolder{
v: &SeverityTracerProvider{
provider: otel.GetTracerProvider(),
},
})
return v
}
func defaultSpanExtractor() *atomic.Value {
v := &atomic.Value{}
v.Store(spanExtractorHolder{
v: NewCompositeSpanExtractor(),
})
return v
}
func defaultSpanInjector() *atomic.Value {
v := &atomic.Value{}
v.Store(spanInjectorHolder{
v: noopSpanInjectorInstance,
})
return v
}