-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
traceutil.go
65 lines (58 loc) · 1.99 KB
/
traceutil.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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package traceutil // import "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/traceutil"
import (
"encoding/hex"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/ptrace"
)
// SpanKindStr returns a string representation of the SpanKind as it's defined in the proto.
// The function provides old behavior of ptrace.SpanKind.String() to support graceful adoption of
// https://github.com/open-telemetry/opentelemetry-collector/pull/6250.
func SpanKindStr(sk ptrace.SpanKind) string {
switch sk {
case ptrace.SpanKindUnspecified:
return "SPAN_KIND_UNSPECIFIED"
case ptrace.SpanKindInternal:
return "SPAN_KIND_INTERNAL"
case ptrace.SpanKindServer:
return "SPAN_KIND_SERVER"
case ptrace.SpanKindClient:
return "SPAN_KIND_CLIENT"
case ptrace.SpanKindProducer:
return "SPAN_KIND_PRODUCER"
case ptrace.SpanKindConsumer:
return "SPAN_KIND_CONSUMER"
}
return ""
}
// StatusCodeStr returns a string representation of the StatusCode as it's defined in the proto.
// The function provides old behavior of ptrace.StatusCode.String() to support graceful adoption of
// https://github.com/open-telemetry/opentelemetry-collector/pull/6250.
func StatusCodeStr(sk ptrace.StatusCode) string {
switch sk {
case ptrace.StatusCodeUnset:
return "STATUS_CODE_UNSET"
case ptrace.StatusCodeOk:
return "STATUS_CODE_OK"
case ptrace.StatusCodeError:
return "STATUS_CODE_ERROR"
}
return ""
}
// SpanIDToHexOrEmptyString returns a hex string from SpanID.
// An empty string is returned, if SpanID is empty.
func SpanIDToHexOrEmptyString(id pcommon.SpanID) string {
if id.IsEmpty() {
return ""
}
return hex.EncodeToString(id[:])
}
// TraceIDToHexOrEmptyString returns a hex string from TraceID.
// An empty string is returned, if TraceID is empty.
func TraceIDToHexOrEmptyString(id pcommon.TraceID) string {
if id.IsEmpty() {
return ""
}
return hex.EncodeToString(id[:])
}