-
Notifications
You must be signed in to change notification settings - Fork 73
feat(observability): introduce minimal tracing implementation #4105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 16 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
7082247
feat: introduce minimal implementation of OTel tracing
diegomarquezp bfe6a6d
chore: avoid new public methods
diegomarquezp ea6cb18
feat: add api tracer context
diegomarquezp 97bec08
Merge remote-tracking branch 'origin/main' into observability/initial…
diegomarquezp 097f701
chore: concise comment
diegomarquezp f547e5a
fix: use internal span kind for operations
diegomarquezp b7b9e31
chore: remove unnecessary inScope implementation
diegomarquezp 556c84c
Revert "chore: remove unnecessary inScope implementation"
diegomarquezp 0359b7d
test: add test for inScope()
diegomarquezp 402cb89
Merge remote-tracking branch 'origin/main' into observability/initial…
diegomarquezp 420278b
chore: use suggested server address resolution impl
diegomarquezp 6de9fb6
fix: use concurrent hash map
diegomarquezp a61dacf
chore: remove default impl for startSpan with parent
diegomarquezp b000d52
chore: add opentelemery-context to tests
diegomarquezp 9ce0c34
test: increase coverage for TracingTracerTest
diegomarquezp 9c6c737
deps: include opentelemetry context in gax
diegomarquezp e77de58
chore: simplify and remove error handling
diegomarquezp 8f07f61
chore: review refactor
diegomarquezp 2cfcd68
chore: make TracingTracerFactory(recorder, opAtts, atAtts) package pr…
diegomarquezp 2415c6b
chore: remove unnecessary inScope
diegomarquezp 0f5e9b5
chore: rename startSpan to createSpan
diegomarquezp 0c3bd22
chore: use server address instead of endpoint context
diegomarquezp bdeb291
chore: rename classes
diegomarquezp 5c07a3c
chore: add javadoc for tracer
diegomarquezp ff1d45d
chore: rename to TraceSpan, improve javadocs
diegomarquezp 043ce62
chore: format
diegomarquezp dbc5f41
Update gax-java/gax/src/main/java/com/google/api/gax/tracing/AppCentr…
diegomarquezp b4bce0d
chore: handle ipv6 in endpoint context
diegomarquezp 6e95cf4
Merge branch 'observability/initial-tracing-impl' of https://github.c…
diegomarquezp e873904
chore: add language tests
diegomarquezp 68943b0
chore: AppCentricTracer to implement interface
diegomarquezp cd4d4d0
chore: revert operation implementation
diegomarquezp 5b76e40
chore: extract common span attributes to separate class
diegomarquezp c783d68
chore: remove unused var
diegomarquezp 3e06b39
chore: restore context dep
diegomarquezp 40a97a5
chore: process attributes in context and tracer classes
diegomarquezp 5b43fa5
chore: rename to GaxSpan
diegomarquezp ed4af8e
chore: use fq name for otel tracer
diegomarquezp 3bfd1ce
chore: add otel context to maven deps
diegomarquezp 5382d78
chore: rename TraceRecorder to TraceManager and GaxSpan to Span
diegomarquezp 4ece157
chore: remove attrs from factory
diegomarquezp fb57471
chore: adjust javadoc in TraceManager
diegomarquezp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracerContext.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
diegomarquezp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * | ||
| * 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.api.gax.rpc.EndpointContext; | ||
| import com.google.auto.value.AutoValue; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * A context object that contains information used to infer attributes that are common for all | ||
| * {@link ApiTracer}s. | ||
| * | ||
| * <p>For internal use only. | ||
| */ | ||
| @InternalApi | ||
| @AutoValue | ||
| public abstract class ApiTracerContext { | ||
|
|
||
| @Nullable | ||
| public abstract EndpointContext getEndpointContext(); | ||
|
|
||
| public static Builder newBuilder() { | ||
| return new AutoValue_ApiTracerContext.Builder(); | ||
| } | ||
|
|
||
| @AutoValue.Builder | ||
| public abstract static class Builder { | ||
| public abstract Builder setEndpointContext(EndpointContext endpointContext); | ||
|
|
||
| public abstract ApiTracerContext build(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
gax-java/gax/src/main/java/com/google/api/gax/tracing/OpenTelemetryTracingRecorder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /* | ||
| * 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 io.opentelemetry.api.OpenTelemetry; | ||
| import io.opentelemetry.api.trace.Span; | ||
| import io.opentelemetry.api.trace.SpanBuilder; | ||
| import io.opentelemetry.api.trace.SpanKind; | ||
| import io.opentelemetry.api.trace.StatusCode; | ||
| import io.opentelemetry.api.trace.Tracer; | ||
| import io.opentelemetry.context.Context; | ||
| import io.opentelemetry.context.Scope; | ||
| 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 { | ||
| private final Tracer tracer; | ||
|
|
||
| public OpenTelemetryTracingRecorder(OpenTelemetry openTelemetry) { | ||
| this.tracer = openTelemetry.getTracer("gax-java"); | ||
| } | ||
|
|
||
| @Override | ||
| public SpanHandle startSpan(String name, Map<String, String> attributes) { | ||
diegomarquezp marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return startSpan(name, attributes, null); | ||
| } | ||
|
|
||
| @Override | ||
| public SpanHandle startSpan(String name, Map<String, String> attributes, SpanHandle parent) { | ||
| SpanBuilder spanBuilder = tracer.spanBuilder(name); | ||
|
|
||
| // Operation and Attempt spans are INTERNAL and CLIENT respectively. | ||
| if (parent == null) { | ||
| spanBuilder.setSpanKind(SpanKind.INTERNAL); | ||
| } else { | ||
| spanBuilder.setSpanKind(SpanKind.CLIENT); | ||
| } | ||
|
|
||
| if (attributes != null) { | ||
| attributes.forEach((k, v) -> spanBuilder.setAttribute(k, v)); | ||
| } | ||
|
|
||
| if (parent instanceof OtelSpanHandle) { | ||
| spanBuilder.setParent(Context.current().with(((OtelSpanHandle) parent).span)); | ||
| } | ||
|
|
||
| Span span = spanBuilder.startSpan(); | ||
|
|
||
| return new OtelSpanHandle(span); | ||
| } | ||
|
|
||
| @Override | ||
| @SuppressWarnings("MustBeClosedChecker") | ||
| public ApiTracer.Scope inScope(SpanHandle handle) { | ||
| if (handle instanceof OtelSpanHandle) { | ||
| Scope scope = ((OtelSpanHandle) handle).span.makeCurrent(); | ||
diegomarquezp marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return scope::close; | ||
| } | ||
| return () -> {}; | ||
| } | ||
|
|
||
| private static class OtelSpanHandle implements SpanHandle { | ||
| private final Span span; | ||
|
|
||
| private OtelSpanHandle(Span span) { | ||
| this.span = span; | ||
| } | ||
|
|
||
| @Override | ||
| public void end() { | ||
| span.end(); | ||
| } | ||
|
|
||
| @Override | ||
| public void recordError(Throwable error) { | ||
| span.recordException(error); | ||
| span.setStatus(StatusCode.ERROR); | ||
| } | ||
|
|
||
| @Override | ||
| public void setAttribute(String key, String value) { | ||
| span.setAttribute(key, value); | ||
| } | ||
| } | ||
| } | ||
68 changes: 68 additions & 0 deletions
68
gax-java/gax/src/main/java/com/google/api/gax/tracing/TracingRecorder.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* | ||
| * 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 { | ||
| /** Starts a span and returns a handle to manage its lifecycle. */ | ||
| SpanHandle startSpan(String name, Map<String, String> attributes); | ||
|
|
||
| /** Starts a span with a parent and returns a handle to manage its lifecycle. */ | ||
| SpanHandle startSpan(String name, Map<String, String> attributes, SpanHandle parent); | ||
|
|
||
| /** | ||
| * Installs the span into the current thread-local context. | ||
| * | ||
| * @return a scope that must be closed to remove the span from the context. | ||
| */ | ||
| default ApiTracer.Scope inScope(SpanHandle handle) { | ||
| return () -> {}; | ||
| } | ||
|
|
||
| interface SpanHandle { | ||
diegomarquezp marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| void end(); | ||
|
|
||
| void recordError(Throwable error); | ||
diegomarquezp marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| void setAttribute(String key, String value); | ||
diegomarquezp marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.