diff --git a/elasticapm/__init__.py b/elasticapm/__init__.py index b6c4499c40..8fb275bfb4 100644 --- a/elasticapm/__init__.py +++ b/elasticapm/__init__.py @@ -49,7 +49,6 @@ ) from elasticapm.utils.disttracing import trace_parent_from_headers, trace_parent_from_string # noqa: F401 - _activation_method = None try: diff --git a/elasticapm/contrib/serverless/aws.py b/elasticapm/contrib/serverless/aws.py index e2af1a7359..88ae75a28c 100644 --- a/elasticapm/contrib/serverless/aws.py +++ b/elasticapm/contrib/serverless/aws.py @@ -469,9 +469,11 @@ def send_partial_transaction(self) -> None: data = transport._json_serializer({"metadata": self.client.build_metadata()}) + "\n" data += transport._json_serializer({"transaction": transaction.to_dict()}) partial_transaction_url = urllib.parse.urljoin( - self.client.config.server_url - if self.client.config.server_url.endswith("/") - else self.client.config.server_url + "/", + ( + self.client.config.server_url + if self.client.config.server_url.endswith("/") + else self.client.config.server_url + "/" + ), "register/transaction", ) try: diff --git a/elasticapm/contrib/tornado/__init__.py b/elasticapm/contrib/tornado/__init__.py index 5fd5614fa1..2bbf2393f2 100644 --- a/elasticapm/contrib/tornado/__init__.py +++ b/elasticapm/contrib/tornado/__init__.py @@ -34,6 +34,7 @@ instrumentation. This module only creates the client for later use by the that instrumentation, and triggers the global instrumentation itself. """ + import tornado import elasticapm diff --git a/elasticapm/instrumentation/packages/tornado.py b/elasticapm/instrumentation/packages/tornado.py index c1f829bc15..121aacd3df 100644 --- a/elasticapm/instrumentation/packages/tornado.py +++ b/elasticapm/instrumentation/packages/tornado.py @@ -30,6 +30,7 @@ """ Instrumentation for Tornado """ + import elasticapm from elasticapm.conf import constants from elasticapm.instrumentation.packages.asyncio.base import AbstractInstrumentedModule, AsyncAbstractInstrumentedModule diff --git a/elasticapm/metrics/sets/prometheus.py b/elasticapm/metrics/sets/prometheus.py index d3798b4181..bf57cd0515 100644 --- a/elasticapm/metrics/sets/prometheus.py +++ b/elasticapm/metrics/sets/prometheus.py @@ -54,18 +54,18 @@ def _prom_counter_handler(self, name, samples, unit) -> None: # given name. The pair consists of the value, and a "created" timestamp. # We only use the former. for total_sample, _ in grouper(samples, 2): - self.counter( - self._registry.client.config.prometheus_metrics_prefix + name, **total_sample.labels - ).val = total_sample.value + self.counter(self._registry.client.config.prometheus_metrics_prefix + name, **total_sample.labels).val = ( + total_sample.value + ) def _prom_gauge_handler(self, name, samples, unit) -> None: # Counters can be converted 1:1 from Prometheus to our # format. Each sample represents a distinct labelset for a # given name for sample in samples: - self.gauge( - self._registry.client.config.prometheus_metrics_prefix + name, **sample.labels - ).val = sample.value + self.gauge(self._registry.client.config.prometheus_metrics_prefix + name, **sample.labels).val = ( + sample.value + ) def _prom_summary_handler(self, name, samples, unit) -> None: # Prometheus Summaries are analogous to our Timers, having diff --git a/tests/contrib/asyncio/starlette_tests.py b/tests/contrib/asyncio/starlette_tests.py index 055cf01ad2..fe80ea89ba 100644 --- a/tests/contrib/asyncio/starlette_tests.py +++ b/tests/contrib/asyncio/starlette_tests.py @@ -32,7 +32,6 @@ import pytest # isort:skip - starlette = pytest.importorskip("starlette") # isort:skip import os diff --git a/tests/instrumentation/asyncio_tests/aiopg_tests.py b/tests/instrumentation/asyncio_tests/aiopg_tests.py index e4808af07f..dd67846816 100644 --- a/tests/instrumentation/asyncio_tests/aiopg_tests.py +++ b/tests/instrumentation/asyncio_tests/aiopg_tests.py @@ -119,16 +119,14 @@ async def test_composable_queries(instrument, cursor, elasticapm_client): async def test_callproc(instrument, cursor, elasticapm_client): - await cursor.execute( - """ + await cursor.execute(""" CREATE OR REPLACE FUNCTION squareme(me INT) RETURNS INTEGER LANGUAGE SQL AS $$ SELECT me*me; $$; - """ - ) + """) elasticapm_client.begin_transaction("test") await cursor.callproc("squareme", [2]) result = await cursor.fetchall() diff --git a/tests/instrumentation/cassandra_tests.py b/tests/instrumentation/cassandra_tests.py index 7349206cc6..a18a4cbb3f 100644 --- a/tests/instrumentation/cassandra_tests.py +++ b/tests/instrumentation/cassandra_tests.py @@ -63,12 +63,10 @@ def cassandra_session(cassandra_cluster): session.execute("DROP KEYSPACE testkeyspace;") except ConfigurationException: pass - session.execute( - """ + session.execute(""" CREATE KEYSPACE testkeyspace WITH REPLICATION = { 'class' : 'SimpleStrategy' ,'replication_factor' : 1 } - """ - ) + """) session.execute("USE testkeyspace;") session.execute("CREATE TABLE testkeyspace.users ( id UUID PRIMARY KEY, name text);") yield session @@ -98,12 +96,10 @@ def test_cassandra_connect(instrument, elasticapm_client, cassandra_cluster): def test_cassandra_connect_keyspace(instrument, elasticapm_client, cassandra_cluster): session = cassandra_cluster.connect() try: - session.execute( - """ + session.execute(""" CREATE KEYSPACE testkeyspace WITH REPLICATION = { 'class' : 'SimpleStrategy' ,'replication_factor' : 1 } - """ - ) + """) elasticapm_client.begin_transaction("transaction.test") sess = cassandra_cluster.connect("testkeyspace") elasticapm_client.end_transaction("test") @@ -185,19 +181,14 @@ def test_signature_create_keyspace(): def test_signature_create_columnfamily(): - assert ( - extract_signature( - """CREATE COLUMNFAMILY users ( + assert extract_signature("""CREATE COLUMNFAMILY users ( userid text PRIMARY KEY, first_name text, last_name text, emails set, top_scores list, todo map -);""" - ) - == "CREATE COLUMNFAMILY" - ) +);""") == "CREATE COLUMNFAMILY" def test_select_from_collection(): diff --git a/tests/instrumentation/psycopg2_tests.py b/tests/instrumentation/psycopg2_tests.py index 1cee5b269c..a45aa4b8d1 100644 --- a/tests/instrumentation/psycopg2_tests.py +++ b/tests/instrumentation/psycopg2_tests.py @@ -447,16 +447,14 @@ def test_psycopg2_composable_query_works(instrument, postgres_connection, elasti @pytest.mark.skipif(not has_postgres_configured, reason="PostgresSQL not configured") def test_psycopg2_call_stored_procedure(instrument, postgres_connection, elasticapm_client): cursor = postgres_connection.cursor() - cursor.execute( - """ + cursor.execute(""" CREATE OR REPLACE FUNCTION squareme(me INT) RETURNS INTEGER LANGUAGE SQL AS $$ SELECT me*me; $$; - """ - ) + """) elasticapm_client.begin_transaction("test") cursor.callproc("squareme", [2]) result = cursor.fetchall()