예제 #1
0
def _get_endpoint():
    legacy = os.environ.get("DD_PROFILING_API_URL")
    if legacy:
        deprecation.deprecation("DD_PROFILING_API_URL", "Use DD_SITE")
        return legacy
    site = os.environ.get("DD_SITE", "datadoghq.com")
    return ENDPOINT_TEMPLATE.format(site)
예제 #2
0
def _get_default_url(
    tracer,  # type: Optional[ddtrace.Tracer]
    api_key,  # type: str
):
    # type: (...) -> str
    """Get default profiler exporter URL.

    If an API key is not specified, the URL will default to the agent location configured via the environment variables.

    If an API key is specified, the profiler goes into agentless mode and uses `DD_SITE` to upload directly to Datadog
    backend.

    :param api_key: The API key provided by the user.
    :param tracer: The tracer object to use to find default URL.
    """
    # Default URL changes if an API_KEY is provided in the env
    if api_key is None:
        if tracer is None:
            return agent.get_trace_url()
        else:
            # Only use the tracer writer URL if it has been modified by the user.
            if tracer.writer.agent_url != agent.get_trace_url() and tracer.writer.agent_url != agent.DEFAULT_TRACE_URL:
                return tracer.writer.agent_url
            else:
                return agent.get_trace_url()
    # Agentless mode
    legacy = os.environ.get("DD_PROFILING_API_URL")
    if legacy:
        deprecation.deprecation("DD_PROFILING_API_URL", "Use DD_SITE")
        return legacy
    site = os.environ.get("DD_SITE", "datadoghq.com")
    return ENDPOINT_TEMPLATE.format(site)
예제 #3
0
def _get_endpoint():
    legacy = _attr.from_env("DD_PROFILING_API_URL", "", str)()
    if legacy:
        deprecation.deprecation("DD_PROFILING_API_URL", "Use DD_SITE")
        return legacy
    site = _attr.from_env("DD_SITE", "datadoghq.com", str)()
    return ENDPOINT_TEMPLATE.format(site)
예제 #4
0
 def test_deprecation(self):
     # ensure `deprecation` properly raise a DeprecationWarning
     with warnings.catch_warnings(record=True) as w:
         warnings.simplefilter("always")
         deprecation(name="fn", message="message", version="1.0.0")
         self.assertEqual(len(w), 1)
         self.assertTrue(issubclass(w[-1].category, DeprecationWarning))
         self.assertIn("message", str(w[-1].message))
예제 #5
0
 def test_deprecation(self):
     # ensure `deprecation` properly raise a DeprecationWarning
     with warnings.catch_warnings(record=True) as w:
         warnings.simplefilter('always')
         deprecation(name='fn', message='message', version='1.0.0')
         self.assertEqual(len(w), 1)
         self.assertTrue(issubclass(w[-1].category, DeprecationWarning))
         self.assertIn('message', str(w[-1].message))
예제 #6
0
 def test_deprecation(self):
     # ensure `deprecation` properly raise a DeprecationWarning
     with warnings.catch_warnings(record=True) as w:
         warnings.simplefilter('always')
         deprecation(
             name='fn',
             message='message',
             version='1.0.0'
         )
         ok_(len(w) == 1)
         ok_(issubclass(w[-1].category, DeprecationWarning))
         ok_('message' in str(w[-1].message))
예제 #7
0
def _get_default_url(
        tracer,  # type: Optional[ddtrace.Tracer]
        api_key,  # type: str
):
    # type: (...) -> str
    """Get default profiler exporter URL.

    If an API key is not specified, the URL will default to the agent location configured via the environment variables.

    If an API key is specified, the profiler goes into agentless mode and uses `DD_SITE` to upload directly to Datadog
    backend.

    :param api_key: The API key provided by the user.
    :param tracer: The tracer object to use to find default URL.
    """
    # Default URL changes if an API_KEY is provided in the env
    if api_key is None:
        if tracer is None:
            default_hostname = "localhost"
            default_port = 8126
            scheme = "http"
            path = ""
        else:
            default_hostname = tracer.writer.api.hostname
            default_port = tracer.writer.api.port
            if tracer.writer.api.https:
                scheme = "https"
                path = ""
            elif tracer.writer.api.uds_path is not None:
                scheme = "unix"
                path = tracer.writer.api.uds_path
            else:
                scheme = "http"
                path = ""

        hostname = os.environ.get(
            "DD_AGENT_HOST",
            os.environ.get("DATADOG_TRACE_AGENT_HOSTNAME", default_hostname))
        port = int(os.environ.get("DD_TRACE_AGENT_PORT", default_port))

        return os.environ.get("DD_TRACE_AGENT_URL",
                              "%s://%s:%d%s" % (scheme, hostname, port, path))

    # Agentless mode
    legacy = os.environ.get("DD_PROFILING_API_URL")
    if legacy:
        deprecation.deprecation("DD_PROFILING_API_URL", "Use DD_SITE")
        return legacy
    site = os.environ.get("DD_SITE", "datadoghq.com")
    return ENDPOINT_TEMPLATE.format(site)
