Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e01ca06
feat(observability): add no-op implementation of tracing
diegomarquezp Jan 8, 2026
d3f61d1
chore: add otel tracing recorder
diegomarquezp Jan 8, 2026
cf98e86
chore: add javadocs
diegomarquezp Jan 8, 2026
523c301
chore: adjust tests and conform more closely to metrics counterpart.
diegomarquezp Jan 8, 2026
d9534bd
chore: expand imports in otel it
diegomarquezp Jan 8, 2026
196d591
Update gax-java/gax/src/main/java/com/google/api/gax/tracing/OpenTele…
diegomarquezp Jan 8, 2026
ea075d3
test: use tracer provider in ItOtelMetrics
diegomarquezp Jan 8, 2026
2997153
Merge branch 'observability/tracing-noop' of https://github.com/googl…
diegomarquezp Jan 8, 2026
2c26971
chore: format
diegomarquezp Jan 8, 2026
1a76c29
chore: generate libraries at Thu Jan 8 19:39:27 UTC 2026
cloud-java-bot Jan 8, 2026
8a0f855
chore: add dummy tracing metric
diegomarquezp Jan 9, 2026
dc3ed42
chore: refine tracing IT
diegomarquezp Jan 9, 2026
5287f82
feat: add composite api tracer
diegomarquezp Jan 9, 2026
ce2d85b
test: use global config for tracing
diegomarquezp Jan 9, 2026
d6341cc
chore: restore metrics it
diegomarquezp Jan 9, 2026
a9c70ab
chore: format
diegomarquezp Jan 12, 2026
69a7fa4
Merge branch 'observability/tracing-noop' of https://github.com/googl…
diegomarquezp Jan 12, 2026
a6716b4
chore: format ii
diegomarquezp Jan 12, 2026
99bfd5b
chore: generate libraries at Mon Jan 12 21:30:41 UTC 2026
cloud-java-bot Jan 12, 2026
7b5709b
Merge branch 'observability/tracing-noop' of https://github.com/googl…
diegomarquezp Jan 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,14 @@
import com.google.api.gax.core.NoCredentialsProvider;
import com.google.api.gax.tracing.ApiTracerFactory;
import com.google.api.gax.tracing.BaseApiTracerFactory;
import com.google.api.gax.tracing.CompositeApiTracerFactory;
import com.google.api.gax.tracing.OpenTelemetryTracingRecorder;
import com.google.api.gax.tracing.TracingTracerFactory;
import com.google.api.gax.tracing.TracingUtils;
import com.google.auth.oauth2.QuotaProjectIdProvider;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import io.opentelemetry.api.GlobalOpenTelemetry;
import java.io.IOException;
import java.util.concurrent.Executor;
import javax.annotation.Nonnull;
Expand Down Expand Up @@ -104,13 +109,26 @@ protected StubSettings(Builder builder) {
this.quotaProjectId = builder.quotaProjectId;
this.streamWatchdogProvider = builder.streamWatchdogProvider;
this.streamWatchdogCheckInterval = builder.streamWatchdogCheckInterval;
this.tracerFactory = builder.tracerFactory;
this.tracerFactory = autoConfigureTracerFactory(builder.tracerFactory);
this.deprecatedExecutorProviderSet = builder.deprecatedExecutorProviderSet;
this.gdchApiAudience = builder.gdchApiAudience;
this.endpointContext = buildEndpointContext(builder);
this.apiKey = builder.apiKey;
}

private ApiTracerFactory autoConfigureTracerFactory(ApiTracerFactory factory) {
if (TracingUtils.isTracingEnabled()) {
ApiTracerFactory tracingFactory =
new TracingTracerFactory(
new OpenTelemetryTracingRecorder(GlobalOpenTelemetry.get(), getServiceName()));
if (factory instanceof BaseApiTracerFactory) {
return tracingFactory;
}
return CompositeApiTracerFactory.of(factory, tracingFactory);
}
return factory;
}

