-
Notifications
You must be signed in to change notification settings - Fork 75
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 29 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
60 changes: 60 additions & 0 deletions
60
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,60 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
|
diegomarquezp marked this conversation as 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 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 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
104 changes: 104 additions & 0 deletions
104
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,104 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
|
diegomarquezp marked this conversation as 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 TraceRecorder} to record traces. This | ||
| * implementation is agnostic to the specific {@link TraceRecorder} in order to allow extensions | ||
| * that interact with other backends. | ||
| */ | ||
| @BetaApi | ||
| @InternalApi | ||
| public class AppCentricTracer extends BaseApiTracer { | ||
|
diegomarquezp marked this conversation as resolved.
Outdated
|
||
| public static final String SERVER_ADDRESS_ATTRIBUTE = "server.address"; | ||
|
diegomarquezp marked this conversation as resolved.
Outdated
|
||
| public static final String LANGUAGE_ATTRIBUTE = "gcp.client.language"; | ||
|
diegomarquezp marked this conversation as resolved.
|
||
|
|
||
| public static final String DEFAULT_LANGUAGE = "Java"; | ||
|
|
||
| private final TraceRecorder recorder; | ||
| private final Map<String, String> attemptAttributes; | ||
| private final String attemptSpanName; | ||
| private final TraceRecorder.TraceSpan operationHandle; | ||
| private TraceRecorder.TraceSpan attemptHandle; | ||
|
|
||
| /** | ||
| * Creates a new instance of {@code AppCentricTracer}. | ||
| * | ||
| * @param recorder the {@link TraceRecorder} to use for recording spans | ||
| * @param operationSpanName the name of the long-lived operation span | ||
| * @param attemptSpanName the name of the individual attempt spans | ||
| * @param operationAttributes attributes to be added to the operation span | ||
| * @param attemptAttributes attributes to be added to each attempt span | ||
| */ | ||
| public AppCentricTracer( | ||
| TraceRecorder recorder, | ||
| String operationSpanName, | ||
| String attemptSpanName, | ||
| Map<String, String> operationAttributes, | ||
| Map<String, String> attemptAttributes) { | ||
| this.recorder = recorder; | ||
| this.attemptSpanName = attemptSpanName; | ||
| this.attemptAttributes = new HashMap<>(attemptAttributes); | ||
| this.attemptAttributes.put(LANGUAGE_ATTRIBUTE, DEFAULT_LANGUAGE); | ||
|
|
||
| // Start the long-lived operation span. | ||
| this.operationHandle = recorder.createSpan(operationSpanName, operationAttributes); | ||
| } | ||
|
|
||
| @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 = recorder.createSpan(attemptSpanName, attemptAttributes, operationHandle); | ||
| } | ||
|
|
||
| @Override | ||
| public void attemptSucceeded() { | ||
|
blakeli0 marked this conversation as resolved.
|
||
| endAttempt(); | ||
| } | ||
|
|
||
| private void endAttempt() { | ||
| if (attemptHandle != null) { | ||
| attemptHandle.end(); | ||
| attemptHandle = null; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void operationSucceeded() { | ||
|
diegomarquezp marked this conversation as resolved.
Outdated
|
||
| operationHandle.end(); | ||
| } | ||
| } | ||
106 changes: 106 additions & 0 deletions
106
gax-java/gax/src/main/java/com/google/api/gax/tracing/AppCentricTracerFactory.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,106 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
|
diegomarquezp marked this conversation as 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 com.google.common.annotations.VisibleForTesting; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * A {@link ApiTracerFactory} to build instances of {@link AppCentricTracer}. | ||
| * | ||
| * <p>This class wraps the {@link TraceRecorder} and pass it to {@link AppCentricTracer}. It will be | ||
| * used to record traces in {@link AppCentricTracer}. | ||
| * | ||
| * <p>This class is expected to be initialized once during client initialization. | ||
| */ | ||
| @BetaApi | ||
| @InternalApi | ||
| public class AppCentricTracerFactory implements ApiTracerFactory { | ||
| private final TraceRecorder traceRecorder; | ||
|
|
||
| /** Mapping of client attributes that are set for every AppCentricTracer at operation level */ | ||
| private final Map<String, String> operationAttributes; | ||
|
diegomarquezp marked this conversation as resolved.
Outdated
|
||
|
|
||
| /** Mapping of client attributes that are set for every AppCentricTracer at attempt level */ | ||
| private final Map<String, String> attemptAttributes; | ||
|
|
||
| /** Creates a AppCentricTracerFactory */ | ||
| public AppCentricTracerFactory(TraceRecorder traceRecorder) { | ||
| this(traceRecorder, new HashMap<>(), new HashMap<>()); | ||
| } | ||
|
|
||
| /** | ||
| * Pass in a Map of client level attributes which will be added to every single AppCentricTracer | ||
| * created from the ApiTracerFactory. This is package private since span attributes are determined | ||
| * internally. | ||
| */ | ||
| @VisibleForTesting | ||
| AppCentricTracerFactory( | ||
| TraceRecorder traceRecorder, | ||
| Map<String, String> operationAttributes, | ||
| Map<String, String> attemptAttributes) { | ||
| this.traceRecorder = traceRecorder; | ||
|
|
||
| this.operationAttributes = new HashMap<>(operationAttributes); | ||
| this.attemptAttributes = new HashMap<>(attemptAttributes); | ||
| } | ||
|
|
||
| @Override | ||
| public ApiTracer newTracer(ApiTracer parent, SpanName spanName, OperationType operationType) { | ||
| // TODO(diegomarquezp): these are placeholders for span names and will be adjusted as the | ||
| // feature is developed. | ||
| String operationSpanName = | ||
| spanName.getClientName() + "." + spanName.getMethodName() + "/operation"; | ||
|
diegomarquezp marked this conversation as resolved.
Outdated
|
||
| String attemptSpanName = spanName.getClientName() + "/" + spanName.getMethodName() + "/attempt"; | ||
|
diegomarquezp marked this conversation as resolved.
Outdated
|
||
|
|
||
| AppCentricTracer appCentricTracer = | ||
| new AppCentricTracer( | ||
| traceRecorder, | ||
| operationSpanName, | ||
| attemptSpanName, | ||
| this.operationAttributes, | ||
| this.attemptAttributes); | ||
| return appCentricTracer; | ||
| } | ||
|
|
||
| @Override | ||
| public ApiTracerFactory withContext(ApiTracerContext context) { | ||
| Map<String, String> newAttemptAttributes = new HashMap<>(this.attemptAttributes); | ||
| if (context.getServerAddress() != null) { | ||
| newAttemptAttributes.put( | ||
| AppCentricTracer.SERVER_ADDRESS_ATTRIBUTE, context.getServerAddress()); | ||
| } | ||
| return new AppCentricTracerFactory(traceRecorder, operationAttributes, newAttemptAttributes); | ||
|
diegomarquezp marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
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.