Skip to content

Commit

Permalink
chore(configs): make rc and http configs internal [3.0] (#12055)
Browse files Browse the repository at this point in the history
Prefixes the following `ddtrace.config` attributes with an `_`. These
attributes are internal to the tracer and should not be referenced or
modified by users:
- http
- http_server
- trace_headers
- header_is_traced
- convert_rc_trace_sampling_rules
- enable_remote_configuration
- get_from

Users should enable remote configuration and set `http` configurations
via environment variables.

## Checklist
- [ ] PR author has checked that all the criteria below are met
- The PR description includes an overview of the change
- The PR description articulates the motivation for the change
- The change includes tests OR the PR description describes a testing
strategy
- The PR description notes risks associated with the change, if any
- Newly-added code is easy to change
- The change follows the [library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
- The change includes or references documentation updates if necessary
- Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))

## Reviewer Checklist
- [ ] Reviewer has checked that all the criteria below are met 
- Title is accurate
- All changes are related to the pull request's stated goal
- Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- Testing strategy adequately addresses listed risks
- Newly-added code is easy to change
- Release note makes sense to a user of the library
- If necessary, author has acknowledged and discussed the performance
implications of this PR as reported in the benchmarks PR comment
- Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
  • Loading branch information
mabdinur authored Jan 24, 2025
1 parent 3167f00 commit 48c6547
Show file tree
Hide file tree
Showing 41 changed files with 1,124 additions and 1,098 deletions.
2 changes: 1 addition & 1 deletion ddtrace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# configure ddtrace logger before other modules log
configure_ddtrace_logger() # noqa: E402

from .settings import _config as config
from .settings import _global_config as config


# Enable telemetry writer and excepthook as early as possible to ensure we capture any exceptions from initialization
Expand Down
2 changes: 1 addition & 1 deletion ddtrace/_monkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .internal import telemetry
from .internal.logger import get_logger
from .internal.utils import formats
from .settings import _config as config
from .settings import _global_config as config


if TYPE_CHECKING: # pragma: no cover
Expand Down
2 changes: 1 addition & 1 deletion ddtrace/_trace/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from ..internal.rate_limiter import RateLimiter
from ..internal.sampling import _get_highest_precedence_rule_matching
from ..internal.sampling import _set_sampling_tags
from ..settings import _config as ddconfig
from ..settings import _global_config as ddconfig
from .sampling_rule import SamplingRule


