diff --git a/go.mod b/go.mod index 1e484419b6..4bfd2be3a9 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( cloud.google.com/go/compute/metadata v0.9.0 cloud.google.com/go/logging v1.13.2 cloud.google.com/go/monitoring v1.24.3 - cloud.google.com/go/trace v1.12.0 + cloud.google.com/go/trace v1.14.0 github.com/GoogleContainerTools/kpt-functions-catalog/functions/go/set-namespace v0.4.1-0.20220713210718-d955e7d3a800 github.com/GoogleContainerTools/kpt-functions-sdk/go/fn v0.0.0-20220706221933-7181f451a663 github.com/Masterminds/semver v1.5.0 @@ -108,7 +108,7 @@ require ( github.com/google/licenseclassifier/v2 v2.0.0 // indirect github.com/google/s2a-go v0.1.9 // indirect github.com/googleapis/enterprise-certificate-proxy v0.3.14 // indirect - github.com/googleapis/gax-go/v2 v2.20.0 // indirect + github.com/googleapis/gax-go/v2 v2.21.0 // indirect github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect diff --git a/go.sum b/go.sum index 589c3c3eb4..f2e241ce51 100644 --- a/go.sum +++ b/go.sum @@ -21,8 +21,8 @@ cloud.google.com/go/monitoring v1.24.3 h1:dde+gMNc0UhPZD1Azu6at2e79bfdztVDS5lvhO cloud.google.com/go/monitoring v1.24.3/go.mod h1:nYP6W0tm3N9H/bOw8am7t62YTzZY+zUeQ+Bi6+2eonI= cloud.google.com/go/storage v1.59.0 h1:9p3yDzEN9Vet4JnbN90FECIw6n4FCXcKBK1scxtQnw8= cloud.google.com/go/storage v1.59.0/go.mod h1:cMWbtM+anpC74gn6qjLh+exqYcfmB9Hqe5z6adx+CLI= -cloud.google.com/go/trace v1.12.0 h1:XvWHYfr9q88cX4pZyou6qCcSagnuASyUq2ej1dB6NzQ= -cloud.google.com/go/trace v1.12.0/go.mod h1:TOYfyeoyCGsSH0ifXD6Aius24uQI9xV3RyvOdljFIyg= +cloud.google.com/go/trace v1.14.0 h1:jUtnmOrNcu5XJNk4Gz0fv+v5sM0weaOa3z5MPQUjRXs= +cloud.google.com/go/trace v1.14.0/go.mod h1:r+bdAn16dKLSV1G2D5v3e58IlQlizfxWrUfjx7kM7X0= github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0= github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= @@ -188,8 +188,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/enterprise-certificate-proxy v0.3.14 h1:yh8ncqsbUY4shRD5dA6RlzjJaT4hi3kII+zYw8wmLb8= github.com/googleapis/enterprise-certificate-proxy v0.3.14/go.mod h1:vqVt9yG9480NtzREnTlmGSBmFrA+bzb0yl0TxoBQXOg= -github.com/googleapis/gax-go/v2 v2.20.0 h1:NIKVuLhDlIV74muWlsMM4CcQZqN6JJ20Qcxd9YMuYcs= -github.com/googleapis/gax-go/v2 v2.20.0/go.mod h1:But/NJU6TnZsrLai/xBAQLLz+Hc7fHZJt/hsCz3Fih4= +github.com/googleapis/gax-go/v2 v2.21.0 h1:h45NjjzEO3faG9Lg/cFrBh2PgegVVgzqKzuZl/wMbiI= +github.com/googleapis/gax-go/v2 v2.21.0/go.mod h1:But/NJU6TnZsrLai/xBAQLLz+Hc7fHZJt/hsCz3Fih4= github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 h1:+ngKgrYPPJrOjhax5N+uePQ0Fh1Z7PheYoUI/0nzkPA= github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0 h1:HWRh5R2+9EifMyIHV7ZV+MIZqgz+PMpZ14Jynv3O2Zs= diff --git a/vendor/cloud.google.com/go/trace/apiv2/trace_client.go b/vendor/cloud.google.com/go/trace/apiv2/trace_client.go index 2fa120f16a..398ea9a4bf 100644 --- a/vendor/cloud.google.com/go/trace/apiv2/trace_client.go +++ b/vendor/cloud.google.com/go/trace/apiv2/trace_client.go @@ -28,6 +28,7 @@ import ( tracepb "cloud.google.com/go/trace/apiv2/tracepb" gax "github.com/googleapis/gax-go/v2" + "github.com/googleapis/gax-go/v2/callctx" "google.golang.org/api/option" "google.golang.org/api/option/internaloption" gtransport "google.golang.org/api/transport/grpc" @@ -213,6 +214,16 @@ type gRPCClient struct { // A single trace can contain spans from multiple services. func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) { clientOpts := defaultGRPCClientOptions() + if gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") { + clientOpts = append(clientOpts, internaloption.WithTelemetryAttributes(map[string]string{ + "gcp.client.service": "cloudtrace", + "gcp.client.version": getVersionClient(), + "gcp.client.repo": "googleapis/google-cloud-go", + "gcp.client.artifact": "cloud.google.com/go/trace/apiv2", + "gcp.client.language": "go", + "url.domain": "cloudtrace.googleapis.com", + })) + } if newClientHook != nil { hookOpts, err := newClientHook(ctx, clientHookParams{}) if err != nil { @@ -234,6 +245,21 @@ func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error logger: internaloption.GetLogger(opts), } c.setGoogleClientInfo() + if gax.IsFeatureEnabled("METRICS") { + metrics := gax.NewClientMetrics( + gax.WithTelemetryLogger(c.logger), + gax.WithTelemetryAttributes(map[string]string{ + gax.ClientService: "cloudtrace", + gax.ClientVersion: getVersionClient(), + gax.ClientArtifact: "cloud.google.com/go/trace/apiv2", + gax.RPCSystem: "grpc", + gax.URLDomain: "cloudtrace.googleapis.com", + }), + ) + + client.CallOptions.BatchWriteSpans = append(client.CallOptions.BatchWriteSpans, gax.WithClientMetrics(metrics)) + client.CallOptions.CreateSpan = append(client.CallOptions.CreateSpan, gax.WithClientMetrics(metrics)) + } client.internalClient = c @@ -293,6 +319,16 @@ type restClient struct { // A single trace can contain spans from multiple services. func NewRESTClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) { clientOpts := append(defaultRESTClientOptions(), opts...) + if gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") { + clientOpts = append(clientOpts, internaloption.WithTelemetryAttributes(map[string]string{ + "gcp.client.service": "cloudtrace", + "gcp.client.version": getVersionClient(), + "gcp.client.repo": "googleapis/google-cloud-go", + "gcp.client.artifact": "cloud.google.com/go/trace/apiv2", + "gcp.client.language": "go", + "url.domain": "cloudtrace.googleapis.com", + })) + } httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) if err != nil { return nil, err @@ -307,6 +343,22 @@ func NewRESTClient(ctx context.Context, opts ...option.ClientOption) (*Client, e } c.setGoogleClientInfo() + if gax.IsFeatureEnabled("METRICS") { + metrics := gax.NewClientMetrics( + gax.WithTelemetryLogger(c.logger), + gax.WithTelemetryAttributes(map[string]string{ + gax.ClientService: "cloudtrace", + gax.ClientVersion: getVersionClient(), + gax.ClientArtifact: "cloud.google.com/go/trace/apiv2", + gax.RPCSystem: "http", + gax.URLDomain: "cloudtrace.googleapis.com", + }), + ) + + callOpts.BatchWriteSpans = append(callOpts.BatchWriteSpans, gax.WithClientMetrics(metrics)) + callOpts.CreateSpan = append(callOpts.CreateSpan, gax.WithClientMetrics(metrics)) + } + return &Client{internalClient: c, CallOptions: callOpts}, nil } @@ -352,6 +404,12 @@ func (c *gRPCClient) BatchWriteSpans(ctx context.Context, req *tracepb.BatchWrit hds = append(c.xGoogHeaders, hds...) ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) + if gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") { + ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//cloudtrace.googleapis.com/%v", req.GetName())) + } + if gax.IsFeatureEnabled("METRICS") || gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") { + ctx = callctx.WithTelemetryContext(ctx, "rpc_method", "google.devtools.cloudtrace.v2.TraceService/BatchWriteSpans") + } opts = append((*c.CallOptions).BatchWriteSpans[0:len((*c.CallOptions).BatchWriteSpans):len((*c.CallOptions).BatchWriteSpans)], opts...) err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { var err error @@ -366,6 +424,9 @@ func (c *gRPCClient) CreateSpan(ctx context.Context, req *tracepb.Span, opts ... hds = append(c.xGoogHeaders, hds...) ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) + if gax.IsFeatureEnabled("METRICS") || gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") { + ctx = callctx.WithTelemetryContext(ctx, "rpc_method", "google.devtools.cloudtrace.v2.TraceService/CreateSpan") + } opts = append((*c.CallOptions).CreateSpan[0:len((*c.CallOptions).CreateSpan):len((*c.CallOptions).CreateSpan)], opts...) var resp *tracepb.Span err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { @@ -405,6 +466,13 @@ func (c *restClient) BatchWriteSpans(ctx context.Context, req *tracepb.BatchWrit hds = append(c.xGoogHeaders, hds...) hds = append(hds, "Content-Type", "application/json") headers := gax.BuildHeaders(ctx, hds...) + if gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") { + ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//cloudtrace.googleapis.com/%v", req.GetName())) + } + if gax.IsFeatureEnabled("METRICS") || gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") { + ctx = callctx.WithTelemetryContext(ctx, "rpc_method", "google.devtools.cloudtrace.v2.TraceService/BatchWriteSpans") + ctx = callctx.WithTelemetryContext(ctx, "url_template", "/v2/{name=projects/*}/traces:batchWrite") + } return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { if settings.Path != "" { baseUrl.Path = settings.Path @@ -446,6 +514,10 @@ func (c *restClient) CreateSpan(ctx context.Context, req *tracepb.Span, opts ... hds = append(c.xGoogHeaders, hds...) hds = append(hds, "Content-Type", "application/json") headers := gax.BuildHeaders(ctx, hds...) + if gax.IsFeatureEnabled("METRICS") || gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") { + ctx = callctx.WithTelemetryContext(ctx, "rpc_method", "google.devtools.cloudtrace.v2.TraceService/CreateSpan") + ctx = callctx.WithTelemetryContext(ctx, "url_template", "/v2/{name=projects/*/traces/*/spans/*}") + } opts = append((*c.CallOptions).CreateSpan[0:len((*c.CallOptions).CreateSpan):len((*c.CallOptions).CreateSpan)], opts...) unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} resp := &tracepb.Span{} diff --git a/vendor/cloud.google.com/go/trace/apiv2/tracepb/trace.pb.go b/vendor/cloud.google.com/go/trace/apiv2/tracepb/trace.pb.go index aeff961418..454b099797 100644 --- a/vendor/cloud.google.com/go/trace/apiv2/tracepb/trace.pb.go +++ b/vendor/cloud.google.com/go/trace/apiv2/tracepb/trace.pb.go @@ -15,7 +15,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.36.11 -// protoc v4.25.7 +// protoc v6.31.0 // source: google/devtools/cloudtrace/v2/trace.proto package tracepb diff --git a/vendor/cloud.google.com/go/trace/apiv2/tracepb/tracing.pb.go b/vendor/cloud.google.com/go/trace/apiv2/tracepb/tracing.pb.go index 1f9f06aa86..e185797367 100644 --- a/vendor/cloud.google.com/go/trace/apiv2/tracepb/tracing.pb.go +++ b/vendor/cloud.google.com/go/trace/apiv2/tracepb/tracing.pb.go @@ -15,7 +15,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.36.11 -// protoc v4.25.7 +// protoc v6.31.0 // source: google/devtools/cloudtrace/v2/tracing.proto package tracepb diff --git a/vendor/cloud.google.com/go/trace/apiv2/tracepb/tracing_grpc.pb.go b/vendor/cloud.google.com/go/trace/apiv2/tracepb/tracing_grpc.pb.go index ca6dc3e583..5940319beb 100644 --- a/vendor/cloud.google.com/go/trace/apiv2/tracepb/tracing_grpc.pb.go +++ b/vendor/cloud.google.com/go/trace/apiv2/tracepb/tracing_grpc.pb.go @@ -15,7 +15,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.3.0 -// - protoc v4.25.7 +// - protoc v6.31.0 // source: google/devtools/cloudtrace/v2/tracing.proto package tracepb diff --git a/vendor/cloud.google.com/go/trace/internal/version.go b/vendor/cloud.google.com/go/trace/internal/version.go index 842c041b5b..7f7d07d0b9 100644 --- a/vendor/cloud.google.com/go/trace/internal/version.go +++ b/vendor/cloud.google.com/go/trace/internal/version.go @@ -17,4 +17,4 @@ package internal // Version is the current tagged release of the library. -const Version = "1.12.0" +const Version = "1.14.0" diff --git a/vendor/github.com/googleapis/gax-go/v2/CHANGES.md b/vendor/github.com/googleapis/gax-go/v2/CHANGES.md index 6c39f72854..86c4828c8b 100644 --- a/vendor/github.com/googleapis/gax-go/v2/CHANGES.md +++ b/vendor/github.com/googleapis/gax-go/v2/CHANGES.md @@ -1,5 +1,12 @@ # Changes +## [2.21.0](https://github.com/googleapis/google-cloud-go/releases/tag/v2.21.0) (2026-04-01) + +### Features + +* hook transport telemetry into gax.Invoke and record (#496) ([d531001](https://github.com/googleapis/google-cloud-go/commit/d5310019d6c635956b61558627b13c2c2419044e)) +* update IsFeatureEnabled to not require EXPERIMENTAL (#497) ([a2a329e](https://github.com/googleapis/google-cloud-go/commit/a2a329e31d8ef8348a1ef7bea1c7072f8abcc145)) + ## [2.20.0](https://github.com/googleapis/google-cloud-go/releases/tag/v2.20.0) (2026-03-25) ### Features diff --git a/vendor/github.com/googleapis/gax-go/v2/feature.go b/vendor/github.com/googleapis/gax-go/v2/feature.go index 32e05a3234..c7a9ec88bb 100644 --- a/vendor/github.com/googleapis/gax-go/v2/feature.go +++ b/vendor/github.com/googleapis/gax-go/v2/feature.go @@ -51,11 +51,17 @@ func IsFeatureEnabled(name string) bool { featureEnabledOnce.Do(func() { featureEnabledStore = make(map[string]bool) for _, env := range os.Environ() { + prefix := "" if strings.HasPrefix(env, "GOOGLE_SDK_GO_EXPERIMENTAL_") { + prefix = "GOOGLE_SDK_GO_EXPERIMENTAL_" + } else if strings.HasPrefix(env, "GOOGLE_SDK_GO_") { + prefix = "GOOGLE_SDK_GO_" + } + if prefix != "" { // Parse "KEY=VALUE" kv := strings.SplitN(env, "=", 2) if len(kv) == 2 && strings.ToLower(kv[1]) == "true" { - key := strings.TrimPrefix(kv[0], "GOOGLE_SDK_GO_EXPERIMENTAL_") + key := strings.TrimPrefix(kv[0], prefix) featureEnabledStore[key] = true } } diff --git a/vendor/github.com/googleapis/gax-go/v2/internal/version.go b/vendor/github.com/googleapis/gax-go/v2/internal/version.go index 54dbcd337a..6ee13c8d0f 100644 --- a/vendor/github.com/googleapis/gax-go/v2/internal/version.go +++ b/vendor/github.com/googleapis/gax-go/v2/internal/version.go @@ -17,4 +17,4 @@ package internal // Version is the current tagged release of the library. -const Version = "2.20.0" +const Version = "2.21.0" diff --git a/vendor/github.com/googleapis/gax-go/v2/invoke.go b/vendor/github.com/googleapis/gax-go/v2/invoke.go index 7975dae367..ea16c3c5ac 100644 --- a/vendor/github.com/googleapis/gax-go/v2/invoke.go +++ b/vendor/github.com/googleapis/gax-go/v2/invoke.go @@ -91,6 +91,7 @@ func invoke(ctx context.Context, call APICall, settings CallSettings, sp sleeper if IsFeatureEnabled("METRICS") { start := time.Now() + ctx = InjectTransportTelemetry(ctx, &TransportTelemetryData{}) defer func() { recordMetric(ctx, settings, time.Since(start), err) }() diff --git a/vendor/github.com/googleapis/gax-go/v2/telemetry.go b/vendor/github.com/googleapis/gax-go/v2/telemetry.go index f3be81d4f6..b849b36919 100644 --- a/vendor/github.com/googleapis/gax-go/v2/telemetry.go +++ b/vendor/github.com/googleapis/gax-go/v2/telemetry.go @@ -54,9 +54,8 @@ import ( // regardless of any other documented package stability guarantees. // It should not be used by external consumers. type TransportTelemetryData struct { - serverAddress string - serverPort int - responseStatusCode int + serverAddress string + serverPort int } // SetServerAddress sets the server address. @@ -79,16 +78,6 @@ func (d *TransportTelemetryData) SetServerPort(port int) { d.serverPort = port } // regardless of any other documented package stability guarantees. func (d *TransportTelemetryData) ServerPort() int { return d.serverPort } -// SetResponseStatusCode sets the response status code. -// Experimental: This function is experimental and may be modified or removed in future versions, -// regardless of any other documented package stability guarantees. -func (d *TransportTelemetryData) SetResponseStatusCode(code int) { d.responseStatusCode = code } - -// ResponseStatusCode returns the response status code. -// Experimental: This function is experimental and may be modified or removed in future versions, -// regardless of any other documented package stability guarantees. -func (d *TransportTelemetryData) ResponseStatusCode() int { return d.responseStatusCode } - // transportTelemetryKey is the private context key used to inject TransportTelemetryData type transportTelemetryKey struct{} @@ -453,9 +442,20 @@ func recordMetric(ctx context.Context, settings CallSettings, d time.Duration, e attrs = append(attrs, settings.clientMetrics.attributes()...) errInfo := ExtractTelemetryErrorInfo(ctx, err) + + if td := ExtractTransportTelemetry(ctx); td != nil { + if td.ServerAddress() != "" { + attrs = append(attrs, attribute.String("server.address", td.ServerAddress())) + } + if td.ServerPort() != 0 { + attrs = append(attrs, attribute.Int("server.port", td.ServerPort())) + } + } + if errInfo.ErrorType != "" { attrs = append(attrs, attribute.String("error.type", errInfo.ErrorType)) } + attrs = append(attrs, attribute.String("rpc.response.status_code", errInfo.StatusCode)) if rpcMethod, ok := callctx.TelemetryFromContext(ctx, "rpc_method"); ok && rpcMethod != "" { diff --git a/vendor/modules.txt b/vendor/modules.txt index 1292abe02b..3abd8bc8eb 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -50,7 +50,7 @@ cloud.google.com/go/longrunning/autogen/longrunningpb cloud.google.com/go/monitoring/apiv3/v2 cloud.google.com/go/monitoring/apiv3/v2/monitoringpb cloud.google.com/go/monitoring/internal -# cloud.google.com/go/trace v1.12.0 +# cloud.google.com/go/trace v1.14.0 ## explicit; go 1.25.0 cloud.google.com/go/trace/apiv2 cloud.google.com/go/trace/apiv2/tracepb @@ -297,7 +297,7 @@ github.com/google/uuid ## explicit; go 1.24.11 github.com/googleapis/enterprise-certificate-proxy/client github.com/googleapis/enterprise-certificate-proxy/client/util -# github.com/googleapis/gax-go/v2 v2.20.0 +# github.com/googleapis/gax-go/v2 v2.21.0 ## explicit; go 1.25.0 github.com/googleapis/gax-go/v2 github.com/googleapis/gax-go/v2/apierror