Skip to content

Commit 4a2e4d4

Browse files
fix(botocore) ensure env vars are parsed as booleans (#2980) (#2988)
* fix(botocore) ensure env vars are parsed as booleans fixes #2978 We were not calling `asbool` when parsing the values * add booleans to spelling list * Add testcases Co-authored-by: Kyle Verhoog <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> (cherry picked from commit 2f830fa) Co-authored-by: Brett Langdon <[email protected]>
1 parent 7cbd938 commit 4a2e4d4

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

ddtrace/contrib/botocore/patch.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from ...pin import Pin
2121
from ...propagation.http import HTTPPropagator
2222
from ...utils import get_argument_value
23+
from ...utils.formats import asbool
2324
from ...utils.formats import deep_getattr
2425
from ...utils.formats import get_env
2526
from ...utils.wrappers import unwrap
@@ -37,8 +38,8 @@
3738
config._add(
3839
"botocore",
3940
{
40-
"distributed_tracing": get_env("botocore", "distributed_tracing", default=True),
41-
"invoke_with_legacy_context": get_env("botocore", "invoke_with_legacy_context", default=False),
41+
"distributed_tracing": asbool(get_env("botocore", "distributed_tracing", default=True)),
42+
"invoke_with_legacy_context": asbool(get_env("botocore", "invoke_with_legacy_context", default=False)),
4243
},
4344
)
4445

docs/spelling_wordlist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ autopatching
2525
backend
2626
backends
2727
bikeshedding
28+
booleans
2829
boto
2930
botocore
3031
CGroup
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
Fixes parsing of ``botocore`` env variables to ensure they are parsed as booleans.

tests/contrib/botocore/test.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# 3p
21
import base64
32
import datetime
43
import io
@@ -15,6 +14,7 @@
1514
from moto import mock_sqs
1615

1716
from ddtrace import Pin
17+
from ddtrace import config
1818
from ddtrace.constants import ANALYTICS_SAMPLE_RATE_KEY
1919
from ddtrace.contrib.botocore.patch import patch
2020
from ddtrace.contrib.botocore.patch import unpatch
@@ -805,3 +805,15 @@ def test_firehose_no_records_arg(self):
805805
assert delivery_stream_span.get_tag("aws.operation") == "CreateDeliveryStream"
806806
assert put_record_batch_span.get_tag("aws.operation") == "PutRecordBatch"
807807
assert put_record_batch_span.get_tag("params.Records") is None
808+
809+
@TracerTestCase.run_in_subprocess(env_overrides=dict(DD_BOTOCORE_DISTRIBUTED_TRACING="true"))
810+
def test_distributed_tracing_env_override(self):
811+
assert config.botocore.distributed_tracing is True
812+
813+
@TracerTestCase.run_in_subprocess(env_overrides=dict(DD_BOTOCORE_DISTRIBUTED_TRACING="false"))
814+
def test_distributed_tracing_env_override_false(self):
815+
assert config.botocore.distributed_tracing is False
816+
817+
@TracerTestCase.run_in_subprocess(env_overrides=dict(DD_BOTOCORE_INVOKE_WITH_LEGACY_CONTEXT="true"))
818+
def test_invoke_legacy_context_env_override(self):
819+
assert config.botocore.invoke_with_legacy_context is True

0 commit comments

Comments
 (0)