From 806316cd94476c39e6eacea5b0f880d8f79b17b5 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Wed, 4 Mar 2026 13:04:19 -0700 Subject: [PATCH 1/2] feat(gengapic): expose telemetry attributes using gax callctx helper Replace gRPC metadata Context management with new telemetry Context helpers. refs: #1690 refs: googleapis/gax-go#472 --- internal/gengapic/gengapic.go | 12 ++-- internal/gengapic/gengapic_test.go | 60 +++++++++---------- internal/gengapic/genrest.go | 16 ++--- internal/gengapic/genrest_test.go | 39 ++++++------ .../testdata/method_GetAnotherThing.want | 2 +- .../testdata/method_GetEmptyThing.want | 2 +- .../testdata/method_GetManyThings.want | 2 +- .../method_GetManyThingsOptional.want | 2 +- .../gengapic/testdata/method_GetOneThing.want | 2 +- .../testdata/method_ServerThings.want | 2 +- internal/gengapic/testdata/rest_CustomOp.want | 2 +- internal/gengapic/testdata/rest_EmptyRPC.want | 4 +- .../gengapic/testdata/rest_HttpBodyRPC.want | 4 +- .../testdata/rest_LongrunningRPC.want | 2 +- .../testdata/rest_ServerStreamRPC.want | 4 +- internal/gengapic/testdata/rest_UnaryRPC.want | 4 +- .../gengapic/testdata/rest_UpdateRPC.want | 2 +- 17 files changed, 81 insertions(+), 80 deletions(-) diff --git a/internal/gengapic/gengapic.go b/internal/gengapic/gengapic.go index e124f36ed2..2d7e3069a7 100644 --- a/internal/gengapic/gengapic.go +++ b/internal/gengapic/gengapic.go @@ -515,12 +515,12 @@ func (g *generator) insertRequestHeaders(m *descriptorpb.MethodDescriptorProto, } if host != "" { - p(` ctx = metadata.AppendToOutgoingContext(ctx, "gcp.resource.name", fmt.Sprintf("//%s/%%v", req%s))`, host, fieldGetter(resField)) + p(` ctx = callctx.WithTelemetryContext(ctx, "gcp.resource.name", fmt.Sprintf("//%s/%%v", req%s))`, host, fieldGetter(resField)) } else { - p(` ctx = metadata.AppendToOutgoingContext(ctx, "gcp.resource.name", fmt.Sprintf("%%v", req%s))`, fieldGetter(resField)) + p(` ctx = callctx.WithTelemetryContext(ctx, "gcp.resource.name", fmt.Sprintf("%%v", req%s))`, fieldGetter(resField)) } p("}") - g.imports[pbinfo.ImportSpec{Path: "google.golang.org/grpc/metadata"}] = true + g.imports[pbinfo.ImportSpec{Path: "github.com/googleapis/gax-go/v2/callctx"}] = true g.imports[pbinfo.ImportSpec{Path: "fmt"}] = true } } @@ -545,12 +545,12 @@ func (g *generator) insertRequestHeaders(m *descriptorpb.MethodDescriptorProto, } if host != "" { - p(` ctx = metadata.AppendToOutgoingContext(ctx, "gcp.resource.name", fmt.Sprintf("//%s/%%v", req%s))`, host, fieldGetter(resField)) + p(` ctx = callctx.WithTelemetryContext(ctx, "gcp.resource.name", fmt.Sprintf("//%s/%%v", req%s))`, host, fieldGetter(resField)) } else { - p(` ctx = metadata.AppendToOutgoingContext(ctx, "gcp.resource.name", fmt.Sprintf("%%v", req%s))`, fieldGetter(resField)) + p(` ctx = callctx.WithTelemetryContext(ctx, "gcp.resource.name", fmt.Sprintf("%%v", req%s))`, fieldGetter(resField)) } p("}") - g.imports[pbinfo.ImportSpec{Path: "google.golang.org/grpc/metadata"}] = true + g.imports[pbinfo.ImportSpec{Path: "github.com/googleapis/gax-go/v2/callctx"}] = true g.imports[pbinfo.ImportSpec{Path: "fmt"}] = true } } diff --git a/internal/gengapic/gengapic_test.go b/internal/gengapic/gengapic_test.go index ab55bec01b..57d250adc1 100644 --- a/internal/gengapic/gengapic_test.go +++ b/internal/gengapic/gengapic_test.go @@ -419,11 +419,11 @@ func TestGenGRPCMethods(t *testing.T) { Options: opts, }, imports: map[pbinfo.ImportSpec]bool{ - {Path: "fmt"}: true, - {Path: "github.com/google/uuid"}: true, - {Path: "google.golang.org/grpc/metadata"}: true, - {Path: "net/url"}: true, - {Name: "mypackagepb", Path: "mypackage"}: true, + {Path: "fmt"}: true, + {Path: "github.com/google/uuid"}: true, + {Path: "github.com/googleapis/gax-go/v2/callctx"}: true, + {Path: "net/url"}: true, + {Name: "mypackagepb", Path: "mypackage"}: true, }, }, { m: &descriptorpb.MethodDescriptorProto{ @@ -433,11 +433,11 @@ func TestGenGRPCMethods(t *testing.T) { Options: opts, }, imports: map[pbinfo.ImportSpec]bool{ - {Path: "fmt"}: true, - {Path: "github.com/google/uuid"}: true, - {Path: "google.golang.org/grpc/metadata"}: true, - {Path: "net/url"}: true, - {Name: "mypackagepb", Path: "mypackage"}: true, + {Path: "fmt"}: true, + {Path: "github.com/google/uuid"}: true, + {Path: "github.com/googleapis/gax-go/v2/callctx"}: true, + {Path: "net/url"}: true, + {Name: "mypackagepb", Path: "mypackage"}: true, }, }, { @@ -448,12 +448,12 @@ func TestGenGRPCMethods(t *testing.T) { Options: opts, }, imports: map[pbinfo.ImportSpec]bool{ - {Path: "fmt"}: true, - {Path: "google.golang.org/api/iterator"}: true, - {Path: "google.golang.org/grpc/metadata"}: true, - {Path: "google.golang.org/protobuf/proto"}: true, - {Path: "net/url"}: true, - {Name: "mypackagepb", Path: "mypackage"}: true, + {Path: "fmt"}: true, + {Path: "google.golang.org/api/iterator"}: true, + {Path: "github.com/googleapis/gax-go/v2/callctx"}: true, + {Path: "google.golang.org/protobuf/proto"}: true, + {Path: "net/url"}: true, + {Name: "mypackagepb", Path: "mypackage"}: true, }, }, { m: &descriptorpb.MethodDescriptorProto{ @@ -463,12 +463,12 @@ func TestGenGRPCMethods(t *testing.T) { Options: opts, }, imports: map[pbinfo.ImportSpec]bool{ - {Path: "fmt"}: true, - {Path: "google.golang.org/api/iterator"}: true, - {Path: "google.golang.org/grpc/metadata"}: true, - {Path: "google.golang.org/protobuf/proto"}: true, - {Path: "net/url"}: true, - {Name: "mypackagepb", Path: "mypackage"}: true, + {Path: "fmt"}: true, + {Path: "google.golang.org/api/iterator"}: true, + {Path: "github.com/googleapis/gax-go/v2/callctx"}: true, + {Path: "google.golang.org/protobuf/proto"}: true, + {Path: "net/url"}: true, + {Name: "mypackagepb", Path: "mypackage"}: true, }, }, { @@ -481,9 +481,9 @@ func TestGenGRPCMethods(t *testing.T) { }, imports: map[pbinfo.ImportSpec]bool{ {Path: "fmt"}: true, - {Path: "google.golang.org/grpc/metadata"}: true, - {Path: "net/url"}: true, - {Name: "mypackagepb", Path: "mypackage"}: true, + {Path: "github.com/googleapis/gax-go/v2/callctx"}: true, + {Path: "net/url"}: true, + {Name: "mypackagepb", Path: "mypackage"}: true, }, }, { @@ -521,11 +521,11 @@ func TestGenGRPCMethods(t *testing.T) { }, imports: map[pbinfo.ImportSpec]bool{ {Path: "fmt"}: true, - {Path: "google.golang.org/grpc/metadata"}: true, - {Path: "net/url"}: true, - {Path: "regexp"}: true, - {Path: "strings"}: true, - {Name: "mypackagepb", Path: "mypackage"}: true, + {Path: "github.com/googleapis/gax-go/v2/callctx"}: true, + {Path: "net/url"}: true, + {Path: "regexp"}: true, + {Path: "strings"}: true, + {Name: "mypackagepb", Path: "mypackage"}: true, }, }, // Test for empty dynamic routing annotation, so no headers should be sent. diff --git a/internal/gengapic/genrest.go b/internal/gengapic/genrest.go index 7ebeb2259d..b101661a01 100644 --- a/internal/gengapic/genrest.go +++ b/internal/gengapic/genrest.go @@ -671,9 +671,9 @@ func (g *generator) serverStreamRESTCall(servName string, s *descriptorpb.Servic g.insertRequestHeaders(m, rest) if info != nil && g.featureEnabled(OpenTelemetryTracingFeature) { p("if gax.IsFeatureEnabled(\"TRACING\") {") - p(" ctx = metadata.AppendToOutgoingContext(ctx, \"url.template\", %q)", info.url) + p(" ctx = callctx.WithTelemetryContext(ctx, \"url.template\", %q)", info.url) p("}") - g.imports[pbinfo.ImportSpec{Path: "google.golang.org/grpc/metadata"}] = true + g.imports[pbinfo.ImportSpec{Path: "github.com/googleapis/gax-go/v2/callctx"}] = true } p("var streamClient *%s", streamClient) p("e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {") @@ -959,9 +959,9 @@ func (g *generator) lroRESTCall(servName string, m *descriptorpb.MethodDescripto g.insertRequestHeaders(m, rest) if info != nil && g.featureEnabled(OpenTelemetryTracingFeature) { p("if gax.IsFeatureEnabled(\"TRACING\") {") - p(" ctx = metadata.AppendToOutgoingContext(ctx, \"url.template\", %q)", info.url) + p(" ctx = callctx.WithTelemetryContext(ctx, \"url.template\", %q)", info.url) p("}") - g.imports[pbinfo.ImportSpec{Path: "google.golang.org/grpc/metadata"}] = true + g.imports[pbinfo.ImportSpec{Path: "github.com/googleapis/gax-go/v2/callctx"}] = true } p("unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}") p("resp := &%s.%s{}", outSpec.Name, outType.GetName()) @@ -1061,9 +1061,9 @@ func (g *generator) emptyUnaryRESTCall(servName string, m *descriptorpb.MethodDe g.insertRequestHeaders(m, rest) if info != nil && g.featureEnabled(OpenTelemetryTracingFeature) { p("if gax.IsFeatureEnabled(\"TRACING\") {") - p(" ctx = metadata.AppendToOutgoingContext(ctx, \"url.template\", %q)", info.url) + p(" ctx = callctx.WithTelemetryContext(ctx, \"url.template\", %q)", info.url) p("}") - g.imports[pbinfo.ImportSpec{Path: "google.golang.org/grpc/metadata"}] = true + g.imports[pbinfo.ImportSpec{Path: "github.com/googleapis/gax-go/v2/callctx"}] = true } p("return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {") p(` if settings.Path != "" {`) @@ -1156,9 +1156,9 @@ func (g *generator) unaryRESTCall(servName string, m *descriptorpb.MethodDescrip g.insertRequestHeaders(m, rest) if info != nil && g.featureEnabled(OpenTelemetryTracingFeature) { p("if gax.IsFeatureEnabled(\"TRACING\") {") - p(" ctx = metadata.AppendToOutgoingContext(ctx, \"url.template\", %q)", info.url) + p(" ctx = callctx.WithTelemetryContext(ctx, \"url.template\", %q)", info.url) p("}") - g.imports[pbinfo.ImportSpec{Path: "google.golang.org/grpc/metadata"}] = true + g.imports[pbinfo.ImportSpec{Path: "github.com/googleapis/gax-go/v2/callctx"}] = true } g.appendCallOpts(m) if !isHTTPBodyMessage { diff --git a/internal/gengapic/genrest_test.go b/internal/gengapic/genrest_test.go index 0fa597a9d2..44542078b5 100644 --- a/internal/gengapic/genrest_test.go +++ b/internal/gengapic/genrest_test.go @@ -762,7 +762,7 @@ func TestGenRestMethod(t *testing.T) { method: opRPC, cfg: &generatorConfig{generateAsDIREGAPIC: true, featureEnablement: map[featureID]struct{}{OpenTelemetryTracingFeature: {}}}, imports: map[pbinfo.ImportSpec]bool{ - {Path: "google.golang.org/grpc/metadata"}: true, + {Path: "github.com/googleapis/gax-go/v2/callctx"}: true, {Path: "google.golang.org/protobuf/encoding/protojson"}: true, {Path: "net/url"}: true, {Path: "fmt"}: true, @@ -774,10 +774,10 @@ func TestGenRestMethod(t *testing.T) { method: emptyRPC, cfg: &generatorConfig{featureEnablement: map[featureID]struct{}{OpenTelemetryTracingFeature: {}}}, imports: map[pbinfo.ImportSpec]bool{ - {Path: "fmt"}: true, - {Path: "github.com/google/uuid"}: true, - {Path: "google.golang.org/grpc/metadata"}: true, - {Path: "net/url"}: true, + {Path: "fmt"}: true, + {Path: "github.com/google/uuid"}: true, + {Path: "github.com/googleapis/gax-go/v2/callctx"}: true, + {Path: "net/url"}: true, {Name: "foopb", Path: "google.golang.org/genproto/cloud/foo/v1"}: true, }, }, @@ -786,14 +786,14 @@ func TestGenRestMethod(t *testing.T) { method: unaryRPC, cfg: &generatorConfig{restNumericEnum: true, featureEnablement: map[featureID]struct{}{OpenTelemetryTracingFeature: {}}}, imports: map[pbinfo.ImportSpec]bool{ - {Path: "bytes"}: true, - {Path: "fmt"}: true, - {Path: "github.com/google/uuid"}: true, - {Path: "google.golang.org/grpc/metadata"}: true, + {Path: "bytes"}: true, + {Path: "fmt"}: true, + {Path: "github.com/google/uuid"}: true, + {Path: "github.com/googleapis/gax-go/v2/callctx"}: true, {Path: "google.golang.org/protobuf/encoding/protojson"}: true, - {Path: "net/url"}: true, - {Path: "regexp"}: true, - {Path: "strings"}: true, + {Path: "net/url"}: true, + {Path: "regexp"}: true, + {Path: "strings"}: true, {Name: "foopb", Path: "google.golang.org/genproto/cloud/foo/v1"}: true, }, }, @@ -820,10 +820,11 @@ func TestGenRestMethod(t *testing.T) { {Path: "context"}: true, {Path: "errors"}: true, {Path: "fmt"}: true, - {Path: "net/url"}: true, - {Path: "regexp"}: true, - {Path: "strings"}: true, - {Path: "google.golang.org/grpc/metadata"}: true, + {Path: "github.com/googleapis/gax-go/v2/callctx"}: true, + {Path: "net/url"}: true, + {Path: "regexp"}: true, + {Path: "strings"}: true, + {Path: "google.golang.org/grpc/metadata"}: true, {Path: "google.golang.org/protobuf/encoding/protojson"}: true, {Name: "foopb", Path: "google.golang.org/genproto/cloud/foo/v1"}: true, }, @@ -843,7 +844,7 @@ func TestGenRestMethod(t *testing.T) { method: lroRPC, cfg: &generatorConfig{transports: []transport{rest}, featureEnablement: map[featureID]struct{}{OpenTelemetryTracingFeature: {}}}, imports: map[pbinfo.ImportSpec]bool{ - {Path: "google.golang.org/grpc/metadata"}: true, + {Path: "github.com/googleapis/gax-go/v2/callctx"}: true, {Path: "bytes"}: true, {Path: "cloud.google.com/go/longrunning"}: true, {Path: "fmt"}: true, @@ -860,7 +861,7 @@ func TestGenRestMethod(t *testing.T) { imports: map[pbinfo.ImportSpec]bool{ {Path: "bytes"}: true, {Path: "fmt"}: true, - {Path: "google.golang.org/grpc/metadata"}: true, + {Path: "github.com/googleapis/gax-go/v2/callctx"}: true, {Path: "google.golang.org/protobuf/encoding/protojson"}: true, {Path: "net/url"}: true, {Path: "regexp"}: true, @@ -874,7 +875,7 @@ func TestGenRestMethod(t *testing.T) { method: updateRPC, cfg: &generatorConfig{restNumericEnum: true, featureEnablement: map[featureID]struct{}{OpenTelemetryTracingFeature: {}}}, imports: map[pbinfo.ImportSpec]bool{ - {Path: "google.golang.org/grpc/metadata"}: true, + {Path: "github.com/googleapis/gax-go/v2/callctx"}: true, {Path: "bytes"}: true, {Path: "fmt"}: true, {Path: "google.golang.org/protobuf/encoding/protojson"}: true, diff --git a/internal/gengapic/testdata/method_GetAnotherThing.want b/internal/gengapic/testdata/method_GetAnotherThing.want index 0c6153adf7..145d2dfd81 100644 --- a/internal/gengapic/testdata/method_GetAnotherThing.want +++ b/internal/gengapic/testdata/method_GetAnotherThing.want @@ -31,7 +31,7 @@ func (c *fooGRPCClient) GetAnotherThing(ctx context.Context, req *mypackagepb.In hds = append(c.xGoogHeaders, hds...) ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) if gax.IsFeatureEnabled("TRACING") { - ctx = metadata.AppendToOutgoingContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) + ctx = callctx.WithTelemetryContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) } opts = append((*c.CallOptions).GetAnotherThing[0:len((*c.CallOptions).GetAnotherThing):len((*c.CallOptions).GetAnotherThing)], opts...) var resp *mypackagepb.OutputType diff --git a/internal/gengapic/testdata/method_GetEmptyThing.want b/internal/gengapic/testdata/method_GetEmptyThing.want index 532f01e1d7..d26848a191 100644 --- a/internal/gengapic/testdata/method_GetEmptyThing.want +++ b/internal/gengapic/testdata/method_GetEmptyThing.want @@ -4,7 +4,7 @@ func (c *fooGRPCClient) GetEmptyThing(ctx context.Context, req *mypackagepb.Inpu hds = append(c.xGoogHeaders, hds...) ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) if gax.IsFeatureEnabled("TRACING") { - ctx = metadata.AppendToOutgoingContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) + ctx = callctx.WithTelemetryContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) } if req != nil && req.RequestId == nil { req.RequestId = proto.String(uuid.NewString()) diff --git a/internal/gengapic/testdata/method_GetManyThings.want b/internal/gengapic/testdata/method_GetManyThings.want index 0c621bfac9..ba698abb17 100644 --- a/internal/gengapic/testdata/method_GetManyThings.want +++ b/internal/gengapic/testdata/method_GetManyThings.want @@ -4,7 +4,7 @@ func (c *fooGRPCClient) GetManyThings(ctx context.Context, req *mypackagepb.Page hds = append(c.xGoogHeaders, hds...) ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) if gax.IsFeatureEnabled("TRACING") { - ctx = metadata.AppendToOutgoingContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) + ctx = callctx.WithTelemetryContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) } opts = append((*c.CallOptions).GetManyThings[0:len((*c.CallOptions).GetManyThings):len((*c.CallOptions).GetManyThings)], opts...) it := &StringIterator{} diff --git a/internal/gengapic/testdata/method_GetManyThingsOptional.want b/internal/gengapic/testdata/method_GetManyThingsOptional.want index 00fca00884..3429a636d0 100644 --- a/internal/gengapic/testdata/method_GetManyThingsOptional.want +++ b/internal/gengapic/testdata/method_GetManyThingsOptional.want @@ -4,7 +4,7 @@ func (c *fooGRPCClient) GetManyThingsOptional(ctx context.Context, req *mypackag hds = append(c.xGoogHeaders, hds...) ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) if gax.IsFeatureEnabled("TRACING") { - ctx = metadata.AppendToOutgoingContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) + ctx = callctx.WithTelemetryContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) } opts = append((*c.CallOptions).GetManyThingsOptional[0:len((*c.CallOptions).GetManyThingsOptional):len((*c.CallOptions).GetManyThingsOptional)], opts...) it := &StringIterator{} diff --git a/internal/gengapic/testdata/method_GetOneThing.want b/internal/gengapic/testdata/method_GetOneThing.want index 8fc8f2d6e9..5932e4afcd 100644 --- a/internal/gengapic/testdata/method_GetOneThing.want +++ b/internal/gengapic/testdata/method_GetOneThing.want @@ -4,7 +4,7 @@ func (c *fooGRPCClient) GetOneThing(ctx context.Context, req *mypackagepb.InputT hds = append(c.xGoogHeaders, hds...) ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) if gax.IsFeatureEnabled("TRACING") { - ctx = metadata.AppendToOutgoingContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) + ctx = callctx.WithTelemetryContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) } if req != nil && req.RequestId == nil { req.RequestId = proto.String(uuid.NewString()) diff --git a/internal/gengapic/testdata/method_ServerThings.want b/internal/gengapic/testdata/method_ServerThings.want index f2694b8cd5..63a022a65a 100644 --- a/internal/gengapic/testdata/method_ServerThings.want +++ b/internal/gengapic/testdata/method_ServerThings.want @@ -4,7 +4,7 @@ func (c *fooGRPCClient) ServerThings(ctx context.Context, req *mypackagepb.Input hds = append(c.xGoogHeaders, hds...) ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) if gax.IsFeatureEnabled("TRACING") { - ctx = metadata.AppendToOutgoingContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) + ctx = callctx.WithTelemetryContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) } opts = append((*c.CallOptions).ServerThings[0:len((*c.CallOptions).ServerThings):len((*c.CallOptions).ServerThings)], opts...) var resp mypackagepb.Foo_ServerThingsClient diff --git a/internal/gengapic/testdata/rest_CustomOp.want b/internal/gengapic/testdata/rest_CustomOp.want index d7fcffedc2..81606385b2 100644 --- a/internal/gengapic/testdata/rest_CustomOp.want +++ b/internal/gengapic/testdata/rest_CustomOp.want @@ -20,7 +20,7 @@ func (c *fooRESTClient) CustomOp(ctx context.Context, req *foopb.Foo, opts ...ga hds := append(c.xGoogHeaders, "Content-Type", "application/json") headers := gax.BuildHeaders(ctx, hds...) if gax.IsFeatureEnabled("TRACING") { - ctx = metadata.AppendToOutgoingContext(ctx, "url.template", "/v1/foo") + ctx = callctx.WithTelemetryContext(ctx, "url.template", "/v1/foo") } opts = append((*c.CallOptions).CustomOp[0:len((*c.CallOptions).CustomOp):len((*c.CallOptions).CustomOp)], opts...) unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} diff --git a/internal/gengapic/testdata/rest_EmptyRPC.want b/internal/gengapic/testdata/rest_EmptyRPC.want index f053dff964..41cd870007 100644 --- a/internal/gengapic/testdata/rest_EmptyRPC.want +++ b/internal/gengapic/testdata/rest_EmptyRPC.want @@ -23,10 +23,10 @@ func (c *fooRESTClient) EmptyRPC(ctx context.Context, req *foopb.Foo, opts ...ga hds = append(hds, "Content-Type", "application/json") headers := gax.BuildHeaders(ctx, hds...) if gax.IsFeatureEnabled("TRACING") { - ctx = metadata.AppendToOutgoingContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) + ctx = callctx.WithTelemetryContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) } if gax.IsFeatureEnabled("TRACING") { - ctx = metadata.AppendToOutgoingContext(ctx, "url.template", "/v1/foo/{other=*}") + ctx = callctx.WithTelemetryContext(ctx, "url.template", "/v1/foo/{other=*}") } return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { if settings.Path != "" { diff --git a/internal/gengapic/testdata/rest_HttpBodyRPC.want b/internal/gengapic/testdata/rest_HttpBodyRPC.want index e8c2fdf645..d2da40075a 100644 --- a/internal/gengapic/testdata/rest_HttpBodyRPC.want +++ b/internal/gengapic/testdata/rest_HttpBodyRPC.want @@ -27,10 +27,10 @@ func (c *fooRESTClient) HttpBodyRPC(ctx context.Context, req *foopb.Foo, opts .. hds = append(hds, "Content-Type", "application/json") headers := gax.BuildHeaders(ctx, hds...) if gax.IsFeatureEnabled("TRACING") { - ctx = metadata.AppendToOutgoingContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) + ctx = callctx.WithTelemetryContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) } if gax.IsFeatureEnabled("TRACING") { - ctx = metadata.AppendToOutgoingContext(ctx, "url.template", "/v1/foo") + ctx = callctx.WithTelemetryContext(ctx, "url.template", "/v1/foo") } opts = append((*c.CallOptions).HttpBodyRPC[0:len((*c.CallOptions).HttpBodyRPC):len((*c.CallOptions).HttpBodyRPC)], opts...) resp := &httpbodypb.HttpBody{} diff --git a/internal/gengapic/testdata/rest_LongrunningRPC.want b/internal/gengapic/testdata/rest_LongrunningRPC.want index f824cc77d0..b6ef7564b3 100644 --- a/internal/gengapic/testdata/rest_LongrunningRPC.want +++ b/internal/gengapic/testdata/rest_LongrunningRPC.want @@ -18,7 +18,7 @@ func (c *fooRESTClient) LongrunningRPC(ctx context.Context, req *foopb.Foo, opts hds := append(c.xGoogHeaders, "Content-Type", "application/json") headers := gax.BuildHeaders(ctx, hds...) if gax.IsFeatureEnabled("TRACING") { - ctx = metadata.AppendToOutgoingContext(ctx, "url.template", "/v1/foo") + ctx = callctx.WithTelemetryContext(ctx, "url.template", "/v1/foo") } unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} resp := &longrunningpb.Operation{} diff --git a/internal/gengapic/testdata/rest_ServerStreamRPC.want b/internal/gengapic/testdata/rest_ServerStreamRPC.want index 35a29601d4..6a2ad8cef5 100644 --- a/internal/gengapic/testdata/rest_ServerStreamRPC.want +++ b/internal/gengapic/testdata/rest_ServerStreamRPC.want @@ -27,10 +27,10 @@ func (c *fooRESTClient) ServerStreamRPC(ctx context.Context, req *foopb.Foo, opt hds = append(hds, "Content-Type", "application/json") headers := gax.BuildHeaders(ctx, hds...) if gax.IsFeatureEnabled("TRACING") { - ctx = metadata.AppendToOutgoingContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) + ctx = callctx.WithTelemetryContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) } if gax.IsFeatureEnabled("TRACING") { - ctx = metadata.AppendToOutgoingContext(ctx, "url.template", "/v1/foo") + ctx = callctx.WithTelemetryContext(ctx, "url.template", "/v1/foo") } var streamClient *serverStreamRPCRESTStreamClient e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { diff --git a/internal/gengapic/testdata/rest_UnaryRPC.want b/internal/gengapic/testdata/rest_UnaryRPC.want index 965fca2648..8688be4163 100644 --- a/internal/gengapic/testdata/rest_UnaryRPC.want +++ b/internal/gengapic/testdata/rest_UnaryRPC.want @@ -35,10 +35,10 @@ func (c *fooRESTClient) UnaryRPC(ctx context.Context, req *foopb.Foo, opts ...ga hds = append(hds, "Content-Type", "application/json") headers := gax.BuildHeaders(ctx, hds...) if gax.IsFeatureEnabled("TRACING") { - ctx = metadata.AppendToOutgoingContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) + ctx = callctx.WithTelemetryContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) } if gax.IsFeatureEnabled("TRACING") { - ctx = metadata.AppendToOutgoingContext(ctx, "url.template", "/v1/foo") + ctx = callctx.WithTelemetryContext(ctx, "url.template", "/v1/foo") } opts = append((*c.CallOptions).UnaryRPC[0:len((*c.CallOptions).UnaryRPC):len((*c.CallOptions).UnaryRPC)], opts...) unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} diff --git a/internal/gengapic/testdata/rest_UpdateRPC.want b/internal/gengapic/testdata/rest_UpdateRPC.want index 73e43aa115..d528c3783e 100644 --- a/internal/gengapic/testdata/rest_UpdateRPC.want +++ b/internal/gengapic/testdata/rest_UpdateRPC.want @@ -40,7 +40,7 @@ func (c *fooRESTClient) UpdateRPC(ctx context.Context, req *foopb.UpdateRequest, hds := append(c.xGoogHeaders, "Content-Type", "application/json") headers := gax.BuildHeaders(ctx, hds...) if gax.IsFeatureEnabled("TRACING") { - ctx = metadata.AppendToOutgoingContext(ctx, "url.template", "/v1/foo") + ctx = callctx.WithTelemetryContext(ctx, "url.template", "/v1/foo") } opts = append((*c.CallOptions).UpdateRPC[0:len((*c.CallOptions).UpdateRPC):len((*c.CallOptions).UpdateRPC)], opts...) unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} From 326c4352c1f6cf593ef0a7479c6064fc3ea7394d Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Thu, 5 Mar 2026 15:48:41 -0700 Subject: [PATCH 2/2] update telemetry context keys --- internal/gengapic/gengapic.go | 8 ++++---- internal/gengapic/genrest.go | 8 ++++---- internal/gengapic/testdata/method_GetAnotherThing.want | 2 +- internal/gengapic/testdata/method_GetEmptyThing.want | 2 +- internal/gengapic/testdata/method_GetManyThings.want | 2 +- .../gengapic/testdata/method_GetManyThingsOptional.want | 2 +- internal/gengapic/testdata/method_GetOneThing.want | 2 +- internal/gengapic/testdata/method_ServerThings.want | 2 +- internal/gengapic/testdata/rest_CustomOp.want | 2 +- internal/gengapic/testdata/rest_EmptyRPC.want | 4 ++-- internal/gengapic/testdata/rest_HttpBodyRPC.want | 4 ++-- internal/gengapic/testdata/rest_LongrunningRPC.want | 2 +- internal/gengapic/testdata/rest_ServerStreamRPC.want | 4 ++-- internal/gengapic/testdata/rest_UnaryRPC.want | 4 ++-- internal/gengapic/testdata/rest_UpdateRPC.want | 2 +- 15 files changed, 25 insertions(+), 25 deletions(-) diff --git a/internal/gengapic/gengapic.go b/internal/gengapic/gengapic.go index 2d7e3069a7..7686c7dbdb 100644 --- a/internal/gengapic/gengapic.go +++ b/internal/gengapic/gengapic.go @@ -515,9 +515,9 @@ func (g *generator) insertRequestHeaders(m *descriptorpb.MethodDescriptorProto, } if host != "" { - p(` ctx = callctx.WithTelemetryContext(ctx, "gcp.resource.name", fmt.Sprintf("//%s/%%v", req%s))`, host, fieldGetter(resField)) + p(` ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//%s/%%v", req%s))`, host, fieldGetter(resField)) } else { - p(` ctx = callctx.WithTelemetryContext(ctx, "gcp.resource.name", fmt.Sprintf("%%v", req%s))`, fieldGetter(resField)) + p(` ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("%%v", req%s))`, fieldGetter(resField)) } p("}") g.imports[pbinfo.ImportSpec{Path: "github.com/googleapis/gax-go/v2/callctx"}] = true @@ -545,9 +545,9 @@ func (g *generator) insertRequestHeaders(m *descriptorpb.MethodDescriptorProto, } if host != "" { - p(` ctx = callctx.WithTelemetryContext(ctx, "gcp.resource.name", fmt.Sprintf("//%s/%%v", req%s))`, host, fieldGetter(resField)) + p(` ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//%s/%%v", req%s))`, host, fieldGetter(resField)) } else { - p(` ctx = callctx.WithTelemetryContext(ctx, "gcp.resource.name", fmt.Sprintf("%%v", req%s))`, fieldGetter(resField)) + p(` ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("%%v", req%s))`, fieldGetter(resField)) } p("}") g.imports[pbinfo.ImportSpec{Path: "github.com/googleapis/gax-go/v2/callctx"}] = true diff --git a/internal/gengapic/genrest.go b/internal/gengapic/genrest.go index b101661a01..46e7c21423 100644 --- a/internal/gengapic/genrest.go +++ b/internal/gengapic/genrest.go @@ -671,7 +671,7 @@ func (g *generator) serverStreamRESTCall(servName string, s *descriptorpb.Servic g.insertRequestHeaders(m, rest) if info != nil && g.featureEnabled(OpenTelemetryTracingFeature) { p("if gax.IsFeatureEnabled(\"TRACING\") {") - p(" ctx = callctx.WithTelemetryContext(ctx, \"url.template\", %q)", info.url) + p(" ctx = callctx.WithTelemetryContext(ctx, \"url_template\", %q)", info.url) p("}") g.imports[pbinfo.ImportSpec{Path: "github.com/googleapis/gax-go/v2/callctx"}] = true } @@ -959,7 +959,7 @@ func (g *generator) lroRESTCall(servName string, m *descriptorpb.MethodDescripto g.insertRequestHeaders(m, rest) if info != nil && g.featureEnabled(OpenTelemetryTracingFeature) { p("if gax.IsFeatureEnabled(\"TRACING\") {") - p(" ctx = callctx.WithTelemetryContext(ctx, \"url.template\", %q)", info.url) + p(" ctx = callctx.WithTelemetryContext(ctx, \"url_template\", %q)", info.url) p("}") g.imports[pbinfo.ImportSpec{Path: "github.com/googleapis/gax-go/v2/callctx"}] = true } @@ -1061,7 +1061,7 @@ func (g *generator) emptyUnaryRESTCall(servName string, m *descriptorpb.MethodDe g.insertRequestHeaders(m, rest) if info != nil && g.featureEnabled(OpenTelemetryTracingFeature) { p("if gax.IsFeatureEnabled(\"TRACING\") {") - p(" ctx = callctx.WithTelemetryContext(ctx, \"url.template\", %q)", info.url) + p(" ctx = callctx.WithTelemetryContext(ctx, \"url_template\", %q)", info.url) p("}") g.imports[pbinfo.ImportSpec{Path: "github.com/googleapis/gax-go/v2/callctx"}] = true } @@ -1156,7 +1156,7 @@ func (g *generator) unaryRESTCall(servName string, m *descriptorpb.MethodDescrip g.insertRequestHeaders(m, rest) if info != nil && g.featureEnabled(OpenTelemetryTracingFeature) { p("if gax.IsFeatureEnabled(\"TRACING\") {") - p(" ctx = callctx.WithTelemetryContext(ctx, \"url.template\", %q)", info.url) + p(" ctx = callctx.WithTelemetryContext(ctx, \"url_template\", %q)", info.url) p("}") g.imports[pbinfo.ImportSpec{Path: "github.com/googleapis/gax-go/v2/callctx"}] = true } diff --git a/internal/gengapic/testdata/method_GetAnotherThing.want b/internal/gengapic/testdata/method_GetAnotherThing.want index 145d2dfd81..bc804dedfd 100644 --- a/internal/gengapic/testdata/method_GetAnotherThing.want +++ b/internal/gengapic/testdata/method_GetAnotherThing.want @@ -31,7 +31,7 @@ func (c *fooGRPCClient) GetAnotherThing(ctx context.Context, req *mypackagepb.In hds = append(c.xGoogHeaders, hds...) ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) if gax.IsFeatureEnabled("TRACING") { - ctx = callctx.WithTelemetryContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) + ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) } opts = append((*c.CallOptions).GetAnotherThing[0:len((*c.CallOptions).GetAnotherThing):len((*c.CallOptions).GetAnotherThing)], opts...) var resp *mypackagepb.OutputType diff --git a/internal/gengapic/testdata/method_GetEmptyThing.want b/internal/gengapic/testdata/method_GetEmptyThing.want index d26848a191..cc5a6bf56e 100644 --- a/internal/gengapic/testdata/method_GetEmptyThing.want +++ b/internal/gengapic/testdata/method_GetEmptyThing.want @@ -4,7 +4,7 @@ func (c *fooGRPCClient) GetEmptyThing(ctx context.Context, req *mypackagepb.Inpu hds = append(c.xGoogHeaders, hds...) ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) if gax.IsFeatureEnabled("TRACING") { - ctx = callctx.WithTelemetryContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) + ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) } if req != nil && req.RequestId == nil { req.RequestId = proto.String(uuid.NewString()) diff --git a/internal/gengapic/testdata/method_GetManyThings.want b/internal/gengapic/testdata/method_GetManyThings.want index ba698abb17..446d6b0caf 100644 --- a/internal/gengapic/testdata/method_GetManyThings.want +++ b/internal/gengapic/testdata/method_GetManyThings.want @@ -4,7 +4,7 @@ func (c *fooGRPCClient) GetManyThings(ctx context.Context, req *mypackagepb.Page hds = append(c.xGoogHeaders, hds...) ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) if gax.IsFeatureEnabled("TRACING") { - ctx = callctx.WithTelemetryContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) + ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) } opts = append((*c.CallOptions).GetManyThings[0:len((*c.CallOptions).GetManyThings):len((*c.CallOptions).GetManyThings)], opts...) it := &StringIterator{} diff --git a/internal/gengapic/testdata/method_GetManyThingsOptional.want b/internal/gengapic/testdata/method_GetManyThingsOptional.want index 3429a636d0..5c37302d57 100644 --- a/internal/gengapic/testdata/method_GetManyThingsOptional.want +++ b/internal/gengapic/testdata/method_GetManyThingsOptional.want @@ -4,7 +4,7 @@ func (c *fooGRPCClient) GetManyThingsOptional(ctx context.Context, req *mypackag hds = append(c.xGoogHeaders, hds...) ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) if gax.IsFeatureEnabled("TRACING") { - ctx = callctx.WithTelemetryContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) + ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) } opts = append((*c.CallOptions).GetManyThingsOptional[0:len((*c.CallOptions).GetManyThingsOptional):len((*c.CallOptions).GetManyThingsOptional)], opts...) it := &StringIterator{} diff --git a/internal/gengapic/testdata/method_GetOneThing.want b/internal/gengapic/testdata/method_GetOneThing.want index 5932e4afcd..7e1589c3db 100644 --- a/internal/gengapic/testdata/method_GetOneThing.want +++ b/internal/gengapic/testdata/method_GetOneThing.want @@ -4,7 +4,7 @@ func (c *fooGRPCClient) GetOneThing(ctx context.Context, req *mypackagepb.InputT hds = append(c.xGoogHeaders, hds...) ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) if gax.IsFeatureEnabled("TRACING") { - ctx = callctx.WithTelemetryContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) + ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) } if req != nil && req.RequestId == nil { req.RequestId = proto.String(uuid.NewString()) diff --git a/internal/gengapic/testdata/method_ServerThings.want b/internal/gengapic/testdata/method_ServerThings.want index 63a022a65a..5d3fd118de 100644 --- a/internal/gengapic/testdata/method_ServerThings.want +++ b/internal/gengapic/testdata/method_ServerThings.want @@ -4,7 +4,7 @@ func (c *fooGRPCClient) ServerThings(ctx context.Context, req *mypackagepb.Input hds = append(c.xGoogHeaders, hds...) ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) if gax.IsFeatureEnabled("TRACING") { - ctx = callctx.WithTelemetryContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) + ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) } opts = append((*c.CallOptions).ServerThings[0:len((*c.CallOptions).ServerThings):len((*c.CallOptions).ServerThings)], opts...) var resp mypackagepb.Foo_ServerThingsClient diff --git a/internal/gengapic/testdata/rest_CustomOp.want b/internal/gengapic/testdata/rest_CustomOp.want index 81606385b2..39612b524b 100644 --- a/internal/gengapic/testdata/rest_CustomOp.want +++ b/internal/gengapic/testdata/rest_CustomOp.want @@ -20,7 +20,7 @@ func (c *fooRESTClient) CustomOp(ctx context.Context, req *foopb.Foo, opts ...ga hds := append(c.xGoogHeaders, "Content-Type", "application/json") headers := gax.BuildHeaders(ctx, hds...) if gax.IsFeatureEnabled("TRACING") { - ctx = callctx.WithTelemetryContext(ctx, "url.template", "/v1/foo") + ctx = callctx.WithTelemetryContext(ctx, "url_template", "/v1/foo") } opts = append((*c.CallOptions).CustomOp[0:len((*c.CallOptions).CustomOp):len((*c.CallOptions).CustomOp)], opts...) unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} diff --git a/internal/gengapic/testdata/rest_EmptyRPC.want b/internal/gengapic/testdata/rest_EmptyRPC.want index 41cd870007..2bfb3f334d 100644 --- a/internal/gengapic/testdata/rest_EmptyRPC.want +++ b/internal/gengapic/testdata/rest_EmptyRPC.want @@ -23,10 +23,10 @@ func (c *fooRESTClient) EmptyRPC(ctx context.Context, req *foopb.Foo, opts ...ga hds = append(hds, "Content-Type", "application/json") headers := gax.BuildHeaders(ctx, hds...) if gax.IsFeatureEnabled("TRACING") { - ctx = callctx.WithTelemetryContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) + ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) } if gax.IsFeatureEnabled("TRACING") { - ctx = callctx.WithTelemetryContext(ctx, "url.template", "/v1/foo/{other=*}") + ctx = callctx.WithTelemetryContext(ctx, "url_template", "/v1/foo/{other=*}") } return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { if settings.Path != "" { diff --git a/internal/gengapic/testdata/rest_HttpBodyRPC.want b/internal/gengapic/testdata/rest_HttpBodyRPC.want index d2da40075a..afa7072345 100644 --- a/internal/gengapic/testdata/rest_HttpBodyRPC.want +++ b/internal/gengapic/testdata/rest_HttpBodyRPC.want @@ -27,10 +27,10 @@ func (c *fooRESTClient) HttpBodyRPC(ctx context.Context, req *foopb.Foo, opts .. hds = append(hds, "Content-Type", "application/json") headers := gax.BuildHeaders(ctx, hds...) if gax.IsFeatureEnabled("TRACING") { - ctx = callctx.WithTelemetryContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) + ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) } if gax.IsFeatureEnabled("TRACING") { - ctx = callctx.WithTelemetryContext(ctx, "url.template", "/v1/foo") + ctx = callctx.WithTelemetryContext(ctx, "url_template", "/v1/foo") } opts = append((*c.CallOptions).HttpBodyRPC[0:len((*c.CallOptions).HttpBodyRPC):len((*c.CallOptions).HttpBodyRPC)], opts...) resp := &httpbodypb.HttpBody{} diff --git a/internal/gengapic/testdata/rest_LongrunningRPC.want b/internal/gengapic/testdata/rest_LongrunningRPC.want index b6ef7564b3..b267cf307f 100644 --- a/internal/gengapic/testdata/rest_LongrunningRPC.want +++ b/internal/gengapic/testdata/rest_LongrunningRPC.want @@ -18,7 +18,7 @@ func (c *fooRESTClient) LongrunningRPC(ctx context.Context, req *foopb.Foo, opts hds := append(c.xGoogHeaders, "Content-Type", "application/json") headers := gax.BuildHeaders(ctx, hds...) if gax.IsFeatureEnabled("TRACING") { - ctx = callctx.WithTelemetryContext(ctx, "url.template", "/v1/foo") + ctx = callctx.WithTelemetryContext(ctx, "url_template", "/v1/foo") } unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} resp := &longrunningpb.Operation{} diff --git a/internal/gengapic/testdata/rest_ServerStreamRPC.want b/internal/gengapic/testdata/rest_ServerStreamRPC.want index 6a2ad8cef5..cc52ca2eac 100644 --- a/internal/gengapic/testdata/rest_ServerStreamRPC.want +++ b/internal/gengapic/testdata/rest_ServerStreamRPC.want @@ -27,10 +27,10 @@ func (c *fooRESTClient) ServerStreamRPC(ctx context.Context, req *foopb.Foo, opt hds = append(hds, "Content-Type", "application/json") headers := gax.BuildHeaders(ctx, hds...) if gax.IsFeatureEnabled("TRACING") { - ctx = callctx.WithTelemetryContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) + ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) } if gax.IsFeatureEnabled("TRACING") { - ctx = callctx.WithTelemetryContext(ctx, "url.template", "/v1/foo") + ctx = callctx.WithTelemetryContext(ctx, "url_template", "/v1/foo") } var streamClient *serverStreamRPCRESTStreamClient e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { diff --git a/internal/gengapic/testdata/rest_UnaryRPC.want b/internal/gengapic/testdata/rest_UnaryRPC.want index 8688be4163..1cd47e2b47 100644 --- a/internal/gengapic/testdata/rest_UnaryRPC.want +++ b/internal/gengapic/testdata/rest_UnaryRPC.want @@ -35,10 +35,10 @@ func (c *fooRESTClient) UnaryRPC(ctx context.Context, req *foopb.Foo, opts ...ga hds = append(hds, "Content-Type", "application/json") headers := gax.BuildHeaders(ctx, hds...) if gax.IsFeatureEnabled("TRACING") { - ctx = callctx.WithTelemetryContext(ctx, "gcp.resource.name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) + ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//foo.googleapis.com/%v", req.GetOther())) } if gax.IsFeatureEnabled("TRACING") { - ctx = callctx.WithTelemetryContext(ctx, "url.template", "/v1/foo") + ctx = callctx.WithTelemetryContext(ctx, "url_template", "/v1/foo") } opts = append((*c.CallOptions).UnaryRPC[0:len((*c.CallOptions).UnaryRPC):len((*c.CallOptions).UnaryRPC)], opts...) unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} diff --git a/internal/gengapic/testdata/rest_UpdateRPC.want b/internal/gengapic/testdata/rest_UpdateRPC.want index d528c3783e..1614175221 100644 --- a/internal/gengapic/testdata/rest_UpdateRPC.want +++ b/internal/gengapic/testdata/rest_UpdateRPC.want @@ -40,7 +40,7 @@ func (c *fooRESTClient) UpdateRPC(ctx context.Context, req *foopb.UpdateRequest, hds := append(c.xGoogHeaders, "Content-Type", "application/json") headers := gax.BuildHeaders(ctx, hds...) if gax.IsFeatureEnabled("TRACING") { - ctx = callctx.WithTelemetryContext(ctx, "url.template", "/v1/foo") + ctx = callctx.WithTelemetryContext(ctx, "url_template", "/v1/foo") } opts = append((*c.CallOptions).UpdateRPC[0:len((*c.CallOptions).UpdateRPC):len((*c.CallOptions).UpdateRPC)], opts...) unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}