@@ -62,6 +62,7 @@ def trace_integration(
62
62
database_type : str = "" ,
63
63
connection_attributes : typing .Dict = None ,
64
64
tracer_provider : typing .Optional [TracerProvider ] = None ,
65
+ capture_parameters : bool = False ,
65
66
):
66
67
"""Integrate with DB API library.
67
68
https://www.python.org/dev/peps/pep-0249/
@@ -76,6 +77,7 @@ def trace_integration(
76
77
user in Connection object.
77
78
tracer_provider: The :class:`opentelemetry.trace.TracerProvider` to
78
79
use. If ommited the current configured one is used.
80
+ capture_parameters: Configure if db.statement.parameters should be captured.
79
81
"""
80
82
wrap_connect (
81
83
__name__ ,
@@ -86,6 +88,7 @@ def trace_integration(
86
88
connection_attributes ,
87
89
version = __version__ ,
88
90
tracer_provider = tracer_provider ,
91
+ capture_parameters = capture_parameters ,
89
92
)
90
93
91
94
@@ -98,6 +101,7 @@ def wrap_connect(
98
101
connection_attributes : typing .Dict = None ,
99
102
version : str = "" ,
100
103
tracer_provider : typing .Optional [TracerProvider ] = None ,
104
+ capture_parameters : bool = False ,
101
105
):
102
106
"""Integrate with DB API library.
103
107
https://www.python.org/dev/peps/pep-0249/
@@ -111,6 +115,8 @@ def wrap_connect(
111
115
database_type: The Database type. For any SQL database, "sql".
112
116
connection_attributes: Attribute names for database, port, host and
113
117
user in Connection object.
118
+ capture_parameters: Configure if db.statement.parameters should be captured.
119
+
114
120
"""
115
121
116
122
# pylint: disable=unused-argument
@@ -127,6 +133,7 @@ def wrap_connect_(
127
133
connection_attributes = connection_attributes ,
128
134
version = version ,
129
135
tracer_provider = tracer_provider ,
136
+ capture_parameters = capture_parameters ,
130
137
)
131
138
return db_integration .wrapped_connection (wrapped , args , kwargs )
132
139
@@ -159,6 +166,7 @@ def instrument_connection(
159
166
connection_attributes : typing .Dict = None ,
160
167
version : str = "" ,
161
168
tracer_provider : typing .Optional [TracerProvider ] = None ,
169
+ capture_parameters = False ,
162
170
):
163
171
"""Enable instrumentation in a database connection.
164
172
@@ -170,7 +178,7 @@ def instrument_connection(
170
178
database_type: The Database type. For any SQL database, "sql".
171
179
connection_attributes: Attribute names for database, port, host and
172
180
user in a connection object.
173
-
181
+ capture_parameters: Configure if db.statement.parameters should be captured.
174
182
Returns:
175
183
An instrumented connection.
176
184
"""
@@ -181,6 +189,7 @@ def instrument_connection(
181
189
connection_attributes = connection_attributes ,
182
190
version = version ,
183
191
tracer_provider = tracer_provider ,
192
+ capture_parameters = capture_parameters ,
184
193
)
185
194
db_integration .get_connection_attributes (connection )
186
195
return get_traced_connection_proxy (connection , db_integration )
@@ -211,6 +220,7 @@ def __init__(
211
220
connection_attributes = None ,
212
221
version : str = "" ,
213
222
tracer_provider : typing .Optional [TracerProvider ] = None ,
223
+ capture_parameters : bool = False ,
214
224
):
215
225
self .connection_attributes = connection_attributes
216
226
if self .connection_attributes is None :
@@ -223,6 +233,7 @@ def __init__(
223
233
self ._name = name
224
234
self ._version = version
225
235
self ._tracer_provider = tracer_provider
236
+ self .capture_parameters = capture_parameters
226
237
self .database_component = database_component
227
238
self .database_type = database_type
228
239
self .connection_props = {}
@@ -327,7 +338,7 @@ def _populate_span(
327
338
) in self ._db_api_integration .span_attributes .items ():
328
339
span .set_attribute (attribute_key , attribute_value )
329
340
330
- if len (args ) > 1 :
341
+ if self . _db_api_integration . capture_parameters and len (args ) > 1 :
331
342
span .set_attribute ("db.statement.parameters" , str (args [1 ]))
332
343
333
344
def traced_execution (
0 commit comments