Skip to content
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
25 changes: 25 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,30 @@ jobs:
. venv/bin/activate
pytest -v

python37:
docker:
- image: circleci/python:3.7.9
- image: circleci/postgres:9.6.5-alpine-ram
- image: circleci/mariadb:10-ram
- image: circleci/redis:5.0.4
- image: rabbitmq:3.5.4
- image: circleci/mongo:4.2.3-ram
- image: singularities/pubsub-emulator
environment:
PUBSUB_PROJECT_ID: "project-test"
PUBSUB_LISTEN_ADDRESS: "0.0.0.0:8432"
working_directory: ~/repo
steps:
- checkout
- pip-install-deps
- run:
name: run tests
environment:
INSTANA_TEST: "true"
command: |
. venv/bin/activate
pytest -v

Comment on lines +79 to +102
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's see if we can run asqynp on Python 3.8 - if not, then we can have this additional test job.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like support only until Python 3.7: benjamin-hodgson/asynqp#104
We can keep it @pdimitra

python38:
docker:
- image: circleci/python:3.8.6
Expand Down Expand Up @@ -227,6 +251,7 @@ workflows:
build:
jobs:
- python27
- python37
- python38
- python39
- py27cassandra
Expand Down
18 changes: 10 additions & 8 deletions instana/span.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class InstanaSpan(BasicSpan):
stack = None
synthetic = False

def mark_as_errored(self, tags = None):
def mark_as_errored(self, tags=None):
"""
Mark this span as errored.

Expand Down Expand Up @@ -90,6 +90,7 @@ def log_exception(self, exc):
logger.debug("span.log_exception", exc_info=True)
raise


class BaseSpan(object):
sy = None

Expand Down Expand Up @@ -149,7 +150,7 @@ def _validate_tag(self, key, value):
try:
# Tag keys must be some type of text or string type
if isinstance(key, (six.text_type, six.string_types)):
validated_key = key[0:1024] # Max key length of 1024 characters
validated_key = key[0:1024] # Max key length of 1024 characters

if isinstance(value, (bool, float, int, list, dict, six.text_type, six.string_types)):
validated_value = value
Expand All @@ -169,7 +170,7 @@ def _convert_tag_value(self, value):
final_value = repr(value)
except Exception:
final_value = "(non-fatal) span.set_tag: values must be one of these types: bool, float, int, list, " \
"set, str or alternatively support 'repr'. tag discarded"
"set, str or alternatively support 'repr'. tag discarded"
logger.debug(final_value, exc_info=True)
return None
return final_value
Expand Down Expand Up @@ -247,24 +248,25 @@ def __init__(self, span, source, service_name, **kwargs):
super(RegisteredSpan, self).__init__(span, source, service_name, **kwargs)
self.n = span.operation_name
self.k = 1

if span.operation_name in self.ENTRY_SPANS:
# entry
self._populate_entry_span_data(span)
self.data["service"] = service_name
elif span.operation_name in self.EXIT_SPANS:
self.k = 2 # exit
self.k = 2 # exit
self._populate_exit_span_data(span)
elif span.operation_name in self.LOCAL_SPANS:
self.k = 3 # intermediate span
self.k = 3 # intermediate span
self._populate_local_span_data(span)

if "rabbitmq" in self.data and self.data["rabbitmq"]["sort"] == "consume":
Copy link
Contributor

Choose a reason for hiding this comment

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

@pdimitra:

I checked span.py and it seems like the _populate_entry_span_data & _populate_exit_span_data for rabbitmq is the same. In this case, we can let it stay in the ENTRY_SPANS tuple and just change the method here to publish and set self.k = 2

self.k = 1 # entry
if "rabbitmq" in self.data and self.data["rabbitmq"]["sort"] == "publish":
self.k = 2 # exit

# unify the span operation_name for gcps-producer and gcps-consumer
if "gcps" in span.operation_name:
self.n = 'gcps'

# Store any leftover tags in the custom section
if len(span.tags) > 0:
self.data["custom"]["tags"] = self._validate_tags(span.tags)
Expand Down
26 changes: 25 additions & 1 deletion tests/clients/test_asynqp.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
rabbitmq_host = "localhost"

is_unsupported_version = LooseVersion(sys.version) < LooseVersion('3.5.3') \
or LooseVersion(sys.version) >= LooseVersion('3.8.0')
or LooseVersion(sys.version) >= LooseVersion('3.8.0')


@pytest.mark.skipif(is_unsupported_version, reason="Asynqp supports >=3.5.3;<3.8.0")
class TestAsynqp(unittest.TestCase):
Expand Down Expand Up @@ -96,6 +97,9 @@ def test():
self.assertIsNone(test_span.ec)
self.assertIsNone(rabbitmq_span.ec)

# Span type
self.assertEqual(rabbitmq_span.k, 2) # exit

# Rabbitmq
self.assertEqual('test.exchange', rabbitmq_span.data["rabbitmq"]["exchange"])
self.assertEqual('publish', rabbitmq_span.data["rabbitmq"]["sort"])
Expand Down Expand Up @@ -132,6 +136,9 @@ def test():
self.assertIsNone(test_span.ec)
self.assertIsNone(rabbitmq_span.ec)

# Span type
self.assertEqual(rabbitmq_span.k, 2) # exit

# Rabbitmq
self.assertEqual('test.exchange', rabbitmq_span.data["rabbitmq"]["exchange"])
self.assertEqual('publish', rabbitmq_span.data["rabbitmq"]["sort"])
Expand Down Expand Up @@ -196,6 +203,10 @@ def publish():
self.assertEqual(publish_span.p, test_span.s)
self.assertEqual(get_span.p, test_span.s)

# Span type
self.assertEqual(publish_span.k, 2) # exit
self.assertEqual(get_span.k, 1) # entry

# Error logging
self.assertIsNone(test_span.ec)
self.assertIsNone(publish_span.ec)
Expand Down Expand Up @@ -250,6 +261,10 @@ def test():
self.assertEqual(publish_span.p, test_span.s)
self.assertEqual(consume_span.p, publish_span.s)

# Span type
self.assertEqual(publish_span.k, 2) # exit
self.assertEqual(consume_span.k, 1) # entry

# publish
self.assertEqual('test.exchange', publish_span.data["rabbitmq"]["exchange"])
self.assertEqual('publish', publish_span.data["rabbitmq"]["sort"])
Expand Down Expand Up @@ -311,6 +326,11 @@ def test():
self.assertEqual(consume1_span.p, publish1_span.s)
self.assertEqual(publish2_span.p, consume1_span.s)

# Span type
self.assertEqual(publish1_span.k, 2) # exit
self.assertEqual(consume1_span.k, 1) # entry
self.assertEqual(publish2_span.k, 2) # exit

# publish
self.assertEqual('test.exchange', publish1_span.data["rabbitmq"]["exchange"])
self.assertEqual('publish', publish1_span.data["rabbitmq"]["sort"])
Expand Down Expand Up @@ -402,6 +422,10 @@ def test():
self.assertEqual(run_later_span.p, consume_span.s)
self.assertEqual(wsgi_span.p, aioclient_span.s)

# Span type
self.assertEqual(publish_span.k, 2) # exit
self.assertEqual(consume_span.k, 1) # entry

# publish
self.assertEqual('test.exchange', publish_span.data["rabbitmq"]["exchange"])
self.assertEqual('publish', publish_span.data["rabbitmq"]["sort"])
Expand Down