/**
* Attempt to build the EndpointContext from the Builder based on all the user configurations
* passed in.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* Copyright 2026 Google LLC
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google LLC nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.google.api.gax.tracing;

import com.google.api.core.InternalApi;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.stream.Collectors;

/** A composite implementation of {@link ApiTracer} that broadcasts events to multiple tracers. */
@InternalApi
public class CompositeApiTracer implements ApiTracer {
private final List<ApiTracer> tracers;

public CompositeApiTracer(List<ApiTracer> tracers) {
this.tracers = ImmutableList.copyOf(tracers);
}

@Override
public Scope inScope() {
List<Scope> scopes = tracers.stream().map(ApiTracer::inScope).collect(Collectors.toList());
return () -> scopes.forEach(Scope::close);
}

@Override
public void operationSucceeded() {
tracers.forEach(ApiTracer::operationSucceeded);
}

@Override
public void operationCancelled() {
tracers.forEach(ApiTracer::operationCancelled);
}

@Override
public void operationFailed(Throwable error) {
tracers.forEach(t -> t.operationFailed(error));
}

@Override
public void connectionSelected(String id) {
tracers.forEach(t -> t.connectionSelected(id));
}

@Override
public void attemptStarted(int attemptNumber) {
tracers.forEach(t -> t.attemptStarted(attemptNumber));
}

@Override
public void attemptStarted(Object request, int attemptNumber) {
tracers.forEach(t -> t.attemptStarted(request, attemptNumber));
}

@Override
public void attemptSucceeded() {
tracers.forEach(ApiTracer::attemptSucceeded);
}

@Override
public void attemptCancelled() {
tracers.forEach(ApiTracer::attemptCancelled);
}

@Override
public void attemptFailedDuration(Throwable error, java.time.Duration delay) {
tracers.forEach(t -> t.attemptFailedDuration(error, delay));
}

@Override
public void attemptFailedRetriesExhausted(Throwable error) {
tracers.forEach(t -> t.attemptFailedRetriesExhausted(error));
}

@Override
public void attemptPermanentFailure(Throwable error) {
tracers.forEach(t -> t.attemptPermanentFailure(error));
}

@Override
public void lroStartFailed(Throwable error) {
tracers.forEach(t -> t.lroStartFailed(error));
}

@Override
public void lroStartSucceeded() {
tracers.forEach(ApiTracer::lroStartSucceeded);
}

@Override
public void responseReceived() {
tracers.forEach(ApiTracer::responseReceived);
}

@Override
public void requestSent() {
tracers.forEach(ApiTracer::requestSent);
}

@Override
public void batchRequestSent(long elementCount, long requestSize) {
tracers.forEach(t -> t.batchRequestSent(elementCount, requestSize));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2026 Google LLC
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google LLC nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.google.api.gax.tracing;

import com.google.api.core.InternalApi;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.stream.Collectors;

/**
* A composite implementation of {@link ApiTracerFactory} that creates {@link CompositeApiTracer}s.
*/
@InternalApi
public class CompositeApiTracerFactory implements ApiTracerFactory {
private final List<ApiTracerFactory> factories;

public CompositeApiTracerFactory(List<ApiTracerFactory> factories) {
this.factories = ImmutableList.copyOf(factories);
}

public static ApiTracerFactory of(ApiTracerFactory... factories) {
return new CompositeApiTracerFactory(ImmutableList.copyOf(factories));
}

@Override
public ApiTracer newTracer(ApiTracer parent, SpanName spanName, OperationType operationType) {
List<ApiTracer> tracers =
factories.stream()
.map(f -> f.newTracer(parent, spanName, operationType))
.collect(Collectors.toList());
return new CompositeApiTracer(tracers);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright 2026 Google LLC
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google LLC nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.google.api.gax.tracing;

import com.google.api.core.BetaApi;
import com.google.api.core.InternalApi;
import com.google.api.gax.core.GaxProperties;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
import java.util.Map;

/**
* OpenTelemetry implementation of recording traces. This implementation collects the measurements
* related to the lifecyle of an RPC.
*/
@BetaApi
@InternalApi
public class OpenTelemetryTracingRecorder implements TracingRecorder {
public static final String GAX_TRACER_NAME = "gax-java";
private final Tracer tracer;
private final String serviceName;

/**
* Creates a new instance of OpenTelemetryTracingRecorder.
*
* @param openTelemetry OpenTelemetry instance
* @param serviceName Service Name
*/
public OpenTelemetryTracingRecorder(OpenTelemetry openTelemetry, String serviceName) {
this.tracer =
openTelemetry
.tracerBuilder(GAX_TRACER_NAME)
.setInstrumentationVersion(GaxProperties.getGaxVersion())
.build();
this.serviceName = serviceName;
}

@Override
public void recordLowLevelNetworkSpan(Map<String, String> attributes) {
Span span = tracer.spanBuilder(serviceName + "/low-level-network-span").startSpan();
if (attributes != null) {
attributes.forEach(span::setAttribute);
}
span.end();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2026 Google LLC
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google LLC nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.google.api.gax.tracing;

import com.google.api.core.BetaApi;
import com.google.api.core.InternalApi;
import java.util.Map;

/**
* Provides an interface for tracing recording. The implementer is expected to use an observability
* framework, e.g. OpenTelemetry. There should be only one instance of TracingRecorder per client,
* all the methods in this class are expected to be called from multiple threads, hence the
* implementation must be thread safe.
*/
@BetaApi
@InternalApi
public interface TracingRecorder {

/**
* Represents a low-level network span (T4) and serves as a placeholder for further development.
* This represents a single network request/attempt.
*
* @param attributes Map of the attributes to store on the span.
*/
default void recordLowLevelNetworkSpan(Map<String, String> attributes) {}
}
Loading
Loading