Skip to content

Commit 39f4191

Browse files
authored
contrib/flask: remove deprecated log shipping integration (#2346)
* contrib/flask: remove deprecated log shipping integration * Fix tests
1 parent eb34e89 commit 39f4191

File tree

2 files changed

+2
-46
lines changed

2 files changed

+2
-46
lines changed

elasticapm/contrib/flask/__init__.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,15 @@
3131

3232
from __future__ import absolute_import
3333

34-
import logging
35-
import warnings
36-
3734
import flask
3835
from flask import request, signals
3936

4037
import elasticapm
4138
import elasticapm.instrumentation.control
4239
from elasticapm import get_client
4340
from elasticapm.base import Client
44-
from elasticapm.conf import constants, setup_logging
41+
from elasticapm.conf import constants
4542
from elasticapm.contrib.flask.utils import get_data_from_request, get_data_from_response
46-
from elasticapm.handlers.logging import LoggingHandler
4743
from elasticapm.traces import execution_context
4844
from elasticapm.utils import build_name_with_http_method_prefix
4945
from elasticapm.utils.disttracing import TraceParent
@@ -81,14 +77,8 @@ class ElasticAPM(object):
8177
>>> elasticapm.capture_message('hello, world!')
8278
"""
8379

84-
def __init__(self, app=None, client=None, client_cls=Client, logging=False, **defaults) -> None:
80+
def __init__(self, app=None, client=None, client_cls=Client, **defaults) -> None:
8581
self.app = app
86-
self.logging = logging
87-
if self.logging:
88-
warnings.warn(
89-
"Flask log shipping is deprecated. See the Flask docs for more info and alternatives.",
90-
DeprecationWarning,
91-
)
9282
self.client = client or get_client()
9383
self.client_cls = client_cls
9484

@@ -127,14 +117,6 @@ def init_app(self, app, **defaults) -> None:
127117

128118
self.client = self.client_cls(config, **defaults)
129119

130-
# 0 is a valid log level (NOTSET), so we need to check explicitly for it
131-
if self.logging or self.logging is logging.NOTSET:
132-
if self.logging is not True:
133-
kwargs = {"level": self.logging}
134-
else:
135-
kwargs = {}
136-
setup_logging(LoggingHandler(self.client, **kwargs))
137-
138120
signals.got_request_exception.connect(self.handle_exception, sender=app, weak=False)
139121

140122
try:

tests/contrib/flask/flask_tests.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -441,32 +441,6 @@ def test_rum_tracing_context_processor(flask_apm_client):
441441
assert callable(context["apm"]["span_id"])
442442

443443

444-
@pytest.mark.parametrize("flask_apm_client", [{"logging": True}], indirect=True)
445-
def test_logging_enabled(flask_apm_client):
446-
logger = logging.getLogger()
447-
logger.error("test")
448-
error = flask_apm_client.client.events[ERROR][0]
449-
assert error["log"]["level"] == "error"
450-
assert error["log"]["message"] == "test"
451-
452-
453-
@pytest.mark.parametrize("flask_apm_client", [{"logging": False}], indirect=True)
454-
def test_logging_disabled(flask_apm_client):
455-
logger = logging.getLogger()
456-
logger.error("test")
457-
assert len(flask_apm_client.client.events[ERROR]) == 0
458-
459-
460-
@pytest.mark.parametrize("flask_apm_client", [{"logging": logging.ERROR}], indirect=True)
461-
def test_logging_by_level(flask_apm_client):
462-
logger = logging.getLogger()
463-
logger.warning("test")
464-
logger.error("test")
465-
assert len(flask_apm_client.client.events[ERROR]) == 1
466-
error = flask_apm_client.client.events[ERROR][0]
467-
assert error["log"]["level"] == "error"
468-
469-
470444
def test_flask_transaction_ignore_urls(flask_apm_client):
471445
resp = flask_apm_client.app.test_client().get("/users/")
472446
resp.close()

0 commit comments

Comments
 (0)