Skip to content

Commit

Permalink
Add test for span context key warning
Browse files Browse the repository at this point in the history
  • Loading branch information
sethmaxwl committed Jul 16, 2020
1 parent 6ebdf8e commit 84b3a12
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion google/cloud/pubsub_v1/opentelemetry_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def create_span(span_name, attributes=None, parent=None):
try:
parent_span_context = SpanContext(**parent)
except TypeError:
_LOGGER.warn(
_LOGGER.warning(
"A parent span was provided but it could not be"
"converted into a SpanContext. Ensure that the"
"parent is a mapping with at least a trace_id, span_id"
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/pubsub_v1/publisher/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def publish(self, topic, data, ordering_key="", **attrs):
if span is not None:

if "googclient_OpenTelemetrySpanContext" in attrs:
_LOGGER.warn(
_LOGGER.warning(
"googclient_OpenTelemetrySpanContext set on message"
"as an attribute, but will be overridden."
)
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/pubsub_v1/publisher/test_publisher_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import pytest
import time
import sys
import logging
from importlib import reload

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

def test_publish_opentelemetry_span_key_warning(caplog):
creds = mock.Mock(spec=credentials.Credentials)
client = publisher.Client(credentials=creds)
topic = "topic/path"

with caplog.at_level(logging.WARNING):
client.publish(topic, b"foo", googclient_OpenTelemetrySpanContext=b"bar")

assert len(caplog.records) == 1


def test_stop():
creds = mock.Mock(spec=credentials.Credentials)
Expand Down

0 comments on commit 84b3a12

Please sign in to comment.