Exemplo n.º 1
0
def test_tracer_with_env():
    t = ddtrace.Tracer()

    # With global `config.env` defined
    with override_global_config(dict(env="prod")):
        with t.trace("test.span") as span:
            assert span.get_tag(ENV_KEY) == "prod"

            # override manually
            span.set_tag(ENV_KEY, "prod-staging")
            assert span.get_tag(ENV_KEY) == "prod-staging"

    # With no `config.env` defined
    with t.trace("test.span") as span:
        assert span.get_tag(ENV_KEY) is None

        # explicitly set in the span
        span.set_tag(ENV_KEY, "prod-staging")
        assert span.get_tag(ENV_KEY) == "prod-staging"

    # With global tags set
    t.set_tags({ENV_KEY: "tags.env"})
    with override_global_config(dict(env="config.env")):
        with t.trace("test.span") as span:
            assert span.get_tag(ENV_KEY) == "config.env"
Exemplo n.º 2
0
def test_tracer_with_env():
    t = ddtrace.Tracer()

    # With global `config.env` defined
    with override_global_config(dict(env='prod')):
        with t.trace('test.span') as span:
            assert span.get_tag(ENV_KEY) == 'prod'

            # override manually
            span.set_tag(ENV_KEY, 'prod-staging')
            assert span.get_tag(ENV_KEY) == 'prod-staging'

    # With no `config.env` defined
    with t.trace('test.span') as span:
        assert span.get_tag(ENV_KEY) is None

        # explicitly set in the span
        span.set_tag(ENV_KEY, 'prod-staging')
        assert span.get_tag(ENV_KEY) == 'prod-staging'

    # With global tags set
    t.set_tags({ENV_KEY: 'tags.env'})
    with override_global_config(dict(env='config.env')):
        with t.trace('test.span') as span:
            assert span.get_tag(ENV_KEY) == 'config.env'
Exemplo n.º 3
0
def test_tracer_with_version():
    t = ddtrace.Tracer()

    # With global `config.version` defined
    with override_global_config(dict(version="1.2.3")):
        with t.trace("test.span") as span:
            assert span.get_tag(VERSION_KEY) == "1.2.3"

            # override manually
            span.set_tag(VERSION_KEY, "4.5.6")
            assert span.get_tag(VERSION_KEY) == "4.5.6"

    # With no `config.version` defined
    with t.trace("test.span") as span:
        assert span.get_tag(VERSION_KEY) is None

        # explicitly set in the span
        span.set_tag(VERSION_KEY, "1.2.3")
        assert span.get_tag(VERSION_KEY) == "1.2.3"

    # With global tags set
    t.set_tags({VERSION_KEY: "tags.version"})
    with override_global_config(dict(version="config.version")):
        with t.trace("test.span") as span:
            assert span.get_tag(VERSION_KEY) == "config.version"
Exemplo n.º 4
0
def test_tracer_with_version():
    t = ddtrace.Tracer()

    # With global `config.version` defined
    with override_global_config(dict(version='1.2.3')):
        with t.trace('test.span') as span:
            assert span.get_tag(VERSION_KEY) == '1.2.3'

            # override manually
            span.set_tag(VERSION_KEY, '4.5.6')
            assert span.get_tag(VERSION_KEY) == '4.5.6'

    # With no `config.version` defined
    with t.trace('test.span') as span:
        assert span.get_tag(VERSION_KEY) is None

        # explicitly set in the span
        span.set_tag(VERSION_KEY, '1.2.3')
        assert span.get_tag(VERSION_KEY) == '1.2.3'

    # With global tags set
    t.set_tags({VERSION_KEY: 'tags.version'})
    with override_global_config(dict(version='config.version')):
        with t.trace('test.span') as span:
            assert span.get_tag(VERSION_KEY) == 'config.version'
Exemplo n.º 5
0
def test_metrics():
    with override_global_config(dict(health_metrics_enabled=True)):
        t = Tracer()
        statsd_mock = mock.Mock()
        t.writer.dogstatsd = statsd_mock
        assert t.writer._report_metrics
        with mock.patch("ddtrace.internal.writer.log") as log:
            for _ in range(5):
                spans = []
                for i in range(3000):
                    spans.append(t.trace("op"))
                for s in spans:
                    s.finish()

            t.shutdown()
            log.warning.assert_not_called()
            log.error.assert_not_called()

        statsd_mock.distribution.assert_has_calls(
            [
                mock.call("datadog.tracer.buffer.accepted.traces", 5, tags=[]),
                mock.call(
                    "datadog.tracer.buffer.accepted.spans", 15000, tags=[]),
                mock.call("datadog.tracer.http.requests", 1, tags=[]),
                mock.call("datadog.tracer.http.sent.bytes", AnyInt()),
            ],
            any_order=True,
        )
Exemplo n.º 6
0
def test_unicode_config_vals():
    t = ddtrace.Tracer()

    with override_global_config(dict(version=u"😇", env=u"😇")):
        with t.trace("1"):
            pass
    t.shutdown()
Exemplo n.º 7
0
def test_int_service_integration(int_config):
    pin = Pin()
    tracer = Tracer()
    assert trace_utils.int_service(pin, int_config.myint) is None

    with override_global_config(dict(service="global-svc")):
        assert trace_utils.int_service(pin, int_config.myint) is None

        with tracer.trace("something", service=trace_utils.int_service(pin, int_config.myint)) as s:
            assert s.service == "global-svc"
Exemplo n.º 8
0
def test_get_report_hostname_default(get_hostname, tracer, test_spans):
    get_hostname.return_value = "test-hostname"
    with override_global_config(dict(report_hostname=False)):
        with tracer.trace("span"):
            with tracer.trace("child"):
                pass

    spans = test_spans.pop()
    root = spans[0]
    child = spans[1]
    assert root.get_tag(HOSTNAME_KEY) is None
    assert child.get_tag(HOSTNAME_KEY) is None
Exemplo n.º 9
0
def test_get_report_hostname_disabled(get_hostname):
    get_hostname.return_value = "test-hostname"
    tracer = Tracer()
    tracer.writer = DummyWriter()

    with override_global_config(dict(report_hostname=False)):
        with tracer.trace("span"):
            with tracer.trace("child"):
                pass

    spans = tracer.writer.pop()
    root = spans[0]
    child = spans[1]
    assert root.get_tag(HOSTNAME_KEY) is None
    assert child.get_tag(HOSTNAME_KEY) is None