Skip to content

feat(gengapic): expose resource names and static identity for OpenTelemetry tracing#1690

Merged
quartzmo merged 8 commits intogoogleapis:mainfrom
quartzmo:otel-tracing-attributes
Feb 3, 2026
Merged

feat(gengapic): expose resource names and static identity for OpenTelemetry tracing#1690
quartzmo merged 8 commits intogoogleapis:mainfrom
quartzmo:otel-tracing-attributes

Conversation

@quartzmo
Copy link
Copy Markdown
Member

@quartzmo quartzmo commented Jan 27, 2026

In this PR:

  • Service Identity Attributes (Phase 1): Updated NewClient (gRPC) and NewRESTClient (HTTP) generation to include gcp.client.version (via getVersionClient()) and gcp.client.repo ("googleapis/google-cloud-go") in the WithTelemetryAttributes internal option.
  • AIP-Compliant Resource Identification (Phase 2a): Implemented a resourceNameField helper that scans request fields for the google.api.resource_reference annotation, including tie-breaking logic that prioritizes fields appearing in the HTTP path pattern.
  • Canonical Prefixing: Updated resource name injection to prepend the Service Data Host (e.g., fmt.Sprintf("//service.host/%v", req.GetResourceNameField())).
  • REST Span Renaming: Updated REST method generation to inject the url.template metadata key containing the raw HTTP path pattern.
  • Test Verification: Updated gengapic_test.go and genrest_test.go fixtures to include resource_reference and default_host, and regenerated all golden files.
  • Tracing Allow-listing: Add a gated feature to gate tracing to a strictly defined list of services (test canaries, early adopters).

Missing from this PR:

Heuristic Logic
  • Vocabulary Learning: Implement logic to scan service definitions at generation-time and build a vocabulary of valid resource types (e.g., projects, instances, buckets) from literals in HTTP path patterns.
  • Path Reconstruction: Implement logic to parse "exploded" HTTP paths and generate code to reassemble multiple request fields into a single "Canonical Relative Resource Name."
  • Path Pruning: Enhance the path parser to identify and prune non-resource segments (e.g., custom verbs like :access or sub-resource actions) from the end of the reconstructed name.
  • Heuristic Logic Allow-listing: Add a configuration mechanism to gate this advanced heuristic logic to a strictly defined list of legacy services (Compute Engine, Cloud SQL, BigQuery).

…emetry tracing

Modify grpcClientOptions and restClientOptions to populate internaloption.WithTelemetryAttributes.

Modify insertRequestHeaders to expose resource names via metadata.AppendToOutgoingContext.
@quartzmo quartzmo force-pushed the otel-tracing-attributes branch from ba42568 to f5f0947 Compare January 29, 2026 00:36
@quartzmo quartzmo marked this pull request as ready for review January 30, 2026 20:26
@quartzmo quartzmo requested a review from a team January 30, 2026 20:26
@quartzmo quartzmo force-pushed the otel-tracing-attributes branch from ca73707 to 1dd4a39 Compare January 30, 2026 21:39
Copy link
Copy Markdown
Contributor

@shollyman shollyman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally LGTM.

Something we'll probably want to think about is whether having a matrix-like approach to golden testfiles is going to be useful, so we can validate the expectations with different generator features being enabled. That's a problem we can shift to tomorrow, however.

@westarle
Copy link
Copy Markdown
Contributor

westarle commented Feb 2, 2026

This LGTM.

Something to consider for a future Issue/PR: for both URL templates and resource names we are selecting a 'template' in the generator to include in the telemetry. This might not match exactly the URL template or resource name entered by the customer, in the case where there are multiple HTTP bindings or multiple resource reference fields and the "wrong" one is selected by the generator. It could be more correct (but more complex) to select the template based on the actual fields present at request time.

I'd like to see how this PR performs before planning that work.

As for follow-ups in the "Missing" list, I would just add:

  • gcp.client.artifact -> the Go module path or similar

@quartzmo quartzmo merged commit 1dad92a into googleapis:main Feb 3, 2026
8 of 15 checks passed
@quartzmo quartzmo deleted the otel-tracing-attributes branch February 3, 2026 18:07
quartzmo added a commit to quartzmo/gapic-generator-go that referenced this pull request Mar 4, 2026
Replace gRPC metadata Context management with new telemetry Context helpers.

refs: googleapis#1690
refs: googleapis/gax-go#472
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants