This repository was archived by the owner on May 14, 2026. It is now read-only.
feat(observability): introduce minimal tracing implementation#4105
Merged
Conversation
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a new tracing mechanism in GAX that allows recording traces using OpenTelemetry. It provides a way of recording spans and attributes, following the existing
ApiTracerclass pattern with a few tracing-specific additions. The implementation is meant to be extensible to support other implementations.New Classes
TraceManager: An interface for managing spans and attributes; can be implemented by observability frameworks.OpenTelemetryTraceManager: An implementation ofTraceManagerthat uses the OpenTelemetry API.AppCentricTracer: AnApiTracerimplementation that delegates span management to aTraceManager.AppCentricTracerFactory: A factory for creatingAppCentricTracerinstances.ApiTracerContext: A context object that carries information (likeEndpointContext's server address property) used to infer common attributes for all tracers.Span: A handle returned byTraceManagerto manage the lifecycle of a specific span (ending it, recording errors, or setting attributes).Approach
Connecting Tracer with Manager
The implementation aims to decouple
AppCentricTracerfromTraceManager. When a tracer starts an operation or an attempt, it requests aSpanfrom the recorder. This handle allows the tracer to update the span (e.g., adding attributes or recording errors) to keepAppCentricTracerseparated from specific recorder implementations (like OpenTelemetry'sSpanobject).Attribute Inference via
ApiTracerContextTo provide a source of Span Attributes that are common to all operations, we introduced
ApiTracerContext. This context is passed toApiTracerFactoryand contains information such as serverAddress (provided byEndpointContext). It is operated byClientContext.Initially, only
serverAddressis contained in this class and it's meant to obtain theserver.addressattribute.The class is ultimately operated by
AppCentricTracerto extract the necessary attributes.Integration Tests
A new integration test,
ITOtelTracing, was added to thejava-showcasemodule:server.addressandgcp.client.language).Note on java-bigtable downstream check
Since SkipTrailersTest mocks the tracer factory, the
EndpointContextcall toapiTracerFactory.withContext()returns a null factory, causing a null pointer exception when building the client context.We expect the test to be adjusted with this change with the next release.
Confirmation in Cloud Trace