Skip to content

Commit 430ce8a

Browse files
authored
feat(internal/trace): deprecate OpenCensus support (#10287)
* Change default for `GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING` env var flag to OpenTelemetry. * See https://github.com/googleapis/google-cloud-go/blob/main/debug.md\#telemetry refs: #2205 refs: #8655
1 parent 4832e10 commit 430ce8a

File tree

4 files changed

+85
-69
lines changed

4 files changed

+85
-69
lines changed

auth/grpctransport/grpctransport.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var (
4747

4848
// Options used to configure a [GRPCClientConnPool] from [Dial].
4949
type Options struct {
50-
// DisableTelemetry disables default telemetry (OpenCensus). An example
50+
// DisableTelemetry disables default telemetry (OpenTelemetry). An example
5151
// reason to do so would be to bind custom telemetry that overrides the
5252
// defaults.
5353
DisableTelemetry bool

auth/httptransport/httptransport.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type ClientCertProvider = func(*tls.CertificateRequestInfo) (*tls.Certificate, e
3333

3434
// Options used to configure a [net/http.Client] from [NewClient].
3535
type Options struct {
36-
// DisableTelemetry disables default telemetry (OpenCensus). An example
36+
// DisableTelemetry disables default telemetry (OpenTelemetry). An example
3737
// reason to do so would be to bind custom telemetry that overrides the
3838
// defaults.
3939
DisableTelemetry bool

debug.md

+26-32
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
**Warning: The OpenCensus project is obsolete and was archived on July 31st,
44
2023.** This means that any security vulnerabilities that are found will not be
5-
patched. We recommend that you begin migrating to OpenCensus tracing to
5+
patched. We recommend that you migrate from OpenCensus tracing to
66
OpenTelemetry, the successor project. See [OpenCensus](#opencensus) below for
77
details.
88

@@ -181,15 +181,16 @@ func main() {
181181

182182
**Warning: The OpenCensus project is obsolete and was archived on July 31st,
183183
2023.** This means that any security vulnerabilities that are found will not be
184-
patched. We recommend that you begin migrating to OpenCensus tracing to
185-
OpenTelemetry, the successor project. See [OpenCensus](#opencensus) below for
186-
details.
184+
patched. We recommend that you migrate from OpenCensus tracing to
185+
OpenTelemetry, the successor project. The default experimental tracing support
186+
for OpenCensus is now deprecated in the Google Cloud client libraries for Go.
187+
See [OpenCensus](#opencensus) below for details.
187188

188-
The Google Cloud client libraries for Go still use the OpenCensus project by
189-
default. However, opt-in support for
190-
[OpenTelemetry](https://opentelemetry.io/docs/what-is-opentelemetry/) is now
191-
available. The transition from OpenCensus to OpenTelemetry is covered in the
192-
following sections.
189+
The Google Cloud client libraries for Go now use the
190+
[OpenTelemetry](https://opentelemetry.io/docs/what-is-opentelemetry/) project by
191+
default. Temporary opt-in support for OpenCensus is still available. The
192+
transition from OpenCensus to OpenTelemetry is covered in the following
193+
sections.
193194

194195
### Tracing (experimental)
195196

@@ -204,17 +205,18 @@ hand-written clients are in scope for the discussion in this section:
204205
* [cloud.google.com/go/spanner](https://pkg.go.dev/cloud.google.com/go/spanner)
205206
* [cloud.google.com/go/storage](https://pkg.go.dev/cloud.google.com/go/storage)
206207

207-
Currently, the spans created by these clients are for OpenCensus. However,
208-
OpenCensus users are urged to transition to OpenTelemetry as soon as possible,
209-
as explained in the next section. OpenTelemetry users can opt-in to experimental
210-
OpenTelemetry support via an environment variable, as described below.
208+
Currently, the spans created by these clients are for OpenTelemetry. OpenCensus
209+
users are urged to transition to OpenTelemetry as soon as possible, as explained
210+
in the next section. OpenCensus users can still opt-in to the deprecated
211+
OpenCensus support via an environment variable, as described below.
211212

212213
#### OpenCensus
213214

214215
**Warning: The OpenCensus project is obsolete and was archived on July 31st,
215216
2023.** This means that any security vulnerabilities that are found will not be
216-
patched. We recommend that you begin migrating to OpenCensus tracing to
217-
OpenTelemetry, the successor project.
217+
patched. We recommend that you migrate from OpenCensus tracing to
218+
OpenTelemetry, the successor project. The default experimental tracing support
219+
for OpenCensus is now deprecated in the Google Cloud client libraries for Go.
218220

219221
Using the [OpenTelemetry-Go - OpenCensus Bridge](https://pkg.go.dev/go.opentelemetry.io/otel/bridge/opencensus), you can immediately begin exporting your traces with OpenTelemetry, even while
220222
dependencies of your application remain instrumented with OpenCensus. If you do
@@ -226,9 +228,9 @@ instrumentation are used.
226228
On May 29, 2024, six months after the
227229
[release](https://github.com/googleapis/google-cloud-go/releases/tag/v0.111.0)
228230
of experimental, opt-in support for OpenTelemetry tracing, the default tracing
229-
support in the clients above will change from OpenCensus to OpenTelemetry, and
230-
the experimental OpenCensus support will be marked as deprecated. To continue
231-
using the OpenCensus support after this change, set the environment variable
231+
support in the clients above was changed from OpenCensus to OpenTelemetry, and
232+
the experimental OpenCensus support was marked as deprecated. To continue
233+
using the OpenCensus support, set the environment variable
232234
`GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING` to the case-insensitive
233235
value `opencensus` before loading the client library.
234236

@@ -252,6 +254,12 @@ Please refer to the following resources:
252254

253255
#### OpenTelemetry
254256

257+
The default experimental tracing support for OpenCensus is now deprecated in the
258+
Google Cloud client libraries for Go.
259+
260+
On May 29, 2024, the default experimental tracing support in the Google Cloud
261+
client libraries for Go was changed from OpenCensus to OpenTelemetry.
262+
255263
**Warning: OpenTelemetry-Go ensures
256264
[compatibility](https://github.com/open-telemetry/opentelemetry-go/tree/main?tab=readme-ov-file#compatibility)
257265
with ONLY the current supported versions of the [Go
@@ -261,18 +269,6 @@ Ensure that your Go runtime version is supported by the OpenTelemetry-Go
261269
[compatibility](https://github.com/open-telemetry/opentelemetry-go/tree/main?tab=readme-ov-file#compatibility)
262270
policy before enabling OpenTelemetry instrumentation.**
263271

264-
To opt-in to experimental OpenTelemetry tracing currently available in the
265-
clients listed above, set the environment variable
266-
`GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING` to the case-insensitive
267-
value `opentelemetry` before loading the client library.
268-
269-
```sh
270-
export GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING=opentelemetry
271-
```
272-
273-
On May 29, 2024, the default tracing support will change from OpenCensus to
274-
OpenTelemetry, and this environment variable will no longer be needed.
275-
276272
Please refer to the following resources:
277273

278274
* [What is OpenTelemetry?](https://opentelemetry.io/docs/what-is-opentelemetry/)
@@ -341,7 +337,6 @@ func main() {
341337

342338
```
343339

344-
345340
##### Configuring context propagation
346341

347342
In order to pass options to OpenTelemetry trace context propagation, follow the
@@ -388,7 +383,6 @@ if err != nil {
388383
defer c.Close()
389384
```
390385

391-
392386
### Metrics (experimental)
393387

394388
The generated clients do not create metrics. Only the following hand-written

internal/trace/trace.go

+57-35
Original file line numberDiff line numberDiff line change
@@ -33,65 +33,81 @@ import (
3333
)
3434

3535
const (
36+
// Deprecated: The default experimental tracing support for OpenCensus is
37+
// now deprecated in the Google Cloud client libraries for Go.
3638
// TelemetryPlatformTracingOpenCensus is the value to which the environment
3739
// variable GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING should be
3840
// set to enable OpenCensus tracing.
3941
TelemetryPlatformTracingOpenCensus = "opencensus"
40-
// TelemetryPlatformTracingOpenCensus is the value to which the environment
42+
// TelemetryPlatformTracingOpenTelemetry is the value to which the environment
4143
// variable GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING should be
4244
// set to enable OpenTelemetry tracing.
4345
TelemetryPlatformTracingOpenTelemetry = "opentelemetry"
44-
// TelemetryPlatformTracingOpenCensus is the name of the environment
45-
// variable that can be set to change the default tracing from OpenCensus
46-
// to OpenTelemetry.
46+
// TelemetryPlatformTracingVar is the name of the environment
47+
// variable that can be set to change the default tracing from OpenTelemetry
48+
// to OpenCensus.
49+
//
50+
// The default experimental tracing support for OpenCensus is now deprecated
51+
// in the Google Cloud client libraries for Go.
4752
TelemetryPlatformTracingVar = "GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING"
4853
// OpenTelemetryTracerName is the name given to the OpenTelemetry Tracer
4954
// when it is obtained from the OpenTelemetry TracerProvider.
5055
OpenTelemetryTracerName = "cloud.google.com/go"
5156
)
5257

5358
var (
54-
// openTelemetryTracingEnabledMu guards access to openTelemetryTracingEnabled field
55-
openTelemetryTracingEnabledMu = sync.RWMutex{}
56-
// openTelemetryTracingEnabled is true if the environment variable
59+
// openCensusTracingEnabledMu guards access to openCensusTracingEnabled field
60+
openCensusTracingEnabledMu = sync.RWMutex{}
61+
// openCensusTracingEnabled is true if the environment variable
5762
// GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING is set to the
58-
// case-insensitive value "opentelemetry".
59-
openTelemetryTracingEnabled bool = strings.EqualFold(strings.TrimSpace(
60-
os.Getenv(TelemetryPlatformTracingVar)), TelemetryPlatformTracingOpenTelemetry)
63+
// case-insensitive value "opencensus".
64+
openCensusTracingEnabled bool = strings.EqualFold(strings.TrimSpace(
65+
os.Getenv(TelemetryPlatformTracingVar)), TelemetryPlatformTracingOpenCensus)
6166
)
6267

63-
// SetOpenTelemetryTracingEnabledField programmatically sets the value provided by GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING for the purpose of unit testing.
64-
// Do not invoke it directly. Intended for use only in unit tests. Restore original value after each test.
68+
// SetOpenTelemetryTracingEnabledField programmatically sets the value provided
69+
// by GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING for the purpose of
70+
// unit testing. Do not invoke it directly. Intended for use only in unit tests.
71+
// Restore original value after each test.
72+
//
73+
// The default experimental tracing support for OpenCensus is now deprecated in
74+
// the Google Cloud client libraries for Go.
6575
func SetOpenTelemetryTracingEnabledField(enabled bool) {
66-
openTelemetryTracingEnabledMu.Lock()
67-
defer openTelemetryTracingEnabledMu.Unlock()
68-
openTelemetryTracingEnabled = enabled
76+
openCensusTracingEnabledMu.Lock()
77+
defer openCensusTracingEnabledMu.Unlock()
78+
openCensusTracingEnabled = !enabled
6979
}
7080

81+
// Deprecated: The default experimental tracing support for OpenCensus is now
82+
// deprecated in the Google Cloud client libraries for Go.
83+
//
7184
// IsOpenCensusTracingEnabled returns true if the environment variable
72-
// GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING is NOT set to the
73-
// case-insensitive value "opentelemetry".
85+
// GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING is set to the
86+
// case-insensitive value "opencensus".
7487
func IsOpenCensusTracingEnabled() bool {
75-
return !IsOpenTelemetryTracingEnabled()
88+
openCensusTracingEnabledMu.RLock()
89+
defer openCensusTracingEnabledMu.RUnlock()
90+
return openCensusTracingEnabled
7691
}
7792

7893
// IsOpenTelemetryTracingEnabled returns true if the environment variable
79-
// GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING is set to the
80-
// case-insensitive value "opentelemetry".
94+
// GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING is NOT set to the
95+
// case-insensitive value "opencensus".
8196
func IsOpenTelemetryTracingEnabled() bool {
82-
openTelemetryTracingEnabledMu.RLock()
83-
defer openTelemetryTracingEnabledMu.RUnlock()
84-
return openTelemetryTracingEnabled
97+
return !IsOpenCensusTracingEnabled()
8598
}
8699

87100
// StartSpan adds a span to the trace with the given name. If IsOpenCensusTracingEnabled
88101
// returns true, the span will be an OpenCensus span. If IsOpenTelemetryTracingEnabled
89102
// returns true, the span will be an OpenTelemetry span. Set the environment variable
90103
// GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING to the case-insensitive
91-
// value "opentelemetry" before loading the package to use OpenTelemetry tracing.
92-
// The default will remain OpenCensus until May 29, 2024, at which time the default will
93-
// switch to "opentelemetry" and explicitly setting the environment variable to
94-
// "opencensus" will be required to continue using OpenCensus tracing.
104+
// value "opencensus" before loading the package to use OpenCensus tracing.
105+
// The default was OpenCensus until May 29, 2024, at which time the default was
106+
// changed to "opencensus". Explicitly setting the environment variable to
107+
// "opencensus" is required to continue using OpenCensus tracing.
108+
//
109+
// The default experimental tracing support for OpenCensus is now deprecated in
110+
// the Google Cloud client libraries for Go.
95111
func StartSpan(ctx context.Context, name string) context.Context {
96112
if IsOpenTelemetryTracingEnabled() {
97113
ctx, _ = otel.GetTracerProvider().Tracer(OpenTelemetryTracerName).Start(ctx, name)
@@ -105,10 +121,13 @@ func StartSpan(ctx context.Context, name string) context.Context {
105121
// returns true, the span will be an OpenCensus span. If IsOpenTelemetryTracingEnabled
106122
// returns true, the span will be an OpenTelemetry span. Set the environment variable
107123
// GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING to the case-insensitive
108-
// value "opentelemetry" before loading the package to use OpenTelemetry tracing.
109-
// The default will remain OpenCensus until May 29, 2024, at which time the default will
110-
// switch to "opentelemetry" and explicitly setting the environment variable to
111-
// "opencensus" will be required to continue using OpenCensus tracing.
124+
// value "opencensus" before loading the package to use OpenCensus tracing.
125+
// The default was OpenCensus until May 29, 2024, at which time the default was
126+
// changed to "opencensus". Explicitly setting the environment variable to
127+
// "opencensus" is required to continue using OpenCensus tracing.
128+
//
129+
// The default experimental tracing support for OpenCensus is now deprecated in
130+
// the Google Cloud client libraries for Go.
112131
func EndSpan(ctx context.Context, err error) {
113132
if IsOpenTelemetryTracingEnabled() {
114133
span := ottrace.SpanFromContext(ctx)
@@ -191,10 +210,13 @@ func httpStatusCodeToOCCode(httpStatusCode int) int32 {
191210
// OpenCensus span. If IsOpenTelemetryTracingEnabled returns true, the expected
192211
// span must be an OpenTelemetry span. Set the environment variable
193212
// GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING to the case-insensitive
194-
// value "opentelemetry" before loading the package to use OpenTelemetry tracing.
195-
// The default will remain OpenCensus until May 29, 2024, at which time the default will
196-
// switch to "opentelemetry" and explicitly setting the environment variable to
197-
// "opencensus" will be required to continue using OpenCensus tracing.
213+
// value "opencensus" before loading the package to use OpenCensus tracing.
214+
// The default was OpenCensus until May 29, 2024, at which time the default was
215+
// changed to "opencensus". Explicitly setting the environment variable to
216+
// "opencensus" is required to continue using OpenCensus tracing.
217+
//
218+
// The default experimental tracing support for OpenCensus is now deprecated in
219+
// the Google Cloud client libraries for Go.
198220
func TracePrintf(ctx context.Context, attrMap map[string]interface{}, format string, args ...interface{}) {
199221
if IsOpenTelemetryTracingEnabled() {
200222
attrs := otAttrs(attrMap)

0 commit comments

Comments
 (0)