Skip to content
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

Remove 'component' span attribute in instrumentations #301

Merged
merged 5 commits into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

### 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

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ async def on_request_start(

if trace_config_ctx.span.is_recording():
attributes = {
"component": "http",
"http.method": http_method,
"http.url": trace_config_ctx.url_filter(params.url)
if callable(trace_config_ctx.url_filter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ def test_status_codes(self):
"HTTP GET",
(span_status, None),
{
"component": "http",
"http.method": "GET",
"http.url": "http://{}:{}/test-path?query=param#foobar".format(
host, port
Expand Down Expand Up @@ -187,7 +186,6 @@ def test_span_name_option(self):
expected,
(StatusCode.UNSET, None),
{
"component": "http",
"http.method": method,
"http.url": "http://{}:{}{}".format(
host, port, path
Expand Down Expand Up @@ -219,7 +217,6 @@ def strip_query_params(url: yarl.URL) -> str:
"HTTP GET",
(StatusCode.UNSET, None),
{
"component": "http",
"http.method": "GET",
"http.url": "http://{}:{}/some/path".format(
host, port
Expand Down Expand Up @@ -256,11 +253,7 @@ async def do_request(url):
(
"HTTP GET",
(expected_status, None),
{
"component": "http",
"http.method": "GET",
"http.url": url,
},
{"http.method": "GET", "http.url": url},
)
]
)
Expand All @@ -285,7 +278,6 @@ async def request_handler(request):
"HTTP GET",
(StatusCode.ERROR, None),
{
"component": "http",
"http.method": "GET",
"http.url": "http://{}:{}/test_timeout".format(
host, port
Expand Down Expand Up @@ -315,7 +307,6 @@ async def request_handler(request):
"HTTP GET",
(StatusCode.ERROR, None),
{
"component": "http",
"http.method": "GET",
"http.url": "http://{}:{}/test_too_many_redirects".format(
host, port
Expand Down Expand Up @@ -364,7 +355,6 @@ def test_instrument(self):
self.get_default_request(), self.URL, self.default_handler
)
span = self.assert_spans(1)
self.assertEqual("http", span.attributes["component"])
self.assertEqual("GET", span.attributes["http.method"])
self.assertEqual(
"http://{}:{}/test-path".format(host, port),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ class AiopgInstrumentor(BaseInstrumentor):
"user": "info.user",
}

_DATABASE_COMPONENT = "postgresql"
_DATABASE_TYPE = "sql"
_DATABASE_SYSTEM = "postgresql"

def _instrument(self, **kwargs):
"""Integrate with PostgreSQL aiopg library.
Expand All @@ -70,17 +69,15 @@ def _instrument(self, **kwargs):

wrappers.wrap_connect(
__name__,
self._DATABASE_COMPONENT,
self._DATABASE_TYPE,
self._DATABASE_SYSTEM,
self._CONNECTION_ATTRIBUTES,
version=__version__,
tracer_provider=tracer_provider,
)

wrappers.wrap_create_pool(
__name__,
self._DATABASE_COMPONENT,
self._DATABASE_TYPE,
self._DATABASE_SYSTEM,
self._CONNECTION_ATTRIBUTES,
version=__version__,
tracer_provider=tracer_provider,
Expand All @@ -104,8 +101,7 @@ def instrument_connection(self, connection):
return wrappers.instrument_connection(
__name__,
connection,
self._DATABASE_COMPONENT,
self._DATABASE_TYPE,
self._DATABASE_SYSTEM,
self._CONNECTION_ATTRIBUTES,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from opentelemetry import trace
from opentelemetry.instrumentation.aiopg import trace_integration

trace_integration(aiopg.connection, "_connect", "postgresql", "sql")
trace_integration(aiopg.connection, "_connect", "postgresql")

API
---
Expand All @@ -48,28 +48,25 @@


def trace_integration(
database_component: str,
database_type: str = "",
database_system: str,
connection_attributes: typing.Dict = None,
tracer_provider: typing.Optional[TracerProvider] = None,
):
"""Integrate with aiopg library.
based on dbapi integration, where replaced sync wrap methods to async

Args:
database_component: Database driver name or
database name "postgreSQL".
database_type: The Database type. For any SQL database, "sql".
database_system: An identifier for the database management system (DBMS)
product being used.
connection_attributes: Attribute names for database, port, host and
user in Connection object.
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(
__name__,
database_component,
database_type,
database_system,
connection_attributes,
__version__,
tracer_provider,
Expand All @@ -78,8 +75,7 @@ def trace_integration(

def wrap_connect(
name: str,
database_component: str,
database_type: str = "",
database_system: str,
connection_attributes: typing.Dict = None,
version: str = "",
tracer_provider: typing.Optional[TracerProvider] = None,
Expand All @@ -89,14 +85,13 @@ def wrap_connect(

Args:
name: Name of opentelemetry extension for aiopg.
database_component: Database driver name
or database name "postgreSQL".
database_type: The Database type. For any SQL database, "sql".
database_system: An identifier for the database management system (DBMS)
product being used.
connection_attributes: Attribute names for database, port, host and
user in Connection object.
version: Version of opentelemetry extension for aiopg.
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
Expand All @@ -108,8 +103,7 @@ def wrap_connect_(
):
db_integration = AiopgIntegration(
name,
database_component,
database_type=database_type,
database_system,
connection_attributes=connection_attributes,
version=version,
tracer_provider=tracer_provider,
Expand All @@ -135,8 +129,7 @@ def unwrap_connect():
def instrument_connection(
name: str,
connection,
database_component: str,
database_type: str = "",
database_system: str,
connection_attributes: typing.Dict = None,
version: str = "",
tracer_provider: typing.Optional[TracerProvider] = None,
Expand All @@ -146,21 +139,20 @@ def instrument_connection(
Args:
name: Name of opentelemetry extension for aiopg.
connection: The connection to instrument.
database_component: Database driver name or database name "postgreSQL".
database_type: The Database type. For any SQL database, "sql".
database_system: An identifier for the database management system (DBMS)
product being used.
connection_attributes: Attribute names for database, port, host and
user in a connection object.
version: Version of opentelemetry extension for aiopg.
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:
An instrumented connection.
"""
db_integration = AiopgIntegration(
name,
database_component,
database_type,
database_system,
connection_attributes=connection_attributes,
version=version,
tracer_provider=tracer_provider,
Expand All @@ -187,8 +179,7 @@ def uninstrument_connection(connection):

def wrap_create_pool(
name: str,
database_component: str,
database_type: str = "",
database_system: str,
connection_attributes: typing.Dict = None,
version: str = "",
tracer_provider: typing.Optional[TracerProvider] = None,
Expand All @@ -202,8 +193,7 @@ def wrap_create_pool_(
):
db_integration = AiopgIntegration(
name,
database_component,
database_type,
database_system,
connection_attributes=connection_attributes,
version=version,
tracer_provider=tracer_provider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ def test_span_succeeded(self):
db_integration = AiopgIntegration(
self.tracer,
"testcomponent",
"testtype",
connection_attributes,
capture_parameters=True,
)
Expand All @@ -259,7 +258,6 @@ def test_span_succeeded(self):
self.assertEqual(span.name, "Test")
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.name"], "testdatabase")
self.assertEqual(span.attributes["db.statement"], "Test query")
Expand Down Expand Up @@ -294,7 +292,7 @@ def test_span_not_recording(self):
mock_tracer.use_span.return_value.__enter__ = mock_span
mock_tracer.use_span.return_value.__exit__ = True
db_integration = AiopgIntegration(
mock_tracer, "testcomponent", "testtype", connection_attributes
mock_tracer, "testcomponent", connection_attributes
)
mock_connection = async_call(
db_integration.wrapped_connection(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def collect_request_attributes(scope):
http_url = http_url + ("?" + urllib.parse.unquote(query_string))

result = {
"component": scope["type"],
"http.scheme": scope.get("scheme"),
"http.host": server_host,
"net.host.port": port,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ def validate_outputs(self, outputs, error=None, modifiers=None):
"name": "GET asgi",
"kind": trace_api.SpanKind.SERVER,
"attributes": {
"component": "http",
"http.method": "GET",
"http.scheme": "http",
"net.host.port": 80,
Expand Down Expand Up @@ -321,7 +320,6 @@ def test_request_attributes(self):
self.assertDictEqual(
attrs,
{
"component": "http",
"http.method": "GET",
"http.host": "127.0.0.1",
"http.target": "/",
Expand Down
Loading