-
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
+983
−2
Merged
Changes from all 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
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
73 changes: 73 additions & 0 deletions
73
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,73 @@ | ||
| /* | ||
| * 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.auto.value.AutoValue; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| 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 { | ||
|
|
||
| /** | ||
| * @return a map of attributes to be included in attempt-level spans | ||
| */ | ||
| public Map<String, String> getAttemptAttributes() { | ||
| Map<String, String> attributes = new HashMap<>(); | ||
| if (getServerAddress() != null) { | ||
| attributes.put(AppCentricAttributes.SERVER_ADDRESS_ATTRIBUTE, getServerAddress()); | ||
| } | ||
| return attributes; | ||
| } | ||
|
|
||
| @Nullable | ||
| public abstract String getServerAddress(); | ||
|
|
||
| public static Builder newBuilder() { | ||
| return new AutoValue_ApiTracerContext.Builder(); | ||
| } | ||
|
|
||
| @AutoValue.Builder | ||
| public abstract static class Builder { | ||
| public abstract Builder setServerAddress(String serverAddress); | ||
|
|
||
| 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
46 changes: 46 additions & 0 deletions
46
gax-java/gax/src/main/java/com/google/api/gax/tracing/AppCentricAttributes.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,46 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| /** | ||
| * Utility class with common attribute names in app-centric observability. | ||
| * | ||
| * <p>For internal use only. | ||
| */ | ||
| @InternalApi | ||
| @BetaApi | ||
| public class AppCentricAttributes { | ||
| /** The address of the server being called (e.g., "pubsub.googleapis.com"). */ | ||
| public static final String SERVER_ADDRESS_ATTRIBUTE = "server.address"; | ||
| } |
94 changes: 94 additions & 0 deletions
94
gax-java/gax/src/main/java/com/google/api/gax/tracing/AppCentricTracer.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,94 @@ | ||
| /* | ||
| * 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.BetaApi; | ||
| import com.google.api.core.InternalApi; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * An implementation of {@link ApiTracer} that uses a {@link TraceManager} to record traces. This | ||
| * implementation is agnostic to the specific {@link TraceManager} in order to allow extensions that | ||
| * interact with other backends. | ||
| */ | ||
| @BetaApi | ||
| @InternalApi | ||
| public class AppCentricTracer implements ApiTracer { | ||
| public static final String LANGUAGE_ATTRIBUTE = "gcp.client.language"; | ||
diegomarquezp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public static final String DEFAULT_LANGUAGE = "Java"; | ||
|
|
||
| private final TraceManager traceManager; | ||
| private final Map<String, String> attemptAttributes; | ||
| private final String attemptSpanName; | ||
| private final ApiTracerContext apiTracerContext; | ||
| private TraceManager.Span attemptHandle; | ||
|
|
||
| /** | ||
| * Creates a new instance of {@code AppCentricTracer}. | ||
| * | ||
| * @param traceManager the {@link TraceManager} to use for recording spans | ||
| * @param attemptSpanName the name of the individual attempt spans | ||
| */ | ||
| public AppCentricTracer( | ||
| TraceManager traceManager, ApiTracerContext apiTracerContext, String attemptSpanName) { | ||
| this.traceManager = traceManager; | ||
| this.attemptSpanName = attemptSpanName; | ||
| this.apiTracerContext = apiTracerContext; | ||
| this.attemptAttributes = new HashMap<>(); | ||
| buildAttributes(); | ||
| } | ||
|
|
||
| private void buildAttributes() { | ||
| this.attemptAttributes.put(LANGUAGE_ATTRIBUTE, DEFAULT_LANGUAGE); | ||
| this.attemptAttributes.putAll(this.apiTracerContext.getAttemptAttributes()); | ||
| } | ||
|
|
||
| @Override | ||
| public void attemptStarted(Object request, int attemptNumber) { | ||
| Map<String, String> attemptAttributes = new HashMap<>(this.attemptAttributes); | ||
| // Start the specific attempt span with the operation span as parent | ||
| this.attemptHandle = traceManager.createSpan(attemptSpanName, attemptAttributes); | ||
| } | ||
|
|
||
| @Override | ||
| public void attemptSucceeded() { | ||
blakeli0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| endAttempt(); | ||
| } | ||
|
|
||
| private void endAttempt() { | ||
| if (attemptHandle != null) { | ||
| attemptHandle.end(); | ||
| attemptHandle = null; | ||
| } | ||
| } | ||
| } | ||
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.