From 21772ce4342bc8ecbb3e7c8747bba9aec14f3bbb Mon Sep 17 00:00:00 2001 From: Taras Madan Date: Thu, 18 Jan 2024 17:24:16 +0100 Subject: Revert "mod: do: bump google.golang.org/api from 0.153.0 to 0.156.0" --- .../go/internal/.repo-metadata-full.json | 40 ------ vendor/cloud.google.com/go/internal/trace/trace.go | 146 +++------------------ 2 files changed, 15 insertions(+), 171 deletions(-) (limited to 'vendor/cloud.google.com/go/internal') diff --git a/vendor/cloud.google.com/go/internal/.repo-metadata-full.json b/vendor/cloud.google.com/go/internal/.repo-metadata-full.json index 46c4094d3..31d172047 100644 --- a/vendor/cloud.google.com/go/internal/.repo-metadata-full.json +++ b/vendor/cloud.google.com/go/internal/.repo-metadata-full.json @@ -619,16 +619,6 @@ "release_level": "stable", "library_type": "GAPIC_AUTO" }, - "cloud.google.com/go/cloudprofiler/apiv2": { - "api_shortname": "cloudprofiler", - "distribution_name": "cloud.google.com/go/cloudprofiler/apiv2", - "description": "Cloud Profiler API", - "language": "go", - "client_library_type": "generated", - "client_documentation": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/cloudprofiler/latest/apiv2", - "release_level": "preview", - "library_type": "GAPIC_AUTO" - }, "cloud.google.com/go/cloudtasks/apiv2": { "api_shortname": "cloudtasks", "distribution_name": "cloud.google.com/go/cloudtasks/apiv2", @@ -1029,16 +1019,6 @@ "release_level": "stable", "library_type": "GAPIC_AUTO" }, - "cloud.google.com/go/edgenetwork/apiv1": { - "api_shortname": "edgenetwork", - "distribution_name": "cloud.google.com/go/edgenetwork/apiv1", - "description": "Distributed Cloud Edge Network API", - "language": "go", - "client_library_type": "generated", - "client_documentation": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/edgenetwork/latest/apiv1", - "release_level": "preview", - "library_type": "GAPIC_AUTO" - }, "cloud.google.com/go/errorreporting": { "api_shortname": "clouderrorreporting", "distribution_name": "cloud.google.com/go/errorreporting", @@ -1119,16 +1099,6 @@ "release_level": "stable", "library_type": "GAPIC_AUTO" }, - "cloud.google.com/go/firestore/apiv1/admin": { - "api_shortname": "firestore", - "distribution_name": "cloud.google.com/go/firestore/apiv1/admin", - "description": "Cloud Firestore API", - "language": "go", - "client_library_type": "generated", - "client_documentation": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/firestore/latest/apiv1/admin", - "release_level": "stable", - "library_type": "GAPIC_AUTO" - }, "cloud.google.com/go/functions/apiv1": { "api_shortname": "cloudfunctions", "distribution_name": "cloud.google.com/go/functions/apiv1", @@ -2309,16 +2279,6 @@ "release_level": "preview", "library_type": "GAPIC_AUTO" }, - "cloud.google.com/go/telcoautomation/apiv1": { - "api_shortname": "telcoautomation", - "distribution_name": "cloud.google.com/go/telcoautomation/apiv1", - "description": "Telco Automation API", - "language": "go", - "client_library_type": "generated", - "client_documentation": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/telcoautomation/latest/apiv1", - "release_level": "preview", - "library_type": "GAPIC_AUTO" - }, "cloud.google.com/go/texttospeech/apiv1": { "api_shortname": "texttospeech", "distribution_name": "cloud.google.com/go/texttospeech/apiv1", diff --git a/vendor/cloud.google.com/go/internal/trace/trace.go b/vendor/cloud.google.com/go/internal/trace/trace.go index f6b88253b..c201d343e 100644 --- a/vendor/cloud.google.com/go/internal/trace/trace.go +++ b/vendor/cloud.google.com/go/internal/trace/trace.go @@ -16,94 +16,35 @@ package trace import ( "context" - "errors" "fmt" - "os" - "strings" "go.opencensus.io/trace" - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/codes" - ottrace "go.opentelemetry.io/otel/trace" + "golang.org/x/xerrors" "google.golang.org/api/googleapi" "google.golang.org/genproto/googleapis/rpc/code" "google.golang.org/grpc/status" ) -const ( - telemetryPlatformTracingOpenCensus = "opencensus" - telemetryPlatformTracingOpenTelemetry = "opentelemetry" - telemetryPlatformTracingVar = "GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING" -) - -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) -) - -// IsOpenCensusTracingEnabled returns true if the environment variable -// GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING is NOT set to the -// case-insensitive value "opentelemetry". -func IsOpenCensusTracingEnabled() bool { - return !IsOpenTelemetryTracingEnabled() -} - -// IsOpenTelemetryTracingEnabled returns true if the environment variable -// GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING is set to the -// case-insensitive value "opentelemetry". -func IsOpenTelemetryTracingEnabled() bool { - return openTelemetryTracingEnabled -} - -// StartSpan adds a span to the trace with the given name. If IsOpenCensusTracingEnabled -// returns true, the span will be an OpenCensus span. If IsOpenTelemetryTracingEnabled -// returns true, the span will be an OpenTelemetry span. Set the environment variable -// GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING to the case-insensitive -// value "opentelemetry" before loading the package to use OpenTelemetry tracing. -// The default will remain OpenCensus until [TBD], at which time the default will -// switch to "opentelemetry" and explicitly setting the environment variable to -// "opencensus" will be required to continue using OpenCensus tracing. +// StartSpan adds a span to the trace with the given name. func StartSpan(ctx context.Context, name string) context.Context { - if IsOpenTelemetryTracingEnabled() { - ctx, _ = otel.GetTracerProvider().Tracer(openTelemetryTracerName).Start(ctx, name) - } else { - ctx, _ = trace.StartSpan(ctx, name) - } + ctx, _ = trace.StartSpan(ctx, name) return ctx } -// EndSpan ends a span with the given error. If IsOpenCensusTracingEnabled -// returns true, the span will be an OpenCensus span. If IsOpenTelemetryTracingEnabled -// returns true, the span will be an OpenTelemetry span. Set the environment variable -// GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING to the case-insensitive -// value "opentelemetry" before loading the package to use OpenTelemetry tracing. -// The default will remain OpenCensus until [TBD], at which time the default will -// switch to "opentelemetry" and explicitly setting the environment variable to -// "opencensus" will be required to continue using OpenCensus tracing. +// EndSpan ends a span with the given error. func EndSpan(ctx context.Context, err error) { - if IsOpenTelemetryTracingEnabled() { - span := ottrace.SpanFromContext(ctx) - if err != nil { - span.SetStatus(codes.Error, toOpenTelemetryStatusDescription(err)) - span.RecordError(err) - } - span.End() - } else { - span := trace.FromContext(ctx) - if err != nil { - span.SetStatus(toStatus(err)) - } - span.End() + span := trace.FromContext(ctx) + if err != nil { + span.SetStatus(toStatus(err)) } + span.End() } -// toStatus converts an error to an equivalent OpenCensus status. +// toStatus interrogates an error and converts it to an appropriate +// OpenCensus status. func toStatus(err error) trace.Status { var err2 *googleapi.Error - if ok := errors.As(err, &err2); ok { + if ok := xerrors.As(err, &err2); ok { return trace.Status{Code: httpStatusCodeToOCCode(err2.Code), Message: err2.Message} } else if s, ok := status.FromError(err); ok { return trace.Status{Code: int32(s.Code()), Message: s.Message()} @@ -112,18 +53,6 @@ func toStatus(err error) trace.Status { } } -// toOpenTelemetryStatus converts an error to an equivalent OpenTelemetry status description. -func toOpenTelemetryStatusDescription(err error) string { - var err2 *googleapi.Error - if ok := errors.As(err, &err2); ok { - return err2.Message - } else if s, ok := status.FromError(err); ok { - return s.Message() - } else { - return err.Error() - } -} - // TODO(deklerk): switch to using OpenCensus function when it becomes available. // Reference: https://github.com/googleapis/googleapis/blob/26b634d2724ac5dd30ae0b0cbfb01f07f2e4050e/google/rpc/code.proto func httpStatusCodeToOCCode(httpStatusCode int) int32 { @@ -157,33 +86,10 @@ func httpStatusCodeToOCCode(httpStatusCode int) int32 { } } -// TracePrintf retrieves the current OpenCensus or OpenTelemetry span from context, then: -// * calls Span.Annotatef if OpenCensus is enabled; or -// * calls Span.AddEvent if OpenTelemetry is enabled. -// -// If IsOpenCensusTracingEnabled returns true, the expected span must be an -// OpenCensus span. If IsOpenTelemetryTracingEnabled returns true, the expected -// span must be an OpenTelemetry span. Set the environment variable -// GOOGLE_API_GO_EXPERIMENTAL_TELEMETRY_PLATFORM_TRACING to the case-insensitive -// value "opentelemetry" before loading the package to use OpenTelemetry tracing. -// The default will remain OpenCensus until [TBD], at which time the default will -// switch to "opentelemetry" and explicitly setting the environment variable to -// "opencensus" will be required to continue using OpenCensus tracing. +// TODO: (odeke-em): perhaps just pass around spans due to the cost +// incurred from using trace.FromContext(ctx) yet we could avoid +// throwing away the work done by ctx, span := trace.StartSpan. func TracePrintf(ctx context.Context, attrMap map[string]interface{}, format string, args ...interface{}) { - if IsOpenTelemetryTracingEnabled() { - attrs := otAttrs(attrMap) - ottrace.SpanFromContext(ctx).AddEvent(fmt.Sprintf(format, args...), ottrace.WithAttributes(attrs...)) - } else { - attrs := ocAttrs(attrMap) - // TODO: (odeke-em): perhaps just pass around spans due to the cost - // incurred from using trace.FromContext(ctx) yet we could avoid - // throwing away the work done by ctx, span := trace.StartSpan. - trace.FromContext(ctx).Annotatef(attrs, format, args...) - } -} - -// ocAttrs converts a generic map to OpenCensus attributes. -func ocAttrs(attrMap map[string]interface{}) []trace.Attribute { var attrs []trace.Attribute for k, v := range attrMap { var a trace.Attribute @@ -201,27 +107,5 @@ func ocAttrs(attrMap map[string]interface{}) []trace.Attribute { } attrs = append(attrs, a) } - return attrs -} - -// otAttrs converts a generic map to OpenTelemetry attributes. -func otAttrs(attrMap map[string]interface{}) []attribute.KeyValue { - var attrs []attribute.KeyValue - for k, v := range attrMap { - var a attribute.KeyValue - switch v := v.(type) { - case string: - a = attribute.Key(k).String(v) - case bool: - a = attribute.Key(k).Bool(v) - case int: - a = attribute.Key(k).Int(v) - case int64: - a = attribute.Key(k).Int64(v) - default: - a = attribute.Key(k).String(fmt.Sprintf("%#v", v)) - } - attrs = append(attrs, a) - } - return attrs + trace.FromContext(ctx).Annotatef(attrs, format, args...) } -- cgit mrf-deployment