Skip to content

Commit b2e9be7

Browse files
authored
chore(dbm): add injection mode environment variable (#4306)
## Description Adds `DD_TRACE_SQL_COMMENT_INJECTION_MODE` environment variable ## Checklist - [ ] Title must conform to [conventional commit](https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional). - [ ] Add additional sections for `feat` and `fix` pull requests. - [ ] Ensure tests are passing for affected code. - [ ] [Library documentation](https://github.com/DataDog/dd-trace-py/tree/1.x/docs) and/or [Datadog's documentation site](https://github.com/DataDog/documentation/) is updated. Link to doc PR in description. ## Motivation ## Design ## Testing strategy ## Relevant issue(s) ## Testing strategy ## Reviewer Checklist - [ ] Title is accurate. - [ ] Description motivates each change. - [ ] No unnecessary changes were introduced in this PR. - [ ] PR cannot be broken up into smaller PRs. - [ ] Avoid breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [ ] Tests provided or description of manual testing performed is included in the code or PR. - [ ] Release note has been added for fixes and features, or else `changelog/no-changelog` label added. - [ ] All relevant GitHub issues are correctly linked. - [ ] Backports are identified and tagged with Mergifyio. - [ ] Add to milestone.
1 parent f2a52a2 commit b2e9be7

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from envier import En
2+
from envier import validators
3+
4+
5+
class DatabaseMonitoringConfig(En):
6+
__prefix__ = "dd_trace"
7+
8+
injection_mode = En.v(
9+
str,
10+
"sql_comment_injection_mode",
11+
default="disabled",
12+
help="Valid Injection Modes: disabled, service, and full",
13+
validator=validators.choice(["disabled", "full", "service"]),
14+
)
15+
16+
17+
config = DatabaseMonitoringConfig()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import pytest
2+
3+
from ddtrace.settings import database_monitoring
4+
from tests.utils import override_env
5+
6+
7+
def test_injection_mode_configuration():
8+
# Ensure Database Monitoring support is disabled by default
9+
# TODO: Enable DBM support by default
10+
assert database_monitoring.config.injection_mode == "disabled"
11+
12+
# Ensure service is a valid injection mode
13+
with override_env(dict(DD_TRACE_SQL_COMMENT_INJECTION_MODE="service")):
14+
config = database_monitoring.DatabaseMonitoringConfig()
15+
assert config.injection_mode == "service"
16+
17+
# Ensure full is a valid injection mode
18+
with override_env(dict(DD_TRACE_SQL_COMMENT_INJECTION_MODE="full")):
19+
config = database_monitoring.DatabaseMonitoringConfig()
20+
assert config.injection_mode == "full"
21+
22+
# Ensure an invalid injection mode raises a ValueError
23+
with override_env(dict(DD_TRACE_SQL_COMMENT_INJECTION_MODE="notaninjectionmode")):
24+
with pytest.raises(ValueError) as excinfo:
25+
database_monitoring.DatabaseMonitoringConfig()
26+
assert (
27+
excinfo.value.args[0] == "Invalid value for environment variable DD_TRACE_SQL_COMMENT_INJECTION_MODE: "
28+
"value must be one of ['disabled', 'full', 'service']"
29+
)

0 commit comments

Comments
 (0)