Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Adding warning to log/log_event calls #255

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 2 commits into from
Oct 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ext/opentelemetry-ext-opentracing-shim/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ package_dir=
=src
packages=find_namespace:
install_requires =
Deprecated >= 1.2.6
opentracing
opentelemetry-api

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import logging

import opentracing
from deprecated import deprecated

from opentelemetry.ext.opentracing_shim import util

Expand Down Expand Up @@ -77,6 +78,14 @@ def log_kv(self, key_values, timestamp=None):
self._otel_span.add_event(event_name, event_timestamp, key_values)
return self

@deprecated(reason="This method is deprecated in favor of log_kv")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I feel we should add these to opentracing itself too ;) )

def log(self, **kwargs):
super().log(**kwargs)

@deprecated(reason="This method is deprecated in favor of log_kv")
def log_event(self, event, payload=None):
super().log_event(event, payload=payload)

def set_baggage_item(self, key, value):
logger.warning(
"Calling unimplemented method set_baggage_item() on class %s",
Expand All @@ -91,10 +100,6 @@ def get_baggage_item(self, key):
)
# TODO: Implement.

# TODO: Verify calls to deprecated methods `log_event()` and `log()` on
# base class work properly (it's probably fine because both methods call
# `log_kv()`).


class ScopeShim(opentracing.Scope):
"""A `ScopeShim` wraps the OpenTelemetry functionality related to span
Expand Down
22 changes: 22 additions & 0 deletions ext/opentelemetry-ext-opentracing-shim/tests/test_shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,28 @@ def test_log_kv(self):
# biggest possible loss of precision.
self.assertAlmostEqual(result, now, places=6)

def test_log(self):
"""Test the deprecated `log` method on `Span` objects."""

with self.shim.start_span("TestSpan") as span:
with self.assertWarns(DeprecationWarning):
span.log(event="foo", payload="bar")

self.assertEqual(span.unwrap().events[0].attributes["event"], "foo")
self.assertEqual(span.unwrap().events[0].attributes["payload"], "bar")
self.assertIsNotNone(span.unwrap().events[0].timestamp)

def test_log_event(self):
"""Test the deprecated `log_event` method on `Span` objects."""

with self.shim.start_span("TestSpan") as span:
with self.assertWarns(DeprecationWarning):
span.log_event("foo", "bar")

self.assertEqual(span.unwrap().events[0].attributes["event"], "foo")
self.assertEqual(span.unwrap().events[0].attributes["payload"], "bar")
self.assertIsNotNone(span.unwrap().events[0].timestamp)

def test_span_context(self):
"""Test construction of `SpanContextShim` objects."""

Expand Down