This repository was archived by the owner on May 8, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
feat: Add com.google.cloud.firestore.telemetry package. #1533
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8163bb4
feat: Add FirestoreOpenTelemetryOptions to FirestoreOptions.
ehsannas 27d4bc1
feat: Add com.google.cloud.firestore.telemetry package.
ehsannas 79e90a3
Address code review feedback.
ehsannas 1de49a3
Factor out the otel version in pom.xml.
ehsannas 5dd8cb5
Merge remote-tracking branch 'origin/tracing' into tracing-2
ehsannas 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-firestore/src/main/java/com/google/cloud/firestore/FirestoreOpenTelemetryOptions.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.firestore; | ||
|
|
||
| import io.opentelemetry.api.OpenTelemetry; | ||
| import javax.annotation.Nonnull; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| public class FirestoreOpenTelemetryOptions { | ||
| private final boolean enabled; | ||
|
|
||
| @Nullable private final OpenTelemetry openTelemetry; | ||
|
|
||
| FirestoreOpenTelemetryOptions(Builder builder) { | ||
| this.enabled = builder.enabled; | ||
| this.openTelemetry = builder.openTelemetry; | ||
| } | ||
|
|
||
| public boolean getEnabled() { | ||
| return enabled; | ||
| } | ||
|
|
||
| public OpenTelemetry getOpenTelemetry() { | ||
| return openTelemetry; | ||
| } | ||
|
|
||
| @Nonnull | ||
| public FirestoreOpenTelemetryOptions.Builder toBuilder() { | ||
| return new FirestoreOpenTelemetryOptions.Builder(this); | ||
| } | ||
|
|
||
| @Nonnull | ||
| public static FirestoreOpenTelemetryOptions.Builder newBuilder() { | ||
| return new FirestoreOpenTelemetryOptions.Builder(); | ||
| } | ||
|
|
||
| public static class Builder { | ||
|
|
||
| private boolean enabled; | ||
|
|
||
| @Nullable private OpenTelemetry openTelemetry; | ||
|
|
||
| private Builder() { | ||
| enabled = false; | ||
| openTelemetry = null; | ||
| } | ||
|
|
||
| private Builder(FirestoreOpenTelemetryOptions options) { | ||
| this.enabled = options.enabled; | ||
| this.openTelemetry = options.openTelemetry; | ||
| } | ||
|
|
||
| @Nonnull | ||
| public FirestoreOpenTelemetryOptions build() { | ||
| return new FirestoreOpenTelemetryOptions(this); | ||
| } | ||
|
|
||
| /** | ||
| * Sets whether tracing should be enabled. | ||
| * | ||
| * @param enable Whether tracing should be enabled. | ||
| */ | ||
| @Nonnull | ||
| public FirestoreOpenTelemetryOptions.Builder setTracingEnabled(boolean enable) { | ||
| this.enabled = enable; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the {@link OpenTelemetry} to use with this Firestore instance. If telemetry collection | ||
| * is enabled, but an `OpenTelemetry` is not provided, the Firestore SDK will attempt to use the | ||
| * `GlobalOpenTelemetry`. | ||
| * | ||
| * @param openTelemetry The OpenTelemetry that should be used by this Firestore instance. | ||
| */ | ||
| @Nonnull | ||
| public FirestoreOpenTelemetryOptions.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
103 changes: 103 additions & 0 deletions
103
...cloud-firestore/src/main/java/com/google/cloud/firestore/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,103 @@ | ||
| /* | ||
| * 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.firestore.telemetry; | ||
|
|
||
| import com.google.api.core.ApiFunction; | ||
| import com.google.api.core.ApiFuture; | ||
| import io.grpc.ManagedChannelBuilder; | ||
| import java.util.Map; | ||
| import javax.annotation.Nonnull; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| public class DisabledTraceUtil implements TraceUtil { | ||
|
|
||
| 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 DisabledTraceUtil.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.