Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat(runtime_metrics): enable by default #12507

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 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
4 changes: 1 addition & 3 deletions ddtrace/settings/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,7 @@ def __init__(self):
self._telemetry_heartbeat_interval = _get_config("DD_TELEMETRY_HEARTBEAT_INTERVAL", 60, float)
self._telemetry_dependency_collection = _get_config("DD_TELEMETRY_DEPENDENCY_COLLECTION_ENABLED", True, asbool)

self._runtime_metrics_enabled = _get_config(
"DD_RUNTIME_METRICS_ENABLED", False, asbool, "OTEL_METRICS_EXPORTER"
)
self._runtime_metrics_enabled = _get_config("DD_RUNTIME_METRICS_ENABLED", True, asbool, "OTEL_METRICS_EXPORTER")

self._128_bit_trace_id_enabled = _get_config("DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED", True, asbool)

Expand Down
2 changes: 1 addition & 1 deletion docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ Other

DD_RUNTIME_METRICS_ENABLED:
type: Boolean
default: False
default: True

description: |
When used with ``ddtrace-run`` this configuration enables sending runtime metrics to Datadog.
Expand Down
5 changes: 5 additions & 0 deletions releasenotes/notes/ga-runtime-metrics-4fba9b4dbe63ce0f.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
features:
- |
runtime_metrics: Enable python `runtime metrics collection <https://docs.datadoghq.com/tracing/metrics/runtime_metrics/python/>`_ by default.
To disable this feature, set the environment variable ``DD_RUNTIME_METRICS_ENABLED`` to `false`.
4 changes: 3 additions & 1 deletion tests/commands/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,9 @@ def test_ddtrace_auto_imports():
assert module not in sys.modules, module


@pytest.mark.subprocess(ddtrace_run=True, env=dict(DD_UNLOAD_MODULES_FROM_SITECUSTOMIZE="1"))
@pytest.mark.subprocess(
ddtrace_run=True, env=dict(DD_UNLOAD_MODULES_FROM_SITECUSTOMIZE="1", DD_RUNTIME_METRICS_ENABLED="0")
)
def test_ddtrace_re_module():
import re

Expand Down
8 changes: 3 additions & 5 deletions tests/integration/test_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,6 @@ def test_runtime_metrics_enabled_via_manual_start():
from ddtrace.internal import debug
from ddtrace.runtime import RuntimeMetrics

f = debug.collect(ddtrace.tracer)
assert f.get("runtime_metrics_enabled") is False

RuntimeMetrics.enable()
f = debug.collect(ddtrace.tracer)
assert f.get("runtime_metrics_enabled") is True

Expand All @@ -259,7 +255,9 @@ def test_runtime_metrics_enabled_via_manual_start():
assert f.get("runtime_metrics_enabled") is False


@pytest.mark.subprocess(ddtrace_run=True, parametrize={"DD_RUNTIME_METRICS_ENABLED": ["0", "true"]}, err=None)
@pytest.mark.subprocess(
ddtrace_run=True, parametrize={"DD_RUNTIME_METRICS_ENABLED": ["0", "true", "false", "1"]}, err=None
)
def test_runtime_metrics_enabled_via_env_var_start():
import os

Expand Down
2 changes: 1 addition & 1 deletion tests/opentelemetry/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def test_otel_metrics_exporter_configuration():
def test_otel_metrics_exporter_configuration_unsupported_exporter():
from ddtrace import config

assert config._runtime_metrics_enabled is False, config._runtime_metrics_enabled
assert config._runtime_metrics_enabled, config._runtime_metrics_enabled


@pytest.mark.subprocess(
Expand Down
22 changes: 8 additions & 14 deletions tests/runtime/test_runtime_metrics_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,44 +96,38 @@ def test_manually_stop_runtime_metrics_telemetry(test_agent_session, ddtrace_run
assert runtimemetrics_enabled[0]["origin"] == "code"


def test_start_runtime_metrics_via_env_var(monkeypatch, ddtrace_run_python_code_in_subprocess):
def test_start_runtime_metrics_via_env_var(ddtrace_run_python_code_in_subprocess):
"""
When running with ddtrace-run and DD_RUNTIME_METRICS_ENABLED is set
Runtime metrics worker starts and there are no errors
"""

_, _, status, _ = ddtrace_run_python_code_in_subprocess(
"""
from ddtrace.runtime import RuntimeMetrics
assert not RuntimeMetrics._enabled
"""
)
assert status == 0

monkeypatch.setenv("DD_RUNTIME_METRICS_ENABLED", "true")
env = os.environ.copy()
env["DD_RUNTIME_METRICS_ENABLED"] = "true"
_, _, status, _ = ddtrace_run_python_code_in_subprocess(
"""
from ddtrace.runtime import RuntimeMetrics
assert RuntimeMetrics._enabled
""",
env=env,
)
assert status == 0


def test_runtime_metrics_via_env_var_manual_start(monkeypatch, ddtrace_run_python_code_in_subprocess):
def test_runtime_metrics_via_env_var_manual_start(ddtrace_run_python_code_in_subprocess):
"""
When running with ddtrace-run and DD_RUNTIME_METRICS_ENABLED is set and trying to start RuntimeMetrics manually
Runtime metrics worker starts and there are no errors
"""

monkeypatch.setenv("DD_RUNTIME_METRICS_ENABLED", "true")
env = os.environ.copy()
env["DD_RUNTIME_METRICS_ENABLED"] = "true"
_, _, status, _ = ddtrace_run_python_code_in_subprocess(
"""
from ddtrace.runtime import RuntimeMetrics
assert RuntimeMetrics._enabled
RuntimeMetrics.enable()
assert RuntimeMetrics._enabled
""",
env=env,
)
assert status == 0

Expand Down
Loading