-
Notifications
You must be signed in to change notification settings - Fork 651
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
DBAPI: Add param to control capturing of db.statement.parameters #1247
Changes from all commits
0031952
0d838bd
b8268c5
097eaf2
cc1902e
4a6293a
7373a20
32d34bb
684ab0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,7 +199,11 @@ def test_span_succeeded(self): | |
"user": "user", | ||
} | ||
db_integration = AiopgIntegration( | ||
self.tracer, "testcomponent", "testtype", connection_attributes | ||
self.tracer, | ||
"testcomponent", | ||
"testtype", | ||
connection_attributes, | ||
capture_parameters=True, | ||
) | ||
mock_connection = async_call( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Explicitly check the span attribute existence in this test as well. |
||
db_integration.wrapped_connection( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,7 @@ def trace_integration( | |
database_type: str = "", | ||
connection_attributes: typing.Dict = None, | ||
tracer_provider: typing.Optional[TracerProvider] = None, | ||
capture_parameters: bool = False, | ||
): | ||
"""Integrate with DB API library. | ||
https://www.python.org/dev/peps/pep-0249/ | ||
|
@@ -76,6 +77,7 @@ def trace_integration( | |
user in Connection object. | ||
tracer_provider: The :class:`opentelemetry.trace.TracerProvider` to | ||
use. If ommited the current configured one is used. | ||
capture_parameters: Configure if db.statement.parameters should be captured. | ||
""" | ||
wrap_connect( | ||
__name__, | ||
|
@@ -86,6 +88,7 @@ def trace_integration( | |
connection_attributes, | ||
version=__version__, | ||
tracer_provider=tracer_provider, | ||
capture_parameters=capture_parameters, | ||
) | ||
|
||
|
||
|
@@ -98,6 +101,7 @@ def wrap_connect( | |
connection_attributes: typing.Dict = None, | ||
version: str = "", | ||
tracer_provider: typing.Optional[TracerProvider] = None, | ||
capture_parameters: bool = False, | ||
): | ||
"""Integrate with DB API library. | ||
https://www.python.org/dev/peps/pep-0249/ | ||
|
@@ -111,6 +115,8 @@ def wrap_connect( | |
database_type: The Database type. For any SQL database, "sql". | ||
connection_attributes: Attribute names for database, port, host and | ||
user in Connection object. | ||
capture_parameters: Configure if db.statement.parameters should be captured. | ||
|
||
""" | ||
|
||
# pylint: disable=unused-argument | ||
|
@@ -127,6 +133,7 @@ def wrap_connect_( | |
connection_attributes=connection_attributes, | ||
version=version, | ||
tracer_provider=tracer_provider, | ||
capture_parameters=capture_parameters, | ||
) | ||
return db_integration.wrapped_connection(wrapped, args, kwargs) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes sense. |
||
|
@@ -159,6 +166,7 @@ def instrument_connection( | |
connection_attributes: typing.Dict = None, | ||
version: str = "", | ||
tracer_provider: typing.Optional[TracerProvider] = None, | ||
capture_parameters=False, | ||
): | ||
"""Enable instrumentation in a database connection. | ||
|
||
|
@@ -170,7 +178,7 @@ def instrument_connection( | |
database_type: The Database type. For any SQL database, "sql". | ||
connection_attributes: Attribute names for database, port, host and | ||
user in a connection object. | ||
|
||
capture_parameters: Configure if db.statement.parameters should be captured. | ||
Returns: | ||
An instrumented connection. | ||
""" | ||
|
@@ -181,6 +189,7 @@ def instrument_connection( | |
connection_attributes=connection_attributes, | ||
version=version, | ||
tracer_provider=tracer_provider, | ||
capture_parameters=capture_parameters, | ||
) | ||
db_integration.get_connection_attributes(connection) | ||
return get_traced_connection_proxy(connection, db_integration) | ||
|
@@ -211,6 +220,7 @@ def __init__( | |
connection_attributes=None, | ||
version: str = "", | ||
tracer_provider: typing.Optional[TracerProvider] = None, | ||
capture_parameters: bool = False, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How can this be configured by the user? As well as the instrumentations that depend on this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I did not make this configurable for the user. I initially though I was going to but then came across this PR that removes the capturing of "db.statement.parameters" for AsyncPGInstrumentor Would it be better to not have the constructor param and instead introduce a user settable property? Thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having users be able to configure it is fine. The reason why the |
||
): | ||
self.connection_attributes = connection_attributes | ||
if self.connection_attributes is None: | ||
|
@@ -223,6 +233,7 @@ def __init__( | |
self._name = name | ||
self._version = version | ||
self._tracer_provider = tracer_provider | ||
self.capture_parameters = capture_parameters | ||
self.database_component = database_component | ||
self.database_type = database_type | ||
self.connection_props = {} | ||
|
@@ -327,7 +338,7 @@ def _populate_span( | |
) in self._db_api_integration.span_attributes.items(): | ||
span.set_attribute(attribute_key, attribute_value) | ||
|
||
if len(args) > 1: | ||
if self._db_api_integration.capture_parameters and len(args) > 1: | ||
span.set_attribute("db.statement.parameters", str(args[1])) | ||
|
||
def traced_execution( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't there a lot of other instrumentations that use dbapi as well (mysql, psycopg2, etc)? I think tests would need to be added for those as well because this is a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would argue that since the the other instrumentations already are not testing for "db.statement.parameters", we would not need to modify the test to do so now.
Also db.statement.parameters is not even part of the specification: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/database.md#call-level-attributes, why is it being collected at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To ensure completeness of the feature, tests should be added for each instrumentation. The original authors should have tested for this, but since your change will effect the behavior of these instrumentations, it would be good to have them there as well.
That is a good question. Perhaps this should be the discussion topic to address first? @codeboten