Skip to content

Commit f0adb23

Browse files
authored
Remove 'component' span attribute in instrumentations (#301)
1 parent f022385 commit f0adb23

File tree

29 files changed

+77
-166
lines changed

29 files changed

+77
-166
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased](https://github.com/open-telemetry/opentelemetry-python-contrib/compare/v0.17b0...HEAD)
88

9+
### Changed
10+
- Remove `component` span attribute in instrumentations.
11+
`opentelemetry-instrumentation-aiopg`, `opentelemetry-instrumentation-dbapi` Remove unused `database_type` parameter from `trace_integration` function.
12+
([#301](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/301))
13+
914
## [0.17b0](https://github.com/open-telemetry/opentelemetry-python-contrib/releases/tag/v0.17b0) - 2021-01-20
1015

1116
### Added

instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ async def on_request_start(
169169

170170
if trace_config_ctx.span.is_recording():
171171
attributes = {
172-
"component": "http",
173172
"http.method": http_method,
174173
"http.url": trace_config_ctx.url_filter(params.url)
175174
if callable(trace_config_ctx.url_filter)

instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py

+1-11
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ def test_status_codes(self):
129129
"HTTP GET",
130130
(span_status, None),
131131
{
132-
"component": "http",
133132
"http.method": "GET",
134133
"http.url": "http://{}:{}/test-path?query=param#foobar".format(
135134
host, port
@@ -187,7 +186,6 @@ def test_span_name_option(self):
187186
expected,
188187
(StatusCode.UNSET, None),
189188
{
190-
"component": "http",
191189
"http.method": method,
192190
"http.url": "http://{}:{}{}".format(
193191
host, port, path
@@ -219,7 +217,6 @@ def strip_query_params(url: yarl.URL) -> str:
219217
"HTTP GET",
220218
(StatusCode.UNSET, None),
221219
{
222-
"component": "http",
223220
"http.method": "GET",
224221
"http.url": "http://{}:{}/some/path".format(
225222
host, port
@@ -256,11 +253,7 @@ async def do_request(url):
256253
(
257254
"HTTP GET",
258255
(expected_status, None),
259-
{
260-
"component": "http",
261-
"http.method": "GET",
262-
"http.url": url,
263-
},
256+
{"http.method": "GET", "http.url": url},
264257
)
265258
]
266259
)
@@ -285,7 +278,6 @@ async def request_handler(request):
285278
"HTTP GET",
286279
(StatusCode.ERROR, None),
287280
{
288-
"component": "http",
289281
"http.method": "GET",
290282
"http.url": "http://{}:{}/test_timeout".format(
291283
host, port
@@ -315,7 +307,6 @@ async def request_handler(request):
315307
"HTTP GET",
316308
(StatusCode.ERROR, None),
317309
{
318-
"component": "http",
319310
"http.method": "GET",
320311
"http.url": "http://{}:{}/test_too_many_redirects".format(
321312
host, port
@@ -364,7 +355,6 @@ def test_instrument(self):
364355
self.get_default_request(), self.URL, self.default_handler
365356
)
366357
span = self.assert_spans(1)
367-
self.assertEqual("http", span.attributes["component"])
368358
self.assertEqual("GET", span.attributes["http.method"])
369359
self.assertEqual(
370360
"http://{}:{}/test-path".format(host, port),

instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/__init__.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ class AiopgInstrumentor(BaseInstrumentor):
5858
"user": "info.user",
5959
}
6060

61-
_DATABASE_COMPONENT = "postgresql"
62-
_DATABASE_TYPE = "sql"
61+
_DATABASE_SYSTEM = "postgresql"
6362

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

7170
wrappers.wrap_connect(
7271
__name__,
73-
self._DATABASE_COMPONENT,
74-
self._DATABASE_TYPE,
72+
self._DATABASE_SYSTEM,
7573
self._CONNECTION_ATTRIBUTES,
7674
version=__version__,
7775
tracer_provider=tracer_provider,
7876
)
7977

8078
wrappers.wrap_create_pool(
8179
__name__,
82-
self._DATABASE_COMPONENT,
83-
self._DATABASE_TYPE,
80+
self._DATABASE_SYSTEM,
8481
self._CONNECTION_ATTRIBUTES,
8582
version=__version__,
8683
tracer_provider=tracer_provider,
@@ -104,8 +101,7 @@ def instrument_connection(self, connection):
104101
return wrappers.instrument_connection(
105102
__name__,
106103
connection,
107-
self._DATABASE_COMPONENT,
108-
self._DATABASE_TYPE,
104+
self._DATABASE_SYSTEM,
109105
self._CONNECTION_ATTRIBUTES,
110106
)
111107

instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/wrappers.py

+18-28
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from opentelemetry import trace
2525
from opentelemetry.instrumentation.aiopg import trace_integration
2626
27-
trace_integration(aiopg.connection, "_connect", "postgresql", "sql")
27+
trace_integration(aiopg.connection, "_connect", "postgresql")
2828
2929
API
3030
---
@@ -48,28 +48,25 @@
4848

4949

5050
def trace_integration(
51-
database_component: str,
52-
database_type: str = "",
51+
database_system: str,
5352
connection_attributes: typing.Dict = None,
5453
tracer_provider: typing.Optional[TracerProvider] = None,
5554
):
5655
"""Integrate with aiopg library.
5756
based on dbapi integration, where replaced sync wrap methods to async
5857
5958
Args:
60-
database_component: Database driver name or
61-
database name "postgreSQL".
62-
database_type: The Database type. For any SQL database, "sql".
59+
database_system: An identifier for the database management system (DBMS)
60+
product being used.
6361
connection_attributes: Attribute names for database, port, host and
6462
user in Connection object.
6563
tracer_provider: The :class:`opentelemetry.trace.TracerProvider` to
66-
use. If ommited the current configured one is used.
64+
use. If omitted the current configured one is used.
6765
"""
6866

6967
wrap_connect(
7068
__name__,
71-
database_component,
72-
database_type,
69+
database_system,
7370
connection_attributes,
7471
__version__,
7572
tracer_provider,
@@ -78,8 +75,7 @@ def trace_integration(
7875

7976
def wrap_connect(
8077
name: str,
81-
database_component: str,
82-
database_type: str = "",
78+
database_system: str,
8379
connection_attributes: typing.Dict = None,
8480
version: str = "",
8581
tracer_provider: typing.Optional[TracerProvider] = None,
@@ -89,14 +85,13 @@ def wrap_connect(
8985
9086
Args:
9187
name: Name of opentelemetry extension for aiopg.
92-
database_component: Database driver name
93-
or database name "postgreSQL".
94-
database_type: The Database type. For any SQL database, "sql".
88+
database_system: An identifier for the database management system (DBMS)
89+
product being used.
9590
connection_attributes: Attribute names for database, port, host and
9691
user in Connection object.
9792
version: Version of opentelemetry extension for aiopg.
9893
tracer_provider: The :class:`opentelemetry.trace.TracerProvider` to
99-
use. If ommited the current configured one is used.
94+
use. If omitted the current configured one is used.
10095
"""
10196

10297
# pylint: disable=unused-argument
@@ -108,8 +103,7 @@ def wrap_connect_(
108103
):
109104
db_integration = AiopgIntegration(
110105
name,
111-
database_component,
112-
database_type=database_type,
106+
database_system,
113107
connection_attributes=connection_attributes,
114108
version=version,
115109
tracer_provider=tracer_provider,
@@ -135,8 +129,7 @@ def unwrap_connect():
135129
def instrument_connection(
136130
name: str,
137131
connection,
138-
database_component: str,
139-
database_type: str = "",
132+
database_system: str,
140133
connection_attributes: typing.Dict = None,
141134
version: str = "",
142135
tracer_provider: typing.Optional[TracerProvider] = None,
@@ -146,21 +139,20 @@ def instrument_connection(
146139
Args:
147140
name: Name of opentelemetry extension for aiopg.
148141
connection: The connection to instrument.
149-
database_component: Database driver name or database name "postgreSQL".
150-
database_type: The Database type. For any SQL database, "sql".
142+
database_system: An identifier for the database management system (DBMS)
143+
product being used.
151144
connection_attributes: Attribute names for database, port, host and
152145
user in a connection object.
153146
version: Version of opentelemetry extension for aiopg.
154147
tracer_provider: The :class:`opentelemetry.trace.TracerProvider` to
155-
use. If ommited the current configured one is used.
148+
use. If omitted the current configured one is used.
156149
157150
Returns:
158151
An instrumented connection.
159152
"""
160153
db_integration = AiopgIntegration(
161154
name,
162-
database_component,
163-
database_type,
155+
database_system,
164156
connection_attributes=connection_attributes,
165157
version=version,
166158
tracer_provider=tracer_provider,
@@ -187,8 +179,7 @@ def uninstrument_connection(connection):
187179

188180
def wrap_create_pool(
189181
name: str,
190-
database_component: str,
191-
database_type: str = "",
182+
database_system: str,
192183
connection_attributes: typing.Dict = None,
193184
version: str = "",
194185
tracer_provider: typing.Optional[TracerProvider] = None,
@@ -202,8 +193,7 @@ def wrap_create_pool_(
202193
):
203194
db_integration = AiopgIntegration(
204195
name,
205-
database_component,
206-
database_type,
196+
database_system,
207197
connection_attributes=connection_attributes,
208198
version=version,
209199
tracer_provider=tracer_provider,

instrumentation/opentelemetry-instrumentation-aiopg/tests/test_aiopg_integration.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ def test_span_succeeded(self):
242242
db_integration = AiopgIntegration(
243243
self.tracer,
244244
"testcomponent",
245-
"testtype",
246245
connection_attributes,
247246
capture_parameters=True,
248247
)
@@ -259,7 +258,6 @@ def test_span_succeeded(self):
259258
self.assertEqual(span.name, "Test")
260259
self.assertIs(span.kind, trace_api.SpanKind.CLIENT)
261260

262-
self.assertEqual(span.attributes["component"], "testcomponent")
263261
self.assertEqual(span.attributes["db.system"], "testcomponent")
264262
self.assertEqual(span.attributes["db.name"], "testdatabase")
265263
self.assertEqual(span.attributes["db.statement"], "Test query")
@@ -294,7 +292,7 @@ def test_span_not_recording(self):
294292
mock_tracer.use_span.return_value.__enter__ = mock_span
295293
mock_tracer.use_span.return_value.__exit__ = True
296294
db_integration = AiopgIntegration(
297-
mock_tracer, "testcomponent", "testtype", connection_attributes
295+
mock_tracer, "testcomponent", connection_attributes
298296
)
299297
mock_connection = async_call(
300298
db_integration.wrapped_connection(

instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ def collect_request_attributes(scope):
7272
http_url = http_url + ("?" + urllib.parse.unquote(query_string))
7373

7474
result = {
75-
"component": scope["type"],
7675
"http.scheme": scope.get("scheme"),
7776
"http.host": server_host,
7877
"net.host.port": port,

instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py

-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ def validate_outputs(self, outputs, error=None, modifiers=None):
134134
"name": "GET asgi",
135135
"kind": trace_api.SpanKind.SERVER,
136136
"attributes": {
137-
"component": "http",
138137
"http.method": "GET",
139138
"http.scheme": "http",
140139
"net.host.port": 80,
@@ -321,7 +320,6 @@ def test_request_attributes(self):
321320
self.assertDictEqual(
322321
attrs,
323322
{
324-
"component": "http",
325323
"http.method": "GET",
326324
"http.host": "127.0.0.1",
327325
"http.target": "/",

0 commit comments

Comments
 (0)