Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add tracing tests #72

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
57 changes: 57 additions & 0 deletions tests/test_tracing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import ddtrace

from xocto import tracing


class TestSetTags:
def test_single_string_tag(self, mocker):
span = ddtrace.Span(name="active-span")
mocker.patch("xocto.tracing.ddtrace.tracer.current_span", return_value=span)
assert tracing.set_tags({"foo": "bar"}) is None
assert span.get_tag("foo") == "bar"

def test_single_bytes_tag(self, mocker):
span = ddtrace.Span(name="active-span")
mocker.patch("xocto.tracing.ddtrace.tracer.current_span", return_value=span)
assert tracing.set_tags({"foo": b"bar"}) is None
# bytes cast to str in Python 3, unicode in Python 2 (Python 2 not tested)
# see https://ddtrace.readthedocs.io/en/stable/api.html#ddtrace.Span.set_tag_str
assert span.get_tag("foo") == str(b"bar")

def test_multiple_string_tags(self, mocker):
span = ddtrace.Span(name="active-span")
mocker.patch("xocto.tracing.ddtrace.tracer.current_span", return_value=span)
tags = {"foo": "bar", "animal": "cat"}
assert tracing.set_tags(tags) is None
assert span.get_tag("foo") == "bar"
assert span.get_tag("animal") == "cat"

def test_multiple_mixed_type_tags(self, mocker):
span = ddtrace.Span(name="active-span")
mocker.patch("xocto.tracing.ddtrace.tracer.current_span", return_value=span)
tags = {"foo": "bar", "animal": b"cat"}
assert tracing.set_tags(tags) is None
assert span.get_tag("foo") == "bar"
assert span.get_tag("animal") == str(b"cat")


class TestSetTag:
def test_single_string_tag(self, mocker):
span = ddtrace.Span(name="active-span")
mocker.patch("xocto.tracing.ddtrace.tracer.current_span", return_value=span)
assert tracing.set_tag(key="foo", value="bar") is None
assert span.get_tag("foo") == "bar"

def test_single_bytes_tag(self, mocker):
span = ddtrace.Span(name="active-span")
mocker.patch("xocto.tracing.ddtrace.tracer.current_span", return_value=span)
assert tracing.set_tag(key="foo", value=b"bar") is None
assert span.get_tag("foo") == str(b"bar")


class TestSetGlobalTag:
def test_set_string_tag(self, mocker):
span = ddtrace.Span(name="root-span")
mocker.patch("xocto.tracing.ddtrace.tracer.current_root_span", return_value=span)
assert tracing.set_global_tag(key="foo", value="bar") is None
assert span.get_tag("foo") == "bar"