mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-08-01 06:33:52 +08:00
Remove 'component' span attribute in instrumentations (#301)
This commit is contained in:
@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased](https://github.com/open-telemetry/opentelemetry-python-contrib/compare/v0.17b0...HEAD)
|
## [Unreleased](https://github.com/open-telemetry/opentelemetry-python-contrib/compare/v0.17b0...HEAD)
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Remove `component` span attribute in instrumentations.
|
||||||
|
`opentelemetry-instrumentation-aiopg`, `opentelemetry-instrumentation-dbapi` Remove unused `database_type` parameter from `trace_integration` function.
|
||||||
|
([#301](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/301))
|
||||||
|
|
||||||
## [0.17b0](https://github.com/open-telemetry/opentelemetry-python-contrib/releases/tag/v0.17b0) - 2021-01-20
|
## [0.17b0](https://github.com/open-telemetry/opentelemetry-python-contrib/releases/tag/v0.17b0) - 2021-01-20
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@ -169,7 +169,6 @@ def create_trace_config(
|
|||||||
|
|
||||||
if trace_config_ctx.span.is_recording():
|
if trace_config_ctx.span.is_recording():
|
||||||
attributes = {
|
attributes = {
|
||||||
"component": "http",
|
|
||||||
"http.method": http_method,
|
"http.method": http_method,
|
||||||
"http.url": trace_config_ctx.url_filter(params.url)
|
"http.url": trace_config_ctx.url_filter(params.url)
|
||||||
if callable(trace_config_ctx.url_filter)
|
if callable(trace_config_ctx.url_filter)
|
||||||
|
@ -129,7 +129,6 @@ class TestAioHttpIntegration(TestBase):
|
|||||||
"HTTP GET",
|
"HTTP GET",
|
||||||
(span_status, None),
|
(span_status, None),
|
||||||
{
|
{
|
||||||
"component": "http",
|
|
||||||
"http.method": "GET",
|
"http.method": "GET",
|
||||||
"http.url": "http://{}:{}/test-path?query=param#foobar".format(
|
"http.url": "http://{}:{}/test-path?query=param#foobar".format(
|
||||||
host, port
|
host, port
|
||||||
@ -187,7 +186,6 @@ class TestAioHttpIntegration(TestBase):
|
|||||||
expected,
|
expected,
|
||||||
(StatusCode.UNSET, None),
|
(StatusCode.UNSET, None),
|
||||||
{
|
{
|
||||||
"component": "http",
|
|
||||||
"http.method": method,
|
"http.method": method,
|
||||||
"http.url": "http://{}:{}{}".format(
|
"http.url": "http://{}:{}{}".format(
|
||||||
host, port, path
|
host, port, path
|
||||||
@ -219,7 +217,6 @@ class TestAioHttpIntegration(TestBase):
|
|||||||
"HTTP GET",
|
"HTTP GET",
|
||||||
(StatusCode.UNSET, None),
|
(StatusCode.UNSET, None),
|
||||||
{
|
{
|
||||||
"component": "http",
|
|
||||||
"http.method": "GET",
|
"http.method": "GET",
|
||||||
"http.url": "http://{}:{}/some/path".format(
|
"http.url": "http://{}:{}/some/path".format(
|
||||||
host, port
|
host, port
|
||||||
@ -256,11 +253,7 @@ class TestAioHttpIntegration(TestBase):
|
|||||||
(
|
(
|
||||||
"HTTP GET",
|
"HTTP GET",
|
||||||
(expected_status, None),
|
(expected_status, None),
|
||||||
{
|
{"http.method": "GET", "http.url": url},
|
||||||
"component": "http",
|
|
||||||
"http.method": "GET",
|
|
||||||
"http.url": url,
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@ -285,7 +278,6 @@ class TestAioHttpIntegration(TestBase):
|
|||||||
"HTTP GET",
|
"HTTP GET",
|
||||||
(StatusCode.ERROR, None),
|
(StatusCode.ERROR, None),
|
||||||
{
|
{
|
||||||
"component": "http",
|
|
||||||
"http.method": "GET",
|
"http.method": "GET",
|
||||||
"http.url": "http://{}:{}/test_timeout".format(
|
"http.url": "http://{}:{}/test_timeout".format(
|
||||||
host, port
|
host, port
|
||||||
@ -315,7 +307,6 @@ class TestAioHttpIntegration(TestBase):
|
|||||||
"HTTP GET",
|
"HTTP GET",
|
||||||
(StatusCode.ERROR, None),
|
(StatusCode.ERROR, None),
|
||||||
{
|
{
|
||||||
"component": "http",
|
|
||||||
"http.method": "GET",
|
"http.method": "GET",
|
||||||
"http.url": "http://{}:{}/test_too_many_redirects".format(
|
"http.url": "http://{}:{}/test_too_many_redirects".format(
|
||||||
host, port
|
host, port
|
||||||
@ -364,7 +355,6 @@ class TestAioHttpClientInstrumentor(TestBase):
|
|||||||
self.get_default_request(), self.URL, self.default_handler
|
self.get_default_request(), self.URL, self.default_handler
|
||||||
)
|
)
|
||||||
span = self.assert_spans(1)
|
span = self.assert_spans(1)
|
||||||
self.assertEqual("http", span.attributes["component"])
|
|
||||||
self.assertEqual("GET", span.attributes["http.method"])
|
self.assertEqual("GET", span.attributes["http.method"])
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
"http://{}:{}/test-path".format(host, port),
|
"http://{}:{}/test-path".format(host, port),
|
||||||
|
@ -58,8 +58,7 @@ class AiopgInstrumentor(BaseInstrumentor):
|
|||||||
"user": "info.user",
|
"user": "info.user",
|
||||||
}
|
}
|
||||||
|
|
||||||
_DATABASE_COMPONENT = "postgresql"
|
_DATABASE_SYSTEM = "postgresql"
|
||||||
_DATABASE_TYPE = "sql"
|
|
||||||
|
|
||||||
def _instrument(self, **kwargs):
|
def _instrument(self, **kwargs):
|
||||||
"""Integrate with PostgreSQL aiopg library.
|
"""Integrate with PostgreSQL aiopg library.
|
||||||
@ -70,8 +69,7 @@ class AiopgInstrumentor(BaseInstrumentor):
|
|||||||
|
|
||||||
wrappers.wrap_connect(
|
wrappers.wrap_connect(
|
||||||
__name__,
|
__name__,
|
||||||
self._DATABASE_COMPONENT,
|
self._DATABASE_SYSTEM,
|
||||||
self._DATABASE_TYPE,
|
|
||||||
self._CONNECTION_ATTRIBUTES,
|
self._CONNECTION_ATTRIBUTES,
|
||||||
version=__version__,
|
version=__version__,
|
||||||
tracer_provider=tracer_provider,
|
tracer_provider=tracer_provider,
|
||||||
@ -79,8 +77,7 @@ class AiopgInstrumentor(BaseInstrumentor):
|
|||||||
|
|
||||||
wrappers.wrap_create_pool(
|
wrappers.wrap_create_pool(
|
||||||
__name__,
|
__name__,
|
||||||
self._DATABASE_COMPONENT,
|
self._DATABASE_SYSTEM,
|
||||||
self._DATABASE_TYPE,
|
|
||||||
self._CONNECTION_ATTRIBUTES,
|
self._CONNECTION_ATTRIBUTES,
|
||||||
version=__version__,
|
version=__version__,
|
||||||
tracer_provider=tracer_provider,
|
tracer_provider=tracer_provider,
|
||||||
@ -104,8 +101,7 @@ class AiopgInstrumentor(BaseInstrumentor):
|
|||||||
return wrappers.instrument_connection(
|
return wrappers.instrument_connection(
|
||||||
__name__,
|
__name__,
|
||||||
connection,
|
connection,
|
||||||
self._DATABASE_COMPONENT,
|
self._DATABASE_SYSTEM,
|
||||||
self._DATABASE_TYPE,
|
|
||||||
self._CONNECTION_ATTRIBUTES,
|
self._CONNECTION_ATTRIBUTES,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ Usage
|
|||||||
from opentelemetry import trace
|
from opentelemetry import trace
|
||||||
from opentelemetry.instrumentation.aiopg import trace_integration
|
from opentelemetry.instrumentation.aiopg import trace_integration
|
||||||
|
|
||||||
trace_integration(aiopg.connection, "_connect", "postgresql", "sql")
|
trace_integration(aiopg.connection, "_connect", "postgresql")
|
||||||
|
|
||||||
API
|
API
|
||||||
---
|
---
|
||||||
@ -48,8 +48,7 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
def trace_integration(
|
def trace_integration(
|
||||||
database_component: str,
|
database_system: str,
|
||||||
database_type: str = "",
|
|
||||||
connection_attributes: typing.Dict = None,
|
connection_attributes: typing.Dict = None,
|
||||||
tracer_provider: typing.Optional[TracerProvider] = None,
|
tracer_provider: typing.Optional[TracerProvider] = None,
|
||||||
):
|
):
|
||||||
@ -57,19 +56,17 @@ def trace_integration(
|
|||||||
based on dbapi integration, where replaced sync wrap methods to async
|
based on dbapi integration, where replaced sync wrap methods to async
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
database_component: Database driver name or
|
database_system: An identifier for the database management system (DBMS)
|
||||||
database name "postgreSQL".
|
product being used.
|
||||||
database_type: The Database type. For any SQL database, "sql".
|
|
||||||
connection_attributes: Attribute names for database, port, host and
|
connection_attributes: Attribute names for database, port, host and
|
||||||
user in Connection object.
|
user in Connection object.
|
||||||
tracer_provider: The :class:`opentelemetry.trace.TracerProvider` to
|
tracer_provider: The :class:`opentelemetry.trace.TracerProvider` to
|
||||||
use. If ommited the current configured one is used.
|
use. If omitted the current configured one is used.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
wrap_connect(
|
wrap_connect(
|
||||||
__name__,
|
__name__,
|
||||||
database_component,
|
database_system,
|
||||||
database_type,
|
|
||||||
connection_attributes,
|
connection_attributes,
|
||||||
__version__,
|
__version__,
|
||||||
tracer_provider,
|
tracer_provider,
|
||||||
@ -78,8 +75,7 @@ def trace_integration(
|
|||||||
|
|
||||||
def wrap_connect(
|
def wrap_connect(
|
||||||
name: str,
|
name: str,
|
||||||
database_component: str,
|
database_system: str,
|
||||||
database_type: str = "",
|
|
||||||
connection_attributes: typing.Dict = None,
|
connection_attributes: typing.Dict = None,
|
||||||
version: str = "",
|
version: str = "",
|
||||||
tracer_provider: typing.Optional[TracerProvider] = None,
|
tracer_provider: typing.Optional[TracerProvider] = None,
|
||||||
@ -89,14 +85,13 @@ def wrap_connect(
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
name: Name of opentelemetry extension for aiopg.
|
name: Name of opentelemetry extension for aiopg.
|
||||||
database_component: Database driver name
|
database_system: An identifier for the database management system (DBMS)
|
||||||
or database name "postgreSQL".
|
product being used.
|
||||||
database_type: The Database type. For any SQL database, "sql".
|
|
||||||
connection_attributes: Attribute names for database, port, host and
|
connection_attributes: Attribute names for database, port, host and
|
||||||
user in Connection object.
|
user in Connection object.
|
||||||
version: Version of opentelemetry extension for aiopg.
|
version: Version of opentelemetry extension for aiopg.
|
||||||
tracer_provider: The :class:`opentelemetry.trace.TracerProvider` to
|
tracer_provider: The :class:`opentelemetry.trace.TracerProvider` to
|
||||||
use. If ommited the current configured one is used.
|
use. If omitted the current configured one is used.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
@ -108,8 +103,7 @@ def wrap_connect(
|
|||||||
):
|
):
|
||||||
db_integration = AiopgIntegration(
|
db_integration = AiopgIntegration(
|
||||||
name,
|
name,
|
||||||
database_component,
|
database_system,
|
||||||
database_type=database_type,
|
|
||||||
connection_attributes=connection_attributes,
|
connection_attributes=connection_attributes,
|
||||||
version=version,
|
version=version,
|
||||||
tracer_provider=tracer_provider,
|
tracer_provider=tracer_provider,
|
||||||
@ -135,8 +129,7 @@ def unwrap_connect():
|
|||||||
def instrument_connection(
|
def instrument_connection(
|
||||||
name: str,
|
name: str,
|
||||||
connection,
|
connection,
|
||||||
database_component: str,
|
database_system: str,
|
||||||
database_type: str = "",
|
|
||||||
connection_attributes: typing.Dict = None,
|
connection_attributes: typing.Dict = None,
|
||||||
version: str = "",
|
version: str = "",
|
||||||
tracer_provider: typing.Optional[TracerProvider] = None,
|
tracer_provider: typing.Optional[TracerProvider] = None,
|
||||||
@ -146,21 +139,20 @@ def instrument_connection(
|
|||||||
Args:
|
Args:
|
||||||
name: Name of opentelemetry extension for aiopg.
|
name: Name of opentelemetry extension for aiopg.
|
||||||
connection: The connection to instrument.
|
connection: The connection to instrument.
|
||||||
database_component: Database driver name or database name "postgreSQL".
|
database_system: An identifier for the database management system (DBMS)
|
||||||
database_type: The Database type. For any SQL database, "sql".
|
product being used.
|
||||||
connection_attributes: Attribute names for database, port, host and
|
connection_attributes: Attribute names for database, port, host and
|
||||||
user in a connection object.
|
user in a connection object.
|
||||||
version: Version of opentelemetry extension for aiopg.
|
version: Version of opentelemetry extension for aiopg.
|
||||||
tracer_provider: The :class:`opentelemetry.trace.TracerProvider` to
|
tracer_provider: The :class:`opentelemetry.trace.TracerProvider` to
|
||||||
use. If ommited the current configured one is used.
|
use. If omitted the current configured one is used.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
An instrumented connection.
|
An instrumented connection.
|
||||||
"""
|
"""
|
||||||
db_integration = AiopgIntegration(
|
db_integration = AiopgIntegration(
|
||||||
name,
|
name,
|
||||||
database_component,
|
database_system,
|
||||||
database_type,
|
|
||||||
connection_attributes=connection_attributes,
|
connection_attributes=connection_attributes,
|
||||||
version=version,
|
version=version,
|
||||||
tracer_provider=tracer_provider,
|
tracer_provider=tracer_provider,
|
||||||
@ -187,8 +179,7 @@ def uninstrument_connection(connection):
|
|||||||
|
|
||||||
def wrap_create_pool(
|
def wrap_create_pool(
|
||||||
name: str,
|
name: str,
|
||||||
database_component: str,
|
database_system: str,
|
||||||
database_type: str = "",
|
|
||||||
connection_attributes: typing.Dict = None,
|
connection_attributes: typing.Dict = None,
|
||||||
version: str = "",
|
version: str = "",
|
||||||
tracer_provider: typing.Optional[TracerProvider] = None,
|
tracer_provider: typing.Optional[TracerProvider] = None,
|
||||||
@ -202,8 +193,7 @@ def wrap_create_pool(
|
|||||||
):
|
):
|
||||||
db_integration = AiopgIntegration(
|
db_integration = AiopgIntegration(
|
||||||
name,
|
name,
|
||||||
database_component,
|
database_system,
|
||||||
database_type,
|
|
||||||
connection_attributes=connection_attributes,
|
connection_attributes=connection_attributes,
|
||||||
version=version,
|
version=version,
|
||||||
tracer_provider=tracer_provider,
|
tracer_provider=tracer_provider,
|
||||||
|
@ -242,7 +242,6 @@ class TestAiopgIntegration(TestBase):
|
|||||||
db_integration = AiopgIntegration(
|
db_integration = AiopgIntegration(
|
||||||
self.tracer,
|
self.tracer,
|
||||||
"testcomponent",
|
"testcomponent",
|
||||||
"testtype",
|
|
||||||
connection_attributes,
|
connection_attributes,
|
||||||
capture_parameters=True,
|
capture_parameters=True,
|
||||||
)
|
)
|
||||||
@ -259,7 +258,6 @@ class TestAiopgIntegration(TestBase):
|
|||||||
self.assertEqual(span.name, "Test")
|
self.assertEqual(span.name, "Test")
|
||||||
self.assertIs(span.kind, trace_api.SpanKind.CLIENT)
|
self.assertIs(span.kind, trace_api.SpanKind.CLIENT)
|
||||||
|
|
||||||
self.assertEqual(span.attributes["component"], "testcomponent")
|
|
||||||
self.assertEqual(span.attributes["db.system"], "testcomponent")
|
self.assertEqual(span.attributes["db.system"], "testcomponent")
|
||||||
self.assertEqual(span.attributes["db.name"], "testdatabase")
|
self.assertEqual(span.attributes["db.name"], "testdatabase")
|
||||||
self.assertEqual(span.attributes["db.statement"], "Test query")
|
self.assertEqual(span.attributes["db.statement"], "Test query")
|
||||||
@ -294,7 +292,7 @@ class TestAiopgIntegration(TestBase):
|
|||||||
mock_tracer.use_span.return_value.__enter__ = mock_span
|
mock_tracer.use_span.return_value.__enter__ = mock_span
|
||||||
mock_tracer.use_span.return_value.__exit__ = True
|
mock_tracer.use_span.return_value.__exit__ = True
|
||||||
db_integration = AiopgIntegration(
|
db_integration = AiopgIntegration(
|
||||||
mock_tracer, "testcomponent", "testtype", connection_attributes
|
mock_tracer, "testcomponent", connection_attributes
|
||||||
)
|
)
|
||||||
mock_connection = async_call(
|
mock_connection = async_call(
|
||||||
db_integration.wrapped_connection(
|
db_integration.wrapped_connection(
|
||||||
|
@ -72,7 +72,6 @@ def collect_request_attributes(scope):
|
|||||||
http_url = http_url + ("?" + urllib.parse.unquote(query_string))
|
http_url = http_url + ("?" + urllib.parse.unquote(query_string))
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
"component": scope["type"],
|
|
||||||
"http.scheme": scope.get("scheme"),
|
"http.scheme": scope.get("scheme"),
|
||||||
"http.host": server_host,
|
"http.host": server_host,
|
||||||
"net.host.port": port,
|
"net.host.port": port,
|
||||||
|
@ -134,7 +134,6 @@ class TestAsgiApplication(AsgiTestBase):
|
|||||||
"name": "GET asgi",
|
"name": "GET asgi",
|
||||||
"kind": trace_api.SpanKind.SERVER,
|
"kind": trace_api.SpanKind.SERVER,
|
||||||
"attributes": {
|
"attributes": {
|
||||||
"component": "http",
|
|
||||||
"http.method": "GET",
|
"http.method": "GET",
|
||||||
"http.scheme": "http",
|
"http.scheme": "http",
|
||||||
"net.host.port": 80,
|
"net.host.port": 80,
|
||||||
@ -321,7 +320,6 @@ class TestAsgiAttributes(unittest.TestCase):
|
|||||||
self.assertDictEqual(
|
self.assertDictEqual(
|
||||||
attrs,
|
attrs,
|
||||||
{
|
{
|
||||||
"component": "http",
|
|
||||||
"http.method": "GET",
|
"http.method": "GET",
|
||||||
"http.host": "127.0.0.1",
|
"http.host": "127.0.0.1",
|
||||||
"http.target": "/",
|
"http.target": "/",
|
||||||
|
@ -29,9 +29,9 @@ Usage
|
|||||||
|
|
||||||
|
|
||||||
# Ex: mysql.connector
|
# Ex: mysql.connector
|
||||||
trace_integration(mysql.connector, "connect", "mysql", "sql")
|
trace_integration(mysql.connector, "connect", "mysql")
|
||||||
# Ex: pyodbc
|
# Ex: pyodbc
|
||||||
trace_integration(pyodbc, "Connection", "odbc", "sql")
|
trace_integration(pyodbc, "Connection", "odbc")
|
||||||
|
|
||||||
API
|
API
|
||||||
---
|
---
|
||||||
@ -55,8 +55,7 @@ logger = logging.getLogger(__name__)
|
|||||||
def trace_integration(
|
def trace_integration(
|
||||||
connect_module: typing.Callable[..., typing.Any],
|
connect_module: typing.Callable[..., typing.Any],
|
||||||
connect_method_name: str,
|
connect_method_name: str,
|
||||||
database_component: str,
|
database_system: str,
|
||||||
database_type: str = "",
|
|
||||||
connection_attributes: typing.Dict = None,
|
connection_attributes: typing.Dict = None,
|
||||||
tracer_provider: typing.Optional[TracerProvider] = None,
|
tracer_provider: typing.Optional[TracerProvider] = None,
|
||||||
capture_parameters: bool = False,
|
capture_parameters: bool = False,
|
||||||
@ -68,21 +67,19 @@ def trace_integration(
|
|||||||
Args:
|
Args:
|
||||||
connect_module: Module name where connect method is available.
|
connect_module: Module name where connect method is available.
|
||||||
connect_method_name: The connect method name.
|
connect_method_name: The connect method name.
|
||||||
database_component: Database driver name or database name "JDBI",
|
database_system: An identifier for the database management system (DBMS)
|
||||||
"jdbc", "odbc", "postgreSQL".
|
product being used.
|
||||||
database_type: The Database type. For any SQL database, "sql".
|
|
||||||
connection_attributes: Attribute names for database, port, host and
|
connection_attributes: Attribute names for database, port, host and
|
||||||
user in Connection object.
|
user in Connection object.
|
||||||
tracer_provider: The :class:`opentelemetry.trace.TracerProvider` to
|
tracer_provider: The :class:`opentelemetry.trace.TracerProvider` to
|
||||||
use. If ommited the current configured one is used.
|
use. If omitted the current configured one is used.
|
||||||
capture_parameters: Configure if db.statement.parameters should be captured.
|
capture_parameters: Configure if db.statement.parameters should be captured.
|
||||||
"""
|
"""
|
||||||
wrap_connect(
|
wrap_connect(
|
||||||
__name__,
|
__name__,
|
||||||
connect_module,
|
connect_module,
|
||||||
connect_method_name,
|
connect_method_name,
|
||||||
database_component,
|
database_system,
|
||||||
database_type,
|
|
||||||
connection_attributes,
|
connection_attributes,
|
||||||
version=__version__,
|
version=__version__,
|
||||||
tracer_provider=tracer_provider,
|
tracer_provider=tracer_provider,
|
||||||
@ -95,8 +92,7 @@ def wrap_connect(
|
|||||||
name: str,
|
name: str,
|
||||||
connect_module: typing.Callable[..., typing.Any],
|
connect_module: typing.Callable[..., typing.Any],
|
||||||
connect_method_name: str,
|
connect_method_name: str,
|
||||||
database_component: str,
|
database_system: str,
|
||||||
database_type: str = "",
|
|
||||||
connection_attributes: typing.Dict = None,
|
connection_attributes: typing.Dict = None,
|
||||||
version: str = "",
|
version: str = "",
|
||||||
tracer_provider: typing.Optional[TracerProvider] = None,
|
tracer_provider: typing.Optional[TracerProvider] = None,
|
||||||
@ -107,14 +103,14 @@ def wrap_connect(
|
|||||||
https://www.python.org/dev/peps/pep-0249/
|
https://www.python.org/dev/peps/pep-0249/
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
tracer: The :class:`opentelemetry.trace.Tracer` to use.
|
|
||||||
connect_module: Module name where connect method is available.
|
connect_module: Module name where connect method is available.
|
||||||
connect_method_name: The connect method name.
|
connect_method_name: The connect method name.
|
||||||
database_component: Database driver name or database name "JDBI",
|
database_system: An identifier for the database management system (DBMS)
|
||||||
"jdbc", "odbc", "postgreSQL".
|
product being used.
|
||||||
database_type: The Database type. For any SQL database, "sql".
|
|
||||||
connection_attributes: Attribute names for database, port, host and
|
connection_attributes: Attribute names for database, port, host and
|
||||||
user in Connection object.
|
user in Connection object.
|
||||||
|
tracer_provider: The :class:`opentelemetry.trace.TracerProvider` to
|
||||||
|
use. If omitted the current configured one is used.
|
||||||
capture_parameters: Configure if db.statement.parameters should be captured.
|
capture_parameters: Configure if db.statement.parameters should be captured.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -131,8 +127,7 @@ def wrap_connect(
|
|||||||
):
|
):
|
||||||
db_integration = db_api_integration_factory(
|
db_integration = db_api_integration_factory(
|
||||||
name,
|
name,
|
||||||
database_component,
|
database_system,
|
||||||
database_type=database_type,
|
|
||||||
connection_attributes=connection_attributes,
|
connection_attributes=connection_attributes,
|
||||||
version=version,
|
version=version,
|
||||||
tracer_provider=tracer_provider,
|
tracer_provider=tracer_provider,
|
||||||
@ -164,8 +159,7 @@ def unwrap_connect(
|
|||||||
def instrument_connection(
|
def instrument_connection(
|
||||||
name: str,
|
name: str,
|
||||||
connection,
|
connection,
|
||||||
database_component: str,
|
database_system: str,
|
||||||
database_type: str = "",
|
|
||||||
connection_attributes: typing.Dict = None,
|
connection_attributes: typing.Dict = None,
|
||||||
version: str = "",
|
version: str = "",
|
||||||
tracer_provider: typing.Optional[TracerProvider] = None,
|
tracer_provider: typing.Optional[TracerProvider] = None,
|
||||||
@ -174,21 +168,20 @@ def instrument_connection(
|
|||||||
"""Enable instrumentation in a database connection.
|
"""Enable instrumentation in a database connection.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
tracer: The :class:`opentelemetry.trace.Tracer` to use.
|
|
||||||
connection: The connection to instrument.
|
connection: The connection to instrument.
|
||||||
database_component: Database driver name or database name "JDBI",
|
database_system: An identifier for the database management system (DBMS)
|
||||||
"jdbc", "odbc", "postgreSQL".
|
product being used.
|
||||||
database_type: The Database type. For any SQL database, "sql".
|
|
||||||
connection_attributes: Attribute names for database, port, host and
|
connection_attributes: Attribute names for database, port, host and
|
||||||
user in a connection object.
|
user in a connection object.
|
||||||
|
tracer_provider: The :class:`opentelemetry.trace.TracerProvider` to
|
||||||
|
use. If omitted the current configured one is used.
|
||||||
capture_parameters: Configure if db.statement.parameters should be captured.
|
capture_parameters: Configure if db.statement.parameters should be captured.
|
||||||
Returns:
|
Returns:
|
||||||
An instrumented connection.
|
An instrumented connection.
|
||||||
"""
|
"""
|
||||||
db_integration = DatabaseApiIntegration(
|
db_integration = DatabaseApiIntegration(
|
||||||
name,
|
name,
|
||||||
database_component,
|
database_system,
|
||||||
database_type,
|
|
||||||
connection_attributes=connection_attributes,
|
connection_attributes=connection_attributes,
|
||||||
version=version,
|
version=version,
|
||||||
tracer_provider=tracer_provider,
|
tracer_provider=tracer_provider,
|
||||||
@ -218,8 +211,7 @@ class DatabaseApiIntegration:
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
name: str,
|
name: str,
|
||||||
database_component: str,
|
database_system: str,
|
||||||
database_type: str = "sql",
|
|
||||||
connection_attributes=None,
|
connection_attributes=None,
|
||||||
version: str = "",
|
version: str = "",
|
||||||
tracer_provider: typing.Optional[TracerProvider] = None,
|
tracer_provider: typing.Optional[TracerProvider] = None,
|
||||||
@ -237,8 +229,7 @@ class DatabaseApiIntegration:
|
|||||||
self._version = version
|
self._version = version
|
||||||
self._tracer_provider = tracer_provider
|
self._tracer_provider = tracer_provider
|
||||||
self.capture_parameters = capture_parameters
|
self.capture_parameters = capture_parameters
|
||||||
self.database_component = database_component
|
self.database_system = database_system
|
||||||
self.database_type = database_type
|
|
||||||
self.connection_props = {}
|
self.connection_props = {}
|
||||||
self.span_attributes = {}
|
self.span_attributes = {}
|
||||||
self.name = ""
|
self.name = ""
|
||||||
@ -275,7 +266,7 @@ class DatabaseApiIntegration:
|
|||||||
)
|
)
|
||||||
if attribute:
|
if attribute:
|
||||||
self.connection_props[key] = attribute
|
self.connection_props[key] = attribute
|
||||||
self.name = self.database_component
|
self.name = self.database_system
|
||||||
self.database = self.connection_props.get("database", "")
|
self.database = self.connection_props.get("database", "")
|
||||||
if self.database:
|
if self.database:
|
||||||
# PyMySQL encodes names with utf-8
|
# PyMySQL encodes names with utf-8
|
||||||
@ -334,10 +325,7 @@ class CursorTracer:
|
|||||||
return
|
return
|
||||||
statement = self.get_statement(cursor, args)
|
statement = self.get_statement(cursor, args)
|
||||||
span.set_attribute(
|
span.set_attribute(
|
||||||
"component", self._db_api_integration.database_component
|
"db.system", self._db_api_integration.database_system
|
||||||
)
|
|
||||||
span.set_attribute(
|
|
||||||
"db.system", self._db_api_integration.database_component
|
|
||||||
)
|
)
|
||||||
span.set_attribute("db.name", self._db_api_integration.database)
|
span.set_attribute("db.name", self._db_api_integration.database)
|
||||||
span.set_attribute("db.statement", statement)
|
span.set_attribute("db.statement", statement)
|
||||||
|
@ -40,7 +40,7 @@ class TestDBApiIntegration(TestBase):
|
|||||||
"user": "user",
|
"user": "user",
|
||||||
}
|
}
|
||||||
db_integration = dbapi.DatabaseApiIntegration(
|
db_integration = dbapi.DatabaseApiIntegration(
|
||||||
self.tracer, "testcomponent", "testtype", connection_attributes
|
self.tracer, "testcomponent", connection_attributes
|
||||||
)
|
)
|
||||||
mock_connection = db_integration.wrapped_connection(
|
mock_connection = db_integration.wrapped_connection(
|
||||||
mock_connect, {}, connection_props
|
mock_connect, {}, connection_props
|
||||||
@ -53,7 +53,6 @@ class TestDBApiIntegration(TestBase):
|
|||||||
self.assertEqual(span.name, "Test")
|
self.assertEqual(span.name, "Test")
|
||||||
self.assertIs(span.kind, trace_api.SpanKind.CLIENT)
|
self.assertIs(span.kind, trace_api.SpanKind.CLIENT)
|
||||||
|
|
||||||
self.assertEqual(span.attributes["component"], "testcomponent")
|
|
||||||
self.assertEqual(span.attributes["db.system"], "testcomponent")
|
self.assertEqual(span.attributes["db.system"], "testcomponent")
|
||||||
self.assertEqual(span.attributes["db.name"], "testdatabase")
|
self.assertEqual(span.attributes["db.name"], "testdatabase")
|
||||||
self.assertEqual(span.attributes["db.statement"], "Test query")
|
self.assertEqual(span.attributes["db.statement"], "Test query")
|
||||||
@ -67,7 +66,7 @@ class TestDBApiIntegration(TestBase):
|
|||||||
|
|
||||||
def test_span_name(self):
|
def test_span_name(self):
|
||||||
db_integration = dbapi.DatabaseApiIntegration(
|
db_integration = dbapi.DatabaseApiIntegration(
|
||||||
self.tracer, "testcomponent", "testtype", {}
|
self.tracer, "testcomponent", {}
|
||||||
)
|
)
|
||||||
mock_connection = db_integration.wrapped_connection(
|
mock_connection = db_integration.wrapped_connection(
|
||||||
mock_connect, {}, {}
|
mock_connect, {}, {}
|
||||||
@ -102,7 +101,6 @@ class TestDBApiIntegration(TestBase):
|
|||||||
db_integration = dbapi.DatabaseApiIntegration(
|
db_integration = dbapi.DatabaseApiIntegration(
|
||||||
self.tracer,
|
self.tracer,
|
||||||
"testcomponent",
|
"testcomponent",
|
||||||
"testtype",
|
|
||||||
connection_attributes,
|
connection_attributes,
|
||||||
capture_parameters=True,
|
capture_parameters=True,
|
||||||
)
|
)
|
||||||
@ -117,7 +115,6 @@ class TestDBApiIntegration(TestBase):
|
|||||||
self.assertEqual(span.name, "Test")
|
self.assertEqual(span.name, "Test")
|
||||||
self.assertIs(span.kind, trace_api.SpanKind.CLIENT)
|
self.assertIs(span.kind, trace_api.SpanKind.CLIENT)
|
||||||
|
|
||||||
self.assertEqual(span.attributes["component"], "testcomponent")
|
|
||||||
self.assertEqual(span.attributes["db.system"], "testcomponent")
|
self.assertEqual(span.attributes["db.system"], "testcomponent")
|
||||||
self.assertEqual(span.attributes["db.name"], "testdatabase")
|
self.assertEqual(span.attributes["db.name"], "testdatabase")
|
||||||
self.assertEqual(span.attributes["db.statement"], "Test query")
|
self.assertEqual(span.attributes["db.statement"], "Test query")
|
||||||
@ -152,7 +149,7 @@ class TestDBApiIntegration(TestBase):
|
|||||||
mock_tracer.use_span.return_value.__enter__ = mock_span
|
mock_tracer.use_span.return_value.__enter__ = mock_span
|
||||||
mock_tracer.use_span.return_value.__exit__ = True
|
mock_tracer.use_span.return_value.__exit__ = True
|
||||||
db_integration = dbapi.DatabaseApiIntegration(
|
db_integration = dbapi.DatabaseApiIntegration(
|
||||||
mock_tracer, "testcomponent", "testtype", connection_attributes
|
mock_tracer, "testcomponent", connection_attributes
|
||||||
)
|
)
|
||||||
mock_connection = db_integration.wrapped_connection(
|
mock_connection = db_integration.wrapped_connection(
|
||||||
mock_connect, {}, connection_props
|
mock_connect, {}, connection_props
|
||||||
|
@ -128,8 +128,7 @@ def _wrap_perform_request(tracer, span_name_prefix):
|
|||||||
) as span:
|
) as span:
|
||||||
if span.is_recording():
|
if span.is_recording():
|
||||||
attributes = {
|
attributes = {
|
||||||
"component": "elasticsearch-py",
|
"db.system": "elasticsearch",
|
||||||
"db.type": "elasticsearch",
|
|
||||||
}
|
}
|
||||||
if url:
|
if url:
|
||||||
attributes["elasticsearch.url"] = url
|
attributes["elasticsearch.url"] = url
|
||||||
|
@ -248,8 +248,7 @@ class TestElasticsearchIntegration(TestBase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
span.attributes,
|
span.attributes,
|
||||||
{
|
{
|
||||||
"component": "elasticsearch-py",
|
"db.system": "elasticsearch",
|
||||||
"db.type": "elasticsearch",
|
|
||||||
"elasticsearch.url": "/test-index/_search",
|
"elasticsearch.url": "/test-index/_search",
|
||||||
"elasticsearch.method": helpers.dsl_search_method,
|
"elasticsearch.method": helpers.dsl_search_method,
|
||||||
"db.statement": str(
|
"db.statement": str(
|
||||||
@ -276,8 +275,7 @@ class TestElasticsearchIntegration(TestBase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
span1.attributes,
|
span1.attributes,
|
||||||
{
|
{
|
||||||
"component": "elasticsearch-py",
|
"db.system": "elasticsearch",
|
||||||
"db.type": "elasticsearch",
|
|
||||||
"elasticsearch.url": "/test-index",
|
"elasticsearch.url": "/test-index",
|
||||||
"elasticsearch.method": "HEAD",
|
"elasticsearch.method": "HEAD",
|
||||||
},
|
},
|
||||||
@ -285,8 +283,7 @@ class TestElasticsearchIntegration(TestBase):
|
|||||||
|
|
||||||
self.assertEqual(span2.name, "Elasticsearch/test-index")
|
self.assertEqual(span2.name, "Elasticsearch/test-index")
|
||||||
attributes = {
|
attributes = {
|
||||||
"component": "elasticsearch-py",
|
"db.system": "elasticsearch",
|
||||||
"db.type": "elasticsearch",
|
|
||||||
"elasticsearch.url": "/test-index",
|
"elasticsearch.url": "/test-index",
|
||||||
"elasticsearch.method": "PUT",
|
"elasticsearch.method": "PUT",
|
||||||
}
|
}
|
||||||
@ -312,8 +309,7 @@ class TestElasticsearchIntegration(TestBase):
|
|||||||
span = spans[0]
|
span = spans[0]
|
||||||
self.assertEqual(span.name, helpers.dsl_index_span_name)
|
self.assertEqual(span.name, helpers.dsl_index_span_name)
|
||||||
attributes = {
|
attributes = {
|
||||||
"component": "elasticsearch-py",
|
"db.system": "elasticsearch",
|
||||||
"db.type": "elasticsearch",
|
|
||||||
"elasticsearch.url": helpers.dsl_index_url,
|
"elasticsearch.url": helpers.dsl_index_url,
|
||||||
"elasticsearch.method": "PUT",
|
"elasticsearch.method": "PUT",
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,6 @@ class TestFalconInstrumentation(TestBase):
|
|||||||
self.assert_span_has_attributes(
|
self.assert_span_has_attributes(
|
||||||
span,
|
span,
|
||||||
{
|
{
|
||||||
"component": "http",
|
|
||||||
"http.method": method,
|
"http.method": method,
|
||||||
"http.server_name": "falconframework.org",
|
"http.server_name": "falconframework.org",
|
||||||
"http.scheme": "http",
|
"http.scheme": "http",
|
||||||
@ -122,7 +121,6 @@ class TestFalconInstrumentation(TestBase):
|
|||||||
self.assert_span_has_attributes(
|
self.assert_span_has_attributes(
|
||||||
span,
|
span,
|
||||||
{
|
{
|
||||||
"component": "http",
|
|
||||||
"http.method": "GET",
|
"http.method": "GET",
|
||||||
"http.server_name": "falconframework.org",
|
"http.server_name": "falconframework.org",
|
||||||
"http.scheme": "http",
|
"http.scheme": "http",
|
||||||
@ -155,7 +153,6 @@ class TestFalconInstrumentation(TestBase):
|
|||||||
self.assert_span_has_attributes(
|
self.assert_span_has_attributes(
|
||||||
span,
|
span,
|
||||||
{
|
{
|
||||||
"component": "http",
|
|
||||||
"http.method": "GET",
|
"http.method": "GET",
|
||||||
"http.server_name": "falconframework.org",
|
"http.server_name": "falconframework.org",
|
||||||
"http.scheme": "http",
|
"http.scheme": "http",
|
||||||
|
@ -28,7 +28,6 @@ from .base_test import InstrumentationTest
|
|||||||
|
|
||||||
def expected_attributes(override_attributes):
|
def expected_attributes(override_attributes):
|
||||||
default_attributes = {
|
default_attributes = {
|
||||||
"component": "http",
|
|
||||||
"http.method": "GET",
|
"http.method": "GET",
|
||||||
"http.server_name": "localhost",
|
"http.server_name": "localhost",
|
||||||
"http.scheme": "http",
|
"http.scheme": "http",
|
||||||
|
@ -54,8 +54,7 @@ class MySQLInstrumentor(BaseInstrumentor):
|
|||||||
"user": "user",
|
"user": "user",
|
||||||
}
|
}
|
||||||
|
|
||||||
_DATABASE_COMPONENT = "mysql"
|
_DATABASE_SYSTEM = "mysql"
|
||||||
_DATABASE_TYPE = "sql"
|
|
||||||
|
|
||||||
def _instrument(self, **kwargs):
|
def _instrument(self, **kwargs):
|
||||||
"""Integrate with MySQL Connector/Python library.
|
"""Integrate with MySQL Connector/Python library.
|
||||||
@ -67,8 +66,7 @@ class MySQLInstrumentor(BaseInstrumentor):
|
|||||||
__name__,
|
__name__,
|
||||||
mysql.connector,
|
mysql.connector,
|
||||||
"connect",
|
"connect",
|
||||||
self._DATABASE_COMPONENT,
|
self._DATABASE_SYSTEM,
|
||||||
self._DATABASE_TYPE,
|
|
||||||
self._CONNECTION_ATTRIBUTES,
|
self._CONNECTION_ATTRIBUTES,
|
||||||
version=__version__,
|
version=__version__,
|
||||||
tracer_provider=tracer_provider,
|
tracer_provider=tracer_provider,
|
||||||
@ -93,8 +91,7 @@ class MySQLInstrumentor(BaseInstrumentor):
|
|||||||
return dbapi.instrument_connection(
|
return dbapi.instrument_connection(
|
||||||
tracer,
|
tracer,
|
||||||
connection,
|
connection,
|
||||||
self._DATABASE_COMPONENT,
|
self._DATABASE_SYSTEM,
|
||||||
self._DATABASE_TYPE,
|
|
||||||
self._CONNECTION_ATTRIBUTES,
|
self._CONNECTION_ATTRIBUTES,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -62,8 +62,7 @@ class Psycopg2Instrumentor(BaseInstrumentor):
|
|||||||
"user": "info.user",
|
"user": "info.user",
|
||||||
}
|
}
|
||||||
|
|
||||||
_DATABASE_COMPONENT = "postgresql"
|
_DATABASE_SYSTEM = "postgresql"
|
||||||
_DATABASE_TYPE = "sql"
|
|
||||||
|
|
||||||
def _instrument(self, **kwargs):
|
def _instrument(self, **kwargs):
|
||||||
"""Integrate with PostgreSQL Psycopg library.
|
"""Integrate with PostgreSQL Psycopg library.
|
||||||
@ -75,8 +74,7 @@ class Psycopg2Instrumentor(BaseInstrumentor):
|
|||||||
__name__,
|
__name__,
|
||||||
psycopg2,
|
psycopg2,
|
||||||
"connect",
|
"connect",
|
||||||
self._DATABASE_COMPONENT,
|
self._DATABASE_SYSTEM,
|
||||||
self._DATABASE_TYPE,
|
|
||||||
self._CONNECTION_ATTRIBUTES,
|
self._CONNECTION_ATTRIBUTES,
|
||||||
version=__version__,
|
version=__version__,
|
||||||
tracer_provider=tracer_provider,
|
tracer_provider=tracer_provider,
|
||||||
@ -152,8 +150,7 @@ def _new_cursor_factory(db_api=None, base_factory=None):
|
|||||||
if not db_api:
|
if not db_api:
|
||||||
db_api = DatabaseApiIntegration(
|
db_api = DatabaseApiIntegration(
|
||||||
__name__,
|
__name__,
|
||||||
Psycopg2Instrumentor._DATABASE_COMPONENT,
|
Psycopg2Instrumentor._DATABASE_SYSTEM,
|
||||||
database_type=Psycopg2Instrumentor._DATABASE_TYPE,
|
|
||||||
connection_attributes=Psycopg2Instrumentor._CONNECTION_ATTRIBUTES,
|
connection_attributes=Psycopg2Instrumentor._CONNECTION_ATTRIBUTES,
|
||||||
version=__version__,
|
version=__version__,
|
||||||
)
|
)
|
||||||
|
@ -45,7 +45,7 @@ from opentelemetry.instrumentation.pymongo.version import __version__
|
|||||||
from opentelemetry.trace import SpanKind, get_tracer
|
from opentelemetry.trace import SpanKind, get_tracer
|
||||||
from opentelemetry.trace.status import Status, StatusCode
|
from opentelemetry.trace.status import Status, StatusCode
|
||||||
|
|
||||||
DATABASE_TYPE = "mongodb"
|
DATABASE_SYSTEM = "mongodb"
|
||||||
|
|
||||||
|
|
||||||
class CommandTracer(monitoring.CommandListener):
|
class CommandTracer(monitoring.CommandListener):
|
||||||
@ -68,7 +68,7 @@ class CommandTracer(monitoring.CommandListener):
|
|||||||
try:
|
try:
|
||||||
span = self._tracer.start_span(name, kind=SpanKind.CLIENT)
|
span = self._tracer.start_span(name, kind=SpanKind.CLIENT)
|
||||||
if span.is_recording():
|
if span.is_recording():
|
||||||
span.set_attribute("db.system", DATABASE_TYPE)
|
span.set_attribute("db.system", DATABASE_SYSTEM)
|
||||||
span.set_attribute("db.name", event.database_name)
|
span.set_attribute("db.name", event.database_name)
|
||||||
span.set_attribute("db.statement", statement)
|
span.set_attribute("db.statement", statement)
|
||||||
if event.connection_id is not None:
|
if event.connection_id is not None:
|
||||||
|
@ -55,8 +55,7 @@ class PyMySQLInstrumentor(BaseInstrumentor):
|
|||||||
"user": "user",
|
"user": "user",
|
||||||
}
|
}
|
||||||
|
|
||||||
_DATABASE_COMPONENT = "mysql"
|
_DATABASE_SYSTEM = "mysql"
|
||||||
_DATABASE_TYPE = "sql"
|
|
||||||
|
|
||||||
def _instrument(self, **kwargs):
|
def _instrument(self, **kwargs):
|
||||||
"""Integrate with the PyMySQL library.
|
"""Integrate with the PyMySQL library.
|
||||||
@ -68,8 +67,7 @@ class PyMySQLInstrumentor(BaseInstrumentor):
|
|||||||
__name__,
|
__name__,
|
||||||
pymysql,
|
pymysql,
|
||||||
"connect",
|
"connect",
|
||||||
self._DATABASE_COMPONENT,
|
self._DATABASE_SYSTEM,
|
||||||
self._DATABASE_TYPE,
|
|
||||||
self._CONNECTION_ATTRIBUTES,
|
self._CONNECTION_ATTRIBUTES,
|
||||||
version=__version__,
|
version=__version__,
|
||||||
tracer_provider=tracer_provider,
|
tracer_provider=tracer_provider,
|
||||||
@ -93,8 +91,7 @@ class PyMySQLInstrumentor(BaseInstrumentor):
|
|||||||
return dbapi.instrument_connection(
|
return dbapi.instrument_connection(
|
||||||
__name__,
|
__name__,
|
||||||
connection,
|
connection,
|
||||||
self._DATABASE_COMPONENT,
|
self._DATABASE_SYSTEM,
|
||||||
self._DATABASE_TYPE,
|
|
||||||
self._CONNECTION_ATTRIBUTES,
|
self._CONNECTION_ATTRIBUTES,
|
||||||
version=__version__,
|
version=__version__,
|
||||||
)
|
)
|
||||||
|
@ -28,7 +28,6 @@ from .pyramid_base_test import InstrumentationTest
|
|||||||
|
|
||||||
def expected_attributes(override_attributes):
|
def expected_attributes(override_attributes):
|
||||||
default_attributes = {
|
default_attributes = {
|
||||||
"component": "http",
|
|
||||||
"http.method": "GET",
|
"http.method": "GET",
|
||||||
"http.server_name": "localhost",
|
"http.server_name": "localhost",
|
||||||
"http.scheme": "http",
|
"http.scheme": "http",
|
||||||
|
@ -139,7 +139,6 @@ def _instrument(tracer_provider=None, span_callback=None, name_callback=None):
|
|||||||
exception = None
|
exception = None
|
||||||
with recorder.record_client_duration(labels):
|
with recorder.record_client_duration(labels):
|
||||||
if span.is_recording():
|
if span.is_recording():
|
||||||
span.set_attribute("component", "http")
|
|
||||||
span.set_attribute("http.method", method)
|
span.set_attribute("http.method", method)
|
||||||
span.set_attribute("http.url", url)
|
span.set_attribute("http.url", url)
|
||||||
|
|
||||||
|
@ -79,7 +79,6 @@ class RequestsIntegrationTestBase(abc.ABC):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
span.attributes,
|
span.attributes,
|
||||||
{
|
{
|
||||||
"component": "http",
|
|
||||||
"http.method": "GET",
|
"http.method": "GET",
|
||||||
"http.url": self.URL,
|
"http.url": self.URL,
|
||||||
"http.status_code": 200,
|
"http.status_code": 200,
|
||||||
@ -255,7 +254,6 @@ class RequestsIntegrationTestBase(abc.ABC):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
span.attributes,
|
span.attributes,
|
||||||
{
|
{
|
||||||
"component": "http",
|
|
||||||
"http.method": "GET",
|
"http.method": "GET",
|
||||||
"http.url": self.URL,
|
"http.url": self.URL,
|
||||||
"http.status_code": 200,
|
"http.status_code": 200,
|
||||||
@ -287,8 +285,7 @@ class RequestsIntegrationTestBase(abc.ABC):
|
|||||||
|
|
||||||
span = self.assert_span()
|
span = self.assert_span()
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
span.attributes,
|
span.attributes, {"http.method": "GET", "http.url": self.URL}
|
||||||
{"component": "http", "http.method": "GET", "http.url": self.URL},
|
|
||||||
)
|
)
|
||||||
self.assertEqual(span.status.status_code, StatusCode.ERROR)
|
self.assertEqual(span.status.status_code, StatusCode.ERROR)
|
||||||
|
|
||||||
@ -323,8 +320,7 @@ class RequestsIntegrationTestBase(abc.ABC):
|
|||||||
|
|
||||||
span = self.assert_span()
|
span = self.assert_span()
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
span.attributes,
|
span.attributes, {"http.method": "GET", "http.url": self.URL}
|
||||||
{"component": "http", "http.method": "GET", "http.url": self.URL},
|
|
||||||
)
|
)
|
||||||
self.assertEqual(span.status.status_code, StatusCode.ERROR)
|
self.assertEqual(span.status.status_code, StatusCode.ERROR)
|
||||||
|
|
||||||
@ -361,7 +357,6 @@ class RequestsIntegrationTestBase(abc.ABC):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
span.attributes,
|
span.attributes,
|
||||||
{
|
{
|
||||||
"component": "http",
|
|
||||||
"http.method": "GET",
|
"http.method": "GET",
|
||||||
"http.url": self.URL,
|
"http.url": self.URL,
|
||||||
"http.status_code": 500,
|
"http.status_code": 500,
|
||||||
@ -423,8 +418,7 @@ class TestRequestsIntegration(RequestsIntegrationTestBase, TestBase):
|
|||||||
|
|
||||||
self.assertEqual(span.name, "HTTP POST")
|
self.assertEqual(span.name, "HTTP POST")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
span.attributes,
|
span.attributes, {"http.method": "POST", "http.url": url}
|
||||||
{"component": "http", "http.method": "POST", "http.url": url},
|
|
||||||
)
|
)
|
||||||
self.assertEqual(span.status.status_code, StatusCode.ERROR)
|
self.assertEqual(span.status.status_code, StatusCode.ERROR)
|
||||||
|
|
||||||
|
@ -51,8 +51,7 @@ class SQLite3Instrumentor(BaseInstrumentor):
|
|||||||
# No useful attributes of sqlite3 connection object
|
# No useful attributes of sqlite3 connection object
|
||||||
_CONNECTION_ATTRIBUTES = {}
|
_CONNECTION_ATTRIBUTES = {}
|
||||||
|
|
||||||
_DATABASE_COMPONENT = "sqlite"
|
_DATABASE_SYSTEM = "sqlite"
|
||||||
_DATABASE_TYPE = "sql"
|
|
||||||
|
|
||||||
def _instrument(self, **kwargs):
|
def _instrument(self, **kwargs):
|
||||||
"""Integrate with SQLite3 Python library.
|
"""Integrate with SQLite3 Python library.
|
||||||
@ -64,8 +63,7 @@ class SQLite3Instrumentor(BaseInstrumentor):
|
|||||||
__name__,
|
__name__,
|
||||||
sqlite3,
|
sqlite3,
|
||||||
"connect",
|
"connect",
|
||||||
self._DATABASE_COMPONENT,
|
self._DATABASE_SYSTEM,
|
||||||
self._DATABASE_TYPE,
|
|
||||||
self._CONNECTION_ATTRIBUTES,
|
self._CONNECTION_ATTRIBUTES,
|
||||||
version=__version__,
|
version=__version__,
|
||||||
tracer_provider=tracer_provider,
|
tracer_provider=tracer_provider,
|
||||||
@ -90,8 +88,7 @@ class SQLite3Instrumentor(BaseInstrumentor):
|
|||||||
return dbapi.instrument_connection(
|
return dbapi.instrument_connection(
|
||||||
tracer,
|
tracer,
|
||||||
connection,
|
connection,
|
||||||
self._DATABASE_COMPONENT,
|
self._DATABASE_SYSTEM,
|
||||||
self._DATABASE_TYPE,
|
|
||||||
self._CONNECTION_ATTRIBUTES,
|
self._CONNECTION_ATTRIBUTES,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -174,7 +174,6 @@ def _log_exception(tracer, func, handler, args, kwargs):
|
|||||||
|
|
||||||
def _get_attributes_from_request(request):
|
def _get_attributes_from_request(request):
|
||||||
attrs = {
|
attrs = {
|
||||||
"component": "tornado",
|
|
||||||
"http.method": request.method,
|
"http.method": request.method,
|
||||||
"http.scheme": request.protocol,
|
"http.scheme": request.protocol,
|
||||||
"http.host": request.host,
|
"http.host": request.host,
|
||||||
|
@ -43,7 +43,6 @@ def fetch_async(tracer, func, _, args, kwargs):
|
|||||||
|
|
||||||
if span.is_recording():
|
if span.is_recording():
|
||||||
attributes = {
|
attributes = {
|
||||||
"component": "tornado",
|
|
||||||
"http.url": request.url,
|
"http.url": request.url,
|
||||||
"http.method": request.method,
|
"http.method": request.method,
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,6 @@ class TestTornadoInstrumentation(TornadoTest):
|
|||||||
self.assert_span_has_attributes(
|
self.assert_span_has_attributes(
|
||||||
server,
|
server,
|
||||||
{
|
{
|
||||||
"component": "tornado",
|
|
||||||
"http.method": method,
|
"http.method": method,
|
||||||
"http.scheme": "http",
|
"http.scheme": "http",
|
||||||
"http.host": "127.0.0.1:" + str(self.get_http_port()),
|
"http.host": "127.0.0.1:" + str(self.get_http_port()),
|
||||||
@ -146,7 +145,6 @@ class TestTornadoInstrumentation(TornadoTest):
|
|||||||
self.assert_span_has_attributes(
|
self.assert_span_has_attributes(
|
||||||
client,
|
client,
|
||||||
{
|
{
|
||||||
"component": "tornado",
|
|
||||||
"http.url": self.get_url("/"),
|
"http.url": self.get_url("/"),
|
||||||
"http.method": method,
|
"http.method": method,
|
||||||
"http.status_code": 201,
|
"http.status_code": 201,
|
||||||
@ -205,7 +203,6 @@ class TestTornadoInstrumentation(TornadoTest):
|
|||||||
self.assert_span_has_attributes(
|
self.assert_span_has_attributes(
|
||||||
server,
|
server,
|
||||||
{
|
{
|
||||||
"component": "tornado",
|
|
||||||
"http.method": "GET",
|
"http.method": "GET",
|
||||||
"http.scheme": "http",
|
"http.scheme": "http",
|
||||||
"http.host": "127.0.0.1:" + str(self.get_http_port()),
|
"http.host": "127.0.0.1:" + str(self.get_http_port()),
|
||||||
@ -223,7 +220,6 @@ class TestTornadoInstrumentation(TornadoTest):
|
|||||||
self.assert_span_has_attributes(
|
self.assert_span_has_attributes(
|
||||||
client,
|
client,
|
||||||
{
|
{
|
||||||
"component": "tornado",
|
|
||||||
"http.url": self.get_url(url),
|
"http.url": self.get_url(url),
|
||||||
"http.method": "GET",
|
"http.method": "GET",
|
||||||
"http.status_code": 201,
|
"http.status_code": 201,
|
||||||
@ -243,7 +239,6 @@ class TestTornadoInstrumentation(TornadoTest):
|
|||||||
self.assert_span_has_attributes(
|
self.assert_span_has_attributes(
|
||||||
server,
|
server,
|
||||||
{
|
{
|
||||||
"component": "tornado",
|
|
||||||
"http.method": "GET",
|
"http.method": "GET",
|
||||||
"http.scheme": "http",
|
"http.scheme": "http",
|
||||||
"http.host": "127.0.0.1:" + str(self.get_http_port()),
|
"http.host": "127.0.0.1:" + str(self.get_http_port()),
|
||||||
@ -258,7 +253,6 @@ class TestTornadoInstrumentation(TornadoTest):
|
|||||||
self.assert_span_has_attributes(
|
self.assert_span_has_attributes(
|
||||||
client,
|
client,
|
||||||
{
|
{
|
||||||
"component": "tornado",
|
|
||||||
"http.url": self.get_url("/error"),
|
"http.url": self.get_url("/error"),
|
||||||
"http.method": "GET",
|
"http.method": "GET",
|
||||||
"http.status_code": 500,
|
"http.status_code": 500,
|
||||||
@ -278,7 +272,6 @@ class TestTornadoInstrumentation(TornadoTest):
|
|||||||
self.assert_span_has_attributes(
|
self.assert_span_has_attributes(
|
||||||
server,
|
server,
|
||||||
{
|
{
|
||||||
"component": "tornado",
|
|
||||||
"http.method": "GET",
|
"http.method": "GET",
|
||||||
"http.scheme": "http",
|
"http.scheme": "http",
|
||||||
"http.host": "127.0.0.1:" + str(self.get_http_port()),
|
"http.host": "127.0.0.1:" + str(self.get_http_port()),
|
||||||
@ -294,7 +287,6 @@ class TestTornadoInstrumentation(TornadoTest):
|
|||||||
self.assert_span_has_attributes(
|
self.assert_span_has_attributes(
|
||||||
client,
|
client,
|
||||||
{
|
{
|
||||||
"component": "tornado",
|
|
||||||
"http.url": self.get_url("/missing-url"),
|
"http.url": self.get_url("/missing-url"),
|
||||||
"http.method": "GET",
|
"http.method": "GET",
|
||||||
"http.status_code": 404,
|
"http.status_code": 404,
|
||||||
@ -324,7 +316,6 @@ class TestTornadoInstrumentation(TornadoTest):
|
|||||||
self.assert_span_has_attributes(
|
self.assert_span_has_attributes(
|
||||||
server,
|
server,
|
||||||
{
|
{
|
||||||
"component": "tornado",
|
|
||||||
"http.method": "GET",
|
"http.method": "GET",
|
||||||
"http.scheme": "http",
|
"http.scheme": "http",
|
||||||
"http.host": "127.0.0.1:" + str(self.get_http_port()),
|
"http.host": "127.0.0.1:" + str(self.get_http_port()),
|
||||||
@ -342,7 +333,6 @@ class TestTornadoInstrumentation(TornadoTest):
|
|||||||
self.assert_span_has_attributes(
|
self.assert_span_has_attributes(
|
||||||
client,
|
client,
|
||||||
{
|
{
|
||||||
"component": "tornado",
|
|
||||||
"http.url": self.get_url("/dyna"),
|
"http.url": self.get_url("/dyna"),
|
||||||
"http.method": "GET",
|
"http.method": "GET",
|
||||||
"http.status_code": 202,
|
"http.status_code": 202,
|
||||||
@ -362,7 +352,6 @@ class TestTornadoInstrumentation(TornadoTest):
|
|||||||
self.assert_span_has_attributes(
|
self.assert_span_has_attributes(
|
||||||
client,
|
client,
|
||||||
{
|
{
|
||||||
"component": "tornado",
|
|
||||||
"http.url": self.get_url(path),
|
"http.url": self.get_url(path),
|
||||||
"http.method": "GET",
|
"http.method": "GET",
|
||||||
"http.status_code": 200,
|
"http.status_code": 200,
|
||||||
|
@ -163,7 +163,6 @@ def _instrument(tracer_provider=None, span_callback=None, name_callback=None):
|
|||||||
exception = None
|
exception = None
|
||||||
with recorder.record_client_duration(labels):
|
with recorder.record_client_duration(labels):
|
||||||
if span.is_recording():
|
if span.is_recording():
|
||||||
span.set_attribute("component", "http")
|
|
||||||
span.set_attribute("http.method", method)
|
span.set_attribute("http.method", method)
|
||||||
span.set_attribute("http.url", url)
|
span.set_attribute("http.url", url)
|
||||||
|
|
||||||
|
@ -104,7 +104,6 @@ class RequestsIntegrationTestBase(abc.ABC):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
span.attributes,
|
span.attributes,
|
||||||
{
|
{
|
||||||
"component": "http",
|
|
||||||
"http.method": "GET",
|
"http.method": "GET",
|
||||||
"http.url": self.URL,
|
"http.url": self.URL,
|
||||||
"http.status_code": 200,
|
"http.status_code": 200,
|
||||||
@ -289,7 +288,6 @@ class RequestsIntegrationTestBase(abc.ABC):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
span.attributes,
|
span.attributes,
|
||||||
{
|
{
|
||||||
"component": "http",
|
|
||||||
"http.method": "GET",
|
"http.method": "GET",
|
||||||
"http.url": self.URL,
|
"http.url": self.URL,
|
||||||
"http.status_code": 200,
|
"http.status_code": 200,
|
||||||
@ -320,7 +318,6 @@ class RequestsIntegrationTestBase(abc.ABC):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
dict(span.attributes),
|
dict(span.attributes),
|
||||||
{
|
{
|
||||||
"component": "http",
|
|
||||||
"http.method": "GET",
|
"http.method": "GET",
|
||||||
"http.url": "http://httpbin.org/status/500",
|
"http.url": "http://httpbin.org/status/500",
|
||||||
"http.status_code": 500,
|
"http.status_code": 500,
|
||||||
|
@ -104,7 +104,6 @@ def collect_request_attributes(environ):
|
|||||||
WSGI environ and returns a dictionary to be used as span creation attributes."""
|
WSGI environ and returns a dictionary to be used as span creation attributes."""
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
"component": "http",
|
|
||||||
"http.method": environ.get("REQUEST_METHOD"),
|
"http.method": environ.get("REQUEST_METHOD"),
|
||||||
"http.server_name": environ.get("SERVER_NAME"),
|
"http.server_name": environ.get("SERVER_NAME"),
|
||||||
"http.scheme": environ.get("wsgi.url_scheme"),
|
"http.scheme": environ.get("wsgi.url_scheme"),
|
||||||
|
@ -106,7 +106,6 @@ class TestWsgiApplication(WsgiTestBase):
|
|||||||
self.assertEqual(span_list[0].name, span_name)
|
self.assertEqual(span_list[0].name, span_name)
|
||||||
self.assertEqual(span_list[0].kind, trace_api.SpanKind.SERVER)
|
self.assertEqual(span_list[0].kind, trace_api.SpanKind.SERVER)
|
||||||
expected_attributes = {
|
expected_attributes = {
|
||||||
"component": "http",
|
|
||||||
"http.server_name": "127.0.0.1",
|
"http.server_name": "127.0.0.1",
|
||||||
"http.scheme": "http",
|
"http.scheme": "http",
|
||||||
"net.host.port": 80,
|
"net.host.port": 80,
|
||||||
@ -215,7 +214,6 @@ class TestWsgiAttributes(unittest.TestCase):
|
|||||||
self.assertDictEqual(
|
self.assertDictEqual(
|
||||||
attrs,
|
attrs,
|
||||||
{
|
{
|
||||||
"component": "http",
|
|
||||||
"http.method": "GET",
|
"http.method": "GET",
|
||||||
"http.host": "127.0.0.1",
|
"http.host": "127.0.0.1",
|
||||||
"http.url": "http://127.0.0.1/?foo=bar",
|
"http.url": "http://127.0.0.1/?foo=bar",
|
||||||
|
Reference in New Issue
Block a user