Expand Down
3 changes: 0 additions & 3 deletions ddtrace/contrib/flask/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ def index():
# Override service name
config.flask['service_name'] = 'custom-service-name'
# Report 401, and 403 responses as errors
config.http_server.error_statuses = '401,403'
.. __: http://flask.pocoo.org/
:ref:`All HTTP tags <http-tagging>` are supported for this integration.
Expand Down
12 changes: 0 additions & 12 deletions ddtrace/contrib/httplib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,8 @@
# Disable distributed tracing globally.
config.httplib['distributed_tracing'] = False
# Change the service distributed tracing option only for this HTTP
# connection.
# Python 2
connection = urllib.HTTPConnection('www.datadog.com')
# Python 3
connection = http.client.HTTPConnection('www.datadog.com')
cfg = config.get_from(connection)
cfg['distributed_tracing'] = True
:ref:`Headers tracing <http-headers-tracing>` is supported for this integration.
"""

Expand Down
2 changes: 1 addition & 1 deletion ddtrace/contrib/internal/aiohttp/middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def finish_request_span(request, response):
# DEV: aiohttp is special case maintains separate configuration from config api
trace_query_string = request[REQUEST_CONFIG_KEY].get("trace_query_string")
if trace_query_string is None:
trace_query_string = config.http.trace_query_string
trace_query_string = config._http.trace_query_string
if trace_query_string:
request_span.set_tag_str(http.QUERY_STRING, request.query_string)

Expand Down
2 changes: 1 addition & 1 deletion ddtrace/contrib/internal/botocore/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from ddtrace.internal.utils.formats import asbool
from ddtrace.internal.utils.formats import deep_getattr
from ddtrace.llmobs._integrations import BedrockIntegration
from ddtrace.settings.config import Config
from ddtrace.settings._config import Config
from ddtrace.trace import Pin

from .services.bedrock import patched_bedrock_api_call
Expand Down
2 changes: 1 addition & 1 deletion ddtrace/contrib/internal/dramatiq/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ddtrace.contrib import trace_utils
from ddtrace.ext import SpanKind
from ddtrace.ext import SpanTypes
from ddtrace.settings.config import Config
from ddtrace.settings._config import Config


def get_version() -> str:
Expand Down
2 changes: 1 addition & 1 deletion ddtrace/contrib/internal/httplib/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _wrap_request(func, instance, args, kwargs):
if should_skip_request(pin, instance):
return func_to_call(*args, **kwargs)

cfg = config.get_from(instance)
cfg = config._get_from(instance)

try:
# Create a new span and attach to this instance (so we can retrieve/update/close later on the response)
Expand Down
4 changes: 2 additions & 2 deletions ddtrace/contrib/internal/requests/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def _wrap_send(func, instance, args, kwargs):
hostname, path = _extract_hostname_and_path(url)
host_without_port = hostname.split(":")[0] if hostname is not None else None

cfg = config.get_from(instance)
cfg = config._get_from(instance)
service = None
if cfg["split_by_domain"] and hostname:
service = hostname
Expand All @@ -97,7 +97,7 @@ def _wrap_send(func, instance, args, kwargs):

# Configure trace search sample rate
# DEV: analytics enabled on per-session basis
cfg = config.get_from(instance)
cfg = config._get_from(instance)
analytics_enabled = cfg.get("analytics_enabled")
if analytics_enabled:
span.set_tag(_ANALYTICS_SAMPLE_RATE_KEY, cfg.get("analytics_sample_rate", True))
Expand Down
2 changes: 1 addition & 1 deletion ddtrace/contrib/internal/sanic/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ async def sanic_http_lifecycle_exception(request, exception):
# Do not attach exception for exceptions not considered as errors
# ex: Http 400s
# DEV: We still need to set `__dd_span_call_finish` below
if not hasattr(exception, "status_code") or config.http_server.is_error_code(exception.status_code):
if not hasattr(exception, "status_code") or config._http_server.is_error_code(exception.status_code):
ex_type = type(exception)
ex_tb = getattr(exception, "__traceback__", None)
span.set_exc_info(ex_type, exception, ex_tb)
Expand Down
2 changes: 1 addition & 1 deletion ddtrace/contrib/internal/tornado/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def log_exception(func, handler, args, kwargs):
# is not a 2xx. In this case we want to check the status code to be sure that
# only 5xx are traced as errors, while any other HTTPError exception is handled as
# usual.
if config.http_server.is_error_code(value.status_code):
if config._http_server.is_error_code(value.status_code):
current_span.set_exc_info(*args)
else:
# any other uncaught exception should be reported as error
Expand Down
2 changes: 1 addition & 1 deletion ddtrace/contrib/internal/trace_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def set_http_meta(
log.debug("failed to convert http status code %r to int", status_code)
else:
span.set_tag_str(http.STATUS_CODE, str(status_code))
if config.http_server.is_error_code(int_status_code):
if config._http_server.is_error_code(int_status_code):
span.error = 1

if status_msg is not None:
Expand Down
4 changes: 2 additions & 2 deletions ddtrace/contrib/jinja2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
The library can be configured globally and per instance, using the Configuration API::
from ddtrace import config
from ddtrace.trace import Pin
# Change service name globally
config.jinja2['service_name'] = 'jinja-templates'
# change the service name only for this environment
cfg = config.get_from(env)
cfg['service_name'] = 'jinja-templates'
Pin.override(env, service='jinja-templates')
By default, the service name is set to None, so it is inherited from the parent span.
If there is no parent span and the service name is not overridden the agent will drop the traces.
Expand Down
5 changes: 2 additions & 3 deletions ddtrace/contrib/requests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,11 @@
use the config API::
from ddtrace import config
from ddtrace.trace import Pin
from requests import Session
session = Session()
cfg = config.get_from(session)
cfg['service_name'] = 'auth-api'
cfg['distributed_tracing'] = False
Pin.override(session, service='auth-api')
"""


Expand Down
2 changes: 1 addition & 1 deletion ddtrace/internal/remoteconfig/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from ddtrace.internal.remoteconfig.utils import get_poll_interval_seconds
from ddtrace.internal.service import ServiceStatus
from ddtrace.internal.utils.time import StopWatch
from ddtrace.settings import _config as ddconfig
from ddtrace.settings import _global_config as ddconfig


log = get_logger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion ddtrace/internal/sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from ddtrace.internal.constants import SAMPLING_DECISION_TRACE_TAG_KEY
from ddtrace.internal.glob_matching import GlobMatcher
from ddtrace.internal.logger import get_logger
from ddtrace.settings import _config as config
from ddtrace.settings import _global_config as config

from .rate_limiter import RateLimiter

Expand Down
2 changes: 1 addition & 1 deletion ddtrace/internal/writer/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import ddtrace
from ddtrace.internal.utils.retry import fibonacci_backoff_with_jitter
from ddtrace.settings import _config as config
from ddtrace.settings import _global_config as config
from ddtrace.settings.asm import config as asm_config
from ddtrace.vendor.dogstatsd import DogStatsd

Expand Down
2 changes: 1 addition & 1 deletion ddtrace/propagation/_database_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from ..internal import compat
from ..internal.utils import get_argument_value
from ..internal.utils import set_argument_value
from ..settings import _config as dd_config
from ..settings import _global_config as dd_config
from ..settings._database_monitoring import dbm_config


Expand Down
4 changes: 2 additions & 2 deletions ddtrace/settings/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from .._hooks import Hooks
from .config import Config
from ._config import Config
from .exceptions import ConfigException
from .http import HttpConfig
from .integration import IntegrationConfig


# Default global config
_config = Config()
_global_config = Config()

__all__ = [
"Config",
Expand Down
Loading

0 comments on commit 48c6547

Please sign in to comment.