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)
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)
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)
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))
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))
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))
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)
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)
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")
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)()
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", )
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
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"))
""" 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"]
"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", )