-
Notifications
You must be signed in to change notification settings - Fork 49
feat: Adding TraceUtil interface and its implementation to enable Tracing controls via DatastoreOptions #1431
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 all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ff171d7
Adding OpenTelemetry API pom.xml dependency, DatastoreOptions API cha…
jimit-j-shah 3f1dc1b
Adding EnabledTraceUtil, DisabledTraceUtil and TraceUtilTest
jimit-j-shah 1639b92
Fixing unused dependencies
jimit-j-shah 2622810
Fixing linter issues
jimit-j-shah 71ec887
Adding google-auth-library-credentials dependency due to https://gith…
jimit-j-shah f9e0c11
Code review comments
jimit-j-shah cd8ed6a
Code review: fix pom to derive dependency from shared dependency
jimit-j-shah 0b682ef
Code review: s/Firestore/Datastore
jimit-j-shah 376d15c
Code review: remove redundant opentelemetryOptions initialization
jimit-j-shah 5c2c263
Code review: block comments and API use annotation
jimit-j-shah b05645d
Code review: s/Firestore/Datastore
jimit-j-shah 59dc0ce
Code review: Test changes
jimit-j-shah 29e088d
Code review: DatastoreOptionsTest
jimit-j-shah f46058a
Code review: Method name s/getEnabled/isEnabled
jimit-j-shah 2dcc121
Code review: redundant dependency, s/enable/enabled
jimit-j-shah 33d08d6
Code review: reinstating dependency after build failure https://githu…
jimit-j-shah 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
97 changes: 97 additions & 0 deletions
97
...oud-datastore/src/main/java/com/google/cloud/datastore/DatastoreOpenTelemetryOptions.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,97 @@ | ||
| /* | ||
| * Copyright 2024 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.cloud.datastore; | ||
|
|
||
| import io.opentelemetry.api.OpenTelemetry; | ||
| import javax.annotation.Nonnull; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| public class DatastoreOpenTelemetryOptions { | ||
| private final boolean enabled; | ||
| private final @Nullable OpenTelemetry openTelemetry; | ||
|
|
||
| DatastoreOpenTelemetryOptions(Builder builder) { | ||
| this.enabled = builder.enabled; | ||
| this.openTelemetry = builder.openTelemetry; | ||
| } | ||
|
|
||
| public boolean isEnabled() { | ||
| return enabled; | ||
| } | ||
|
|
||
| @Nullable | ||
| public OpenTelemetry getOpenTelemetry() { | ||
| return openTelemetry; | ||
| } | ||
|
|
||
| @Nonnull | ||
| public DatastoreOpenTelemetryOptions.Builder toBuilder() { | ||
| return new DatastoreOpenTelemetryOptions.Builder(this); | ||
| } | ||
|
|
||
| @Nonnull | ||
| public static DatastoreOpenTelemetryOptions.Builder newBuilder() { | ||
| return new DatastoreOpenTelemetryOptions.Builder(); | ||
| } | ||
|
|
||
| public static class Builder { | ||
|
|
||
| private boolean enabled; | ||
|
|
||
| @Nullable private OpenTelemetry openTelemetry; | ||
|
|
||
| private Builder() { | ||
| enabled = false; | ||
| openTelemetry = null; | ||
| } | ||
|
|
||
| private Builder(DatastoreOpenTelemetryOptions options) { | ||
| this.enabled = options.enabled; | ||
| this.openTelemetry = options.openTelemetry; | ||
| } | ||
|
|
||
| @Nonnull | ||
| public DatastoreOpenTelemetryOptions build() { | ||
| return new DatastoreOpenTelemetryOptions(this); | ||
| } | ||
|
|
||
| /** | ||
| * Sets whether tracing should be enabled. | ||
| * | ||
| * @param enabled Whether tracing should be enabled. | ||
| */ | ||
| @Nonnull | ||
| public DatastoreOpenTelemetryOptions.Builder setTracingEnabled(boolean enabled) { | ||
| this.enabled = enabled; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the {@link OpenTelemetry} to use with this Datastore instance. If telemetry collection | ||
| * is enabled, but an `OpenTelemetry` is not provided, the Datastore SDK will attempt to use the | ||
| * `GlobalOpenTelemetry`. | ||
| * | ||
| * @param openTelemetry The OpenTelemetry that should be used by this Datastore instance. | ||
| */ | ||
| @Nonnull | ||
| public DatastoreOpenTelemetryOptions.Builder setOpenTelemetry( | ||
| @Nonnull OpenTelemetry openTelemetry) { | ||
| this.openTelemetry = openTelemetry; | ||
| return this; | ||
| } | ||
| } | ||
| } |
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
109 changes: 109 additions & 0 deletions
109
...cloud-datastore/src/main/java/com/google/cloud/datastore/telemetry/DisabledTraceUtil.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,109 @@ | ||
| /* | ||
| * Copyright 2024 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.cloud.datastore.telemetry; | ||
|
|
||
| import com.google.api.core.ApiFunction; | ||
| import com.google.api.core.ApiFuture; | ||
| import com.google.api.core.InternalApi; | ||
| import io.grpc.ManagedChannelBuilder; | ||
| import java.util.Map; | ||
| import javax.annotation.Nonnull; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * Tracing utility implementation, used to stub out tracing instrumentation when tracing is | ||
| * disabled. | ||
| */ | ||
| @InternalApi | ||
| public class DisabledTraceUtil implements TraceUtil { | ||
jimit-j-shah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| static class Span implements TraceUtil.Span { | ||
| @Override | ||
| public void end() {} | ||
|
|
||
| @Override | ||
| public void end(Throwable error) {} | ||
|
|
||
| @Override | ||
| public <T> void endAtFuture(ApiFuture<T> futureValue) {} | ||
|
|
||
| @Override | ||
| public TraceUtil.Span addEvent(String name) { | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public TraceUtil.Span addEvent(String name, Map<String, Object> attributes) { | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public TraceUtil.Span setAttribute(String key, int value) { | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public TraceUtil.Span setAttribute(String key, String value) { | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public Scope makeCurrent() { | ||
| return new Scope(); | ||
| } | ||
| } | ||
|
|
||
| static class Context implements TraceUtil.Context { | ||
| @Override | ||
| public Scope makeCurrent() { | ||
| return new Scope(); | ||
| } | ||
| } | ||
|
|
||
| static class Scope implements TraceUtil.Scope { | ||
| @Override | ||
| public void close() {} | ||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder> getChannelConfigurator() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public Span startSpan(String spanName) { | ||
| return new Span(); | ||
| } | ||
|
|
||
| @Override | ||
| public TraceUtil.Span startSpan(String spanName, TraceUtil.Context parent) { | ||
| return new Span(); | ||
| } | ||
|
|
||
| @Nonnull | ||
| @Override | ||
| public TraceUtil.Span currentSpan() { | ||
| return new Span(); | ||
| } | ||
|
|
||
| @Nonnull | ||
| @Override | ||
| public TraceUtil.Context currentContext() { | ||
| return new Context(); | ||
| } | ||
| } | ||
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.