예제 #8
0
def _get_default_url(api_key):
    """Get default profiler exporter URL.

    If an API key is not specified, the URL will default to the agent location configured via the environment variables.

    If an API key is specified, the profiler goes into agentless mode and uses `DD_SITE` to upload directly to Datadog
    backend.
    """
    # Default URL changes if an API_KEY is provided in the env
    if api_key is None:
        hostname = os.environ.get(
            "DD_AGENT_HOST",
            os.environ.get("DATADOG_TRACE_AGENT_HOSTNAME", "localhost"))
        port = int(os.environ.get("DD_TRACE_AGENT_PORT", 8126))
        return os.environ.get("DD_TRACE_AGENT_URL",
                              "http://%s:%d" % (hostname, port))

    # Agentless mode
    legacy = os.environ.get("DD_PROFILING_API_URL")
    if legacy:
        deprecation.deprecation("DD_PROFILING_API_URL", "Use DD_SITE")
        return legacy
    site = os.environ.get("DD_SITE", "datadoghq.com")
    return ENDPOINT_TEMPLATE.format(site)
예제 #9
0
def _get_api_key():
    legacy = os.environ.get("DD_PROFILING_API_KEY")
    if legacy:
        deprecation.deprecation("DD_PROFILING_API_KEY", "Use DD_API_KEY")
        return legacy
    return os.environ.get("DD_API_KEY")
예제 #10
0
def _get_api_key():
    legacy = _attr.from_env("DD_PROFILING_API_KEY", "", str)()
    if legacy:
        deprecation.deprecation("DD_PROFILING_API_KEY", "Use DD_API_KEY")
        return legacy
    return _attr.from_env("DD_API_KEY", "", str)()
예제 #11
0
from ddtrace.contrib.trace_utils import NORMALIZE_PATTERN
from ddtrace.contrib.trace_utils import REQUEST
from ddtrace.contrib.trace_utils import RESPONSE
from ddtrace.contrib.trace_utils import _normalize_tag_name
from ddtrace.contrib.trace_utils import _normalized_header_name
from ddtrace.contrib.trace_utils import _store_headers
from ddtrace.contrib.trace_utils import _store_request_headers as store_request_headers
from ddtrace.contrib.trace_utils import _store_response_headers as store_response_headers
from ddtrace.utils.deprecation import deprecation


__all__ = (
    "store_request_headers",
    "store_response_headers",
    "NORMALIZE_PATTERN",
    "REQUEST",
    "RESPONSE",
    "_store_headers",
    "_normalized_header_name",
    "_normalize_tag_name",
)

