From ca4680f76642cc95acf40f27abf19ea93375f40a Mon Sep 17 00:00:00 2001 From: Mike Prieto Date: Thu, 12 Sep 2024 07:13:16 +0000 Subject: [PATCH] feat: Initialize default no-op PubsubTracer in Publisher and Subscriber --- .../cloud/pubsub/v1/BasePubsubTracer.java | 21 +++++++++++++++++++ .../com/google/cloud/pubsub/v1/Publisher.java | 2 +- .../google/cloud/pubsub/v1/Subscriber.java | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/BasePubsubTracer.java diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/BasePubsubTracer.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/BasePubsubTracer.java new file mode 100644 index 000000000..f574ee163 --- /dev/null +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/BasePubsubTracer.java @@ -0,0 +1,21 @@ +/* + * 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.pubsub.v1; + +public class BasePubsubTracer implements PubsubTracer { + BasePubsubTracer() {} +} diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Publisher.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Publisher.java index 0aed2428d..5cd20235d 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Publisher.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Publisher.java @@ -131,7 +131,7 @@ public class Publisher implements PublisherInterface { private final boolean enableOpenTelemetryTracing; private final OpenTelemetry openTelemetry; - private PubsubTracer tracer = null; + private PubsubTracer tracer = new BasePubsubTracer(); /** The maximum number of messages in one request. Defined by the API. */ public static long getApiMaxRequestElementCount() { diff --git a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Subscriber.java b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Subscriber.java index aceea0c86..a6413389f 100644 --- a/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Subscriber.java +++ b/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Subscriber.java @@ -151,7 +151,7 @@ public class Subscriber extends AbstractApiService implements SubscriberInterfac private final boolean enableOpenTelemetryTracing; private final OpenTelemetry openTelemetry; - private PubsubTracer tracer = null; + private PubsubTracer tracer = new BasePubsubTracer(); private Subscriber(Builder builder) { receiver = builder.receiver;