@@ -32,16 +32,33 @@ import (
32
32
)
33
33
34
34
const (
35
- telemetryPlatformTracingOpenCensus = "opencensus"
36
- telemetryPlatformTracingOpenTelemetry = "opentelemetry"
37
- telemetryPlatformTracingVar = "GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING"
35
+ // TelemetryPlatformTracingOpenCensus is the value to which the environment
36
+ // variable GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING should be
37
+ // set to enable OpenCensus tracing.
38
+ TelemetryPlatformTracingOpenCensus = "opencensus"
39
+ // TelemetryPlatformTracingOpenCensus is the value to which the environment
40
+ // variable GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING should be
41
+ // set to enable OpenTelemetry tracing.
42
+ TelemetryPlatformTracingOpenTelemetry = "opentelemetry"
43
+ // TelemetryPlatformTracingOpenCensus is the name of the environment
44
+ // variable that can be set to change the default tracing from OpenCensus
45
+ // to OpenTelemetry.
46
+ TelemetryPlatformTracingVar = "GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING"
47
+ // OpenTelemetryTracerName is the name given to the OpenTelemetry Tracer
48
+ // when it is obtained from the OpenTelemetry TracerProvider.
49
+ OpenTelemetryTracerName = "cloud.google.com/go"
38
50
)
39
51
40
52
var (
41
- // TODO(chrisdsmith): Should the name of the OpenTelemetry tracer be public and mutable?
42
- openTelemetryTracerName string = "cloud.google.com/go"
43
- openTelemetryTracingEnabled bool = strings .EqualFold (strings .TrimSpace (
44
- os .Getenv (telemetryPlatformTracingVar )), telemetryPlatformTracingOpenTelemetry )
53
+ // OpenTelemetryTracingEnabled is true if the environment variable
54
+ // GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING is set to the
55
+ // case-insensitive value "opentelemetry".
56
+ //
57
+ // Do not access directly. Use instead IsOpenTelemetryTracingEnabled or
58
+ // IsOpenCensusTracingEnabled. Intended for use only in unit tests. Restore
59
+ // original value after each test.
60
+ OpenTelemetryTracingEnabled bool = strings .EqualFold (strings .TrimSpace (
61
+ os .Getenv (TelemetryPlatformTracingVar )), TelemetryPlatformTracingOpenTelemetry )
45
62
)
46
63
47
64
// IsOpenCensusTracingEnabled returns true if the environment variable
@@ -55,20 +72,20 @@ func IsOpenCensusTracingEnabled() bool {
55
72
// GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING is set to the
56
73
// case-insensitive value "opentelemetry".
57
74
func IsOpenTelemetryTracingEnabled () bool {
58
- return openTelemetryTracingEnabled
75
+ return OpenTelemetryTracingEnabled
59
76
}
60
77
61
78
// StartSpan adds a span to the trace with the given name. If IsOpenCensusTracingEnabled
62
79
// returns true, the span will be an OpenCensus span. If IsOpenTelemetryTracingEnabled
63
80
// returns true, the span will be an OpenTelemetry span. Set the environment variable
64
81
// GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING to the case-insensitive
65
82
// value "opentelemetry" before loading the package to use OpenTelemetry tracing.
66
- // The default will remain OpenCensus until [TBD] , at which time the default will
83
+ // The default will remain OpenCensus until May 29, 2024 , at which time the default will
67
84
// switch to "opentelemetry" and explicitly setting the environment variable to
68
85
// "opencensus" will be required to continue using OpenCensus tracing.
69
86
func StartSpan (ctx context.Context , name string ) context.Context {
70
87
if IsOpenTelemetryTracingEnabled () {
71
- ctx , _ = otel .GetTracerProvider ().Tracer (openTelemetryTracerName ).Start (ctx , name )
88
+ ctx , _ = otel .GetTracerProvider ().Tracer (OpenTelemetryTracerName ).Start (ctx , name )
72
89
} else {
73
90
ctx , _ = trace .StartSpan (ctx , name )
74
91
}
@@ -80,7 +97,7 @@ func StartSpan(ctx context.Context, name string) context.Context {
80
97
// returns true, the span will be an OpenTelemetry span. Set the environment variable
81
98
// GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING to the case-insensitive
82
99
// value "opentelemetry" before loading the package to use OpenTelemetry tracing.
83
- // The default will remain OpenCensus until [TBD] , at which time the default will
100
+ // The default will remain OpenCensus until May 29, 2024 , at which time the default will
84
101
// switch to "opentelemetry" and explicitly setting the environment variable to
85
102
// "opencensus" will be required to continue using OpenCensus tracing.
86
103
func EndSpan (ctx context.Context , err error ) {
@@ -166,7 +183,7 @@ func httpStatusCodeToOCCode(httpStatusCode int) int32 {
166
183
// span must be an OpenTelemetry span. Set the environment variable
167
184
// GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING to the case-insensitive
168
185
// value "opentelemetry" before loading the package to use OpenTelemetry tracing.
169
- // The default will remain OpenCensus until [TBD] , at which time the default will
186
+ // The default will remain OpenCensus until May 29, 2024 , at which time the default will
170
187
// switch to "opentelemetry" and explicitly setting the environment variable to
171
188
// "opencensus" will be required to continue using OpenCensus tracing.
172
189
func TracePrintf (ctx context.Context , attrMap map [string ]interface {}, format string , args ... interface {}) {
0 commit comments