deprecation(
    name="ddtrace.http.headers",
    message="The http.headers module has been merged into ddtrace.contrib.trace_utils",
    version="1.0.0",
)
예제 #12
0
    def __init__(
            self,
            url=None,  # type: Optional[str]
            dogstatsd_url=None,  # type: Optional[str]
    ):
        # type: (...) -> None
        """
        Create a new ``Tracer`` instance. A global tracer is already initialized
        for common usage, so there is no need to initialize your own ``Tracer``.

        :param url: The Datadog agent URL.
        :param dogstatsd_url: The DogStatsD URL.
        """
        self.log = log
        self._filters = []  # type: List[TraceFilter]

        # globally set tags
        self.tags = config.tags.copy()

        # a buffer for service info so we don't perpetually send the same things
        self._services = set()  # type: Set[str]

        # Runtime id used for associating data collected during runtime to
        # traces
        self._pid = getpid()

        self.enabled = asbool(get_env("trace", "enabled", default=True))
        self.context_provider = DefaultContextProvider()
        self.sampler = DatadogSampler()  # type: BaseSampler
        self.priority_sampler = RateByServiceSampler(
        )  # type: Optional[BasePrioritySampler]
        self._dogstatsd_url = agent.get_stats_url(
        ) if dogstatsd_url is None else dogstatsd_url

        if self._use_log_writer() and url is None:
            writer = LogWriter()  # type: TraceWriter
        else:
            url = url or agent.get_trace_url()
            agent.verify_url(url)

            writer = AgentWriter(
                agent_url=url,
                sampler=self.sampler,
                priority_sampler=self.priority_sampler,
                dogstatsd=get_dogstatsd_client(self._dogstatsd_url),
                report_metrics=config.health_metrics_enabled,
                sync_mode=self._use_sync_mode(),
            )
        self.writer = writer  # type: TraceWriter

        # DD_TRACER_... should be deprecated after version 1.0.0 is released
        pfe_default_value = False
        pfms_default_value = 500
        if "DD_TRACER_PARTIAL_FLUSH_ENABLED" in os.environ or "DD_TRACER_PARTIAL_FLUSH_MIN_SPANS" in os.environ:
            deprecation("DD_TRACER_... use DD_TRACE_... instead",
                        version="1.0.0")
            pfe_default_value = asbool(
                get_env("tracer",
                        "partial_flush_enabled",
                        default=pfe_default_value))
            pfms_default_value = int(
                get_env("tracer",
                        "partial_flush_min_spans",
                        default=pfms_default_value)  # type: ignore[arg-type]
            )
        self._partial_flush_enabled = asbool(
            get_env("trace",
                    "partial_flush_enabled",
                    default=pfe_default_value))
        self._partial_flush_min_spans = int(
            get_env("trace",
                    "partial_flush_min_spans",
                    default=pfms_default_value)  # type: ignore[arg-type]
        )

        self._initialize_span_processors()
        self._hooks = _hooks.Hooks()
        atexit.register(self._atexit)
        forksafe.register(self._child_after_fork)

        self._shutdown_lock = RLock()

        self._new_process = False
예제 #13
0
import importlib
import sys

from ddtrace.utils import deprecation


deprecation.deprecation("ddtrace.profile", "Use ddtrace.profiling instead.")

sys.modules[__name__] = importlib.import_module(__name__.replace("ddtrace.profile", "ddtrace.profiling"))
예제 #14
0
"""
Priority is a hint given to the backend so that it knows which traces to reject or kept.
In a distributed context, it should be set before any context propagation (fork, RPC calls) to be effective.

For example:

from ddtrace.ext.priority import USER_REJECT, USER_KEEP

context = tracer.context_provider.active()
# Indicate to not keep the trace
context.sampling_priority = USER_REJECT

# Indicate to keep the trace
span.context.sampling_priority = USER_KEEP
"""
from ddtrace.constants import AUTO_KEEP
from ddtrace.constants import AUTO_REJECT
from ddtrace.constants import USER_KEEP
from ddtrace.constants import USER_REJECT
from ddtrace.utils.deprecation import deprecation

deprecation(
    name="ddtrace.ext.priority",
    message="Use `ddtrace.constants` module instead",
    version="1.0.0",
)

__all__ = ["USER_REJECT", "AUTO_REJECT", "AUTO_KEEP", "USER_KEEP"]
예제 #15
0
파일: compat.py 프로젝트: nizox/dd-trace-py
    "get_connection_response",
    "getrandbits",
    "httplib",
    "is_integer",
    "iscoroutinefunction",
    "iteritems",
    "main_thread",
    "make_async_decorator",
    "monotonic",
    "monotonic_ns",
    "msgpack_type",
    "numeric_types",
    "parse",
    "pattern_type",
    "process_time_ns",
    "reload_module",
    "reraise",
    "string_type",
    "stringify",
    "time_ns",
    "to_unicode",
    "urlencode",
]

deprecation(
    name="ddtrace.compat",
    message=
    "The compat module has been moved to ddtrace.internal and will no longer be part of the public API.",
    version="1.0.0",
)