Skip to content
This repository was archived by the owner on Mar 9, 2026. It is now read-only.

Commit 84b3a12

Browse files
committed
Add test for span context key warning
1 parent 6ebdf8e commit 84b3a12

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

google/cloud/pubsub_v1/opentelemetry_tracing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def create_span(span_name, attributes=None, parent=None):
6969
try:
7070
parent_span_context = SpanContext(**parent)
7171
except TypeError:
72-
_LOGGER.warn(
72+
_LOGGER.warning(
7373
"A parent span was provided but it could not be"
7474
"converted into a SpanContext. Ensure that the"
7575
"parent is a mapping with at least a trace_id, span_id"

google/cloud/pubsub_v1/publisher/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ def publish(self, topic, data, ordering_key="", **attrs):
378378
if span is not None:
379379

380380
if "googclient_OpenTelemetrySpanContext" in attrs:
381-
_LOGGER.warn(
381+
_LOGGER.warning(
382382
"googclient_OpenTelemetrySpanContext set on message"
383383
"as an attribute, but will be overridden."
384384
)

tests/unit/pubsub_v1/publisher/test_publisher_client.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import pytest
2222
import time
2323
import sys
24+
import logging
2425
from importlib import reload
2526

2627
from google.cloud.pubsub_v1.gapic import publisher_client
@@ -291,6 +292,16 @@ def test_publish_attrs_type_error():
291292
with pytest.raises(TypeError):
292293
client.publish(topic, b"foo", answer=42)
293294

295+
def test_publish_opentelemetry_span_key_warning(caplog):
296+
creds = mock.Mock(spec=credentials.Credentials)
297+
client = publisher.Client(credentials=creds)
298+
topic = "topic/path"
299+
300+
with caplog.at_level(logging.WARNING):
301+
client.publish(topic, b"foo", googclient_OpenTelemetrySpanContext=b"bar")
302+
303+
assert len(caplog.records) == 1
304+
294305

295306
def test_stop():
296307
creds = mock.Mock(spec=credentials.Credentials)

0 commit comments

Comments
 (0)