Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(internal/trace): export internal/trace package constants and vars #9242

Merged
merged 6 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions internal/trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,15 @@ import (
)

const (
telemetryPlatformTracingOpenCensus = "opencensus"
telemetryPlatformTracingOpenTelemetry = "opentelemetry"
telemetryPlatformTracingVar = "GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING"
TelemetryPlatformTracingOpenCensus = "opencensus"
TelemetryPlatformTracingOpenTelemetry = "opentelemetry"
TelemetryPlatformTracingVar = "GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING"
quartzmo marked this conversation as resolved.
Show resolved Hide resolved
)

var (
// TODO(chrisdsmith): Should the name of the OpenTelemetry tracer be public and mutable?
openTelemetryTracerName string = "cloud.google.com/go"
openTelemetryTracingEnabled bool = strings.EqualFold(strings.TrimSpace(
os.Getenv(telemetryPlatformTracingVar)), telemetryPlatformTracingOpenTelemetry)
OpenTelemetryTracerName string = "cloud.google.com/go"
quartzmo marked this conversation as resolved.
Show resolved Hide resolved
OpenTelemetryTracingEnabled bool = strings.EqualFold(strings.TrimSpace(
os.Getenv(TelemetryPlatformTracingVar)), TelemetryPlatformTracingOpenTelemetry)
)

// IsOpenCensusTracingEnabled returns true if the environment variable
Expand All @@ -55,7 +54,7 @@ func IsOpenCensusTracingEnabled() bool {
// GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING is set to the
// case-insensitive value "opentelemetry".
func IsOpenTelemetryTracingEnabled() bool {
return openTelemetryTracingEnabled
return OpenTelemetryTracingEnabled
}

// StartSpan adds a span to the trace with the given name. If IsOpenCensusTracingEnabled
Expand All @@ -68,7 +67,7 @@ func IsOpenTelemetryTracingEnabled() bool {
// "opencensus" will be required to continue using OpenCensus tracing.
func StartSpan(ctx context.Context, name string) context.Context {
if IsOpenTelemetryTracingEnabled() {
ctx, _ = otel.GetTracerProvider().Tracer(openTelemetryTracerName).Start(ctx, name)
ctx, _ = otel.GetTracerProvider().Tracer(OpenTelemetryTracerName).Start(ctx, name)
} else {
ctx, _ = trace.StartSpan(ctx, name)
}
Expand Down
12 changes: 6 additions & 6 deletions internal/trace/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ var (
)

func TestStartSpan_OpenCensus(t *testing.T) {
old := openTelemetryTracingEnabled
openTelemetryTracingEnabled = false
old := OpenTelemetryTracingEnabled
OpenTelemetryTracingEnabled = false
te := testutil.NewTestExporter()
t.Cleanup(func() {
openTelemetryTracingEnabled = old
OpenTelemetryTracingEnabled = old
te.Unregister()
})

Expand Down Expand Up @@ -95,12 +95,12 @@ func TestStartSpan_OpenCensus(t *testing.T) {
}

func TestStartSpan_OpenTelemetry(t *testing.T) {
old := openTelemetryTracingEnabled
openTelemetryTracingEnabled = true
old := OpenTelemetryTracingEnabled
OpenTelemetryTracingEnabled = true
ctx := context.Background()
te := testutil.NewOpenTelemetryTestExporter()
t.Cleanup(func() {
openTelemetryTracingEnabled = old
OpenTelemetryTracingEnabled = old
te.Unregister(ctx)
})

Expand Down