|
1 | 1 | import inspect |
| 2 | +import os |
2 | 3 |
|
3 | 4 | import boto.connection |
4 | 5 |
|
|
10 | 11 | from ddtrace.ext import http |
11 | 12 | from ddtrace.internal.utils.wrappers import unwrap |
12 | 13 | from ddtrace.pin import Pin |
| 14 | +from ddtrace.vendor import debtcollector |
13 | 15 | from ddtrace.vendor import wrapt |
14 | 16 |
|
15 | 17 | from ...internal.utils import get_argument_value |
| 18 | +from ...internal.utils.formats import asbool |
16 | 19 |
|
17 | 20 |
|
18 | 21 | # Original boto client class |
|
32 | 35 | AWS_AUTH_TRACED_ARGS = {"path", "data", "host"} |
33 | 36 |
|
34 | 37 |
|
| 38 | +if os.getenv("DD_AWS_TAG_ALL_PARAMS") is not None: |
| 39 | + debtcollector.deprecate( |
| 40 | + "Using environment variable 'DD_AWS_TAG_ALL_PARAMS' is deprecated", |
| 41 | + message="The boto integration no longer includes all API parameters by default.", |
| 42 | + removal_version="2.0.0", |
| 43 | + ) |
| 44 | + |
| 45 | +config._add( |
| 46 | + "boto", |
| 47 | + { |
| 48 | + "tag_no_params": asbool(os.getenv("DD_AWS_TAG_NO_PARAMS", default=False)), |
| 49 | + "tag_all_params": asbool(os.getenv("DD_AWS_TAG_ALL_PARAMS", default=False)), |
| 50 | + }, |
| 51 | +) |
| 52 | + |
| 53 | + |
35 | 54 | def patch(): |
36 | 55 | if getattr(boto.connection, "_datadog_patch", False): |
37 | 56 | return |
@@ -72,11 +91,17 @@ def patched_query_request(original_func, instance, args, kwargs): |
72 | 91 | operation_name = None |
73 | 92 | if args: |
74 | 93 | operation_name = get_argument_value(args, kwargs, 0, "action") |
| 94 | + params = get_argument_value(args, kwargs, 1, "params") |
| 95 | + |
75 | 96 | span.resource = "%s.%s" % (endpoint_name, operation_name.lower()) |
| 97 | + |
| 98 | + if params and not config.boto["tag_no_params"]: |
| 99 | + aws._add_api_param_span_tags(span, endpoint_name, params) |
76 | 100 | else: |
77 | 101 | span.resource = endpoint_name |
78 | 102 |
|
79 | | - aws.add_span_arg_tags(span, endpoint_name, args, AWS_QUERY_ARGS_NAME, AWS_QUERY_TRACED_ARGS) |
| 103 | + if not config.boto["tag_no_params"] and config.boto["tag_all_params"]: |
| 104 | + aws.add_span_arg_tags(span, endpoint_name, args, AWS_QUERY_ARGS_NAME, AWS_QUERY_TRACED_ARGS) |
80 | 105 |
|
81 | 106 | # Obtaining region name |
82 | 107 | region_name = _get_instance_region_name(instance) |
@@ -140,7 +165,8 @@ def patched_auth_request(original_func, instance, args, kwargs): |
140 | 165 | else: |
141 | 166 | span.resource = endpoint_name |
142 | 167 |
|
143 | | - aws.add_span_arg_tags(span, endpoint_name, args, AWS_AUTH_ARGS_NAME, AWS_AUTH_TRACED_ARGS) |
| 168 | + if not config.boto["tag_no_params"] and config.boto["tag_all_params"]: |
| 169 | + aws.add_span_arg_tags(span, endpoint_name, args, AWS_AUTH_ARGS_NAME, AWS_AUTH_TRACED_ARGS) |
144 | 170 |
|
145 | 171 | # Obtaining region name |
146 | 172 | region_name = _get_instance_region_name(instance) |
|
0 commit comments