-
Notifications
You must be signed in to change notification settings - Fork 25
/
cstrace.go
33 lines (25 loc) · 1013 Bytes
/
cstrace.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
package cstrace
import (
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/label"
"go.opentelemetry.io/otel/trace"
)
var ErrorKey = label.Key("error")
// Status codes for use with Span.SetStatus. These correspond to the status
// codes used by gRPC defined here: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
// Status if there is an error, it sets the error code "unknown" with the error
// string as span status otherwise status ok.
func Status(span trace.Span, err error, msg string) {
if err == nil {
span.SetStatus(codes.Ok, msg)
return
}
span.SetStatus(codes.Error, msg)
span.SetAttributes(ErrorKey.String(err.Error()))
}
// StatusErrorWithCode sets a custom code with an error.
// go.opencensus.io/trace/status_codes.go. These correspond to the status codes
// used by gRPC defined here:
// https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
type Tracer = trace.Tracer
var NewNoopTracerProvider = trace.NewNoopTracerProvider