Skip to content
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
22 changes: 2 additions & 20 deletions elasticapm/contrib/flask/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,15 @@

from __future__ import absolute_import

import logging
import warnings

import flask
from flask import request, signals

import elasticapm
import elasticapm.instrumentation.control
from elasticapm import get_client
from elasticapm.base import Client
from elasticapm.conf import constants, setup_logging
from elasticapm.conf import constants
from elasticapm.contrib.flask.utils import get_data_from_request, get_data_from_response
from elasticapm.handlers.logging import LoggingHandler
from elasticapm.traces import execution_context
from elasticapm.utils import build_name_with_http_method_prefix
from elasticapm.utils.disttracing import TraceParent
Expand Down Expand Up @@ -81,14 +77,8 @@ class ElasticAPM(object):
>>> elasticapm.capture_message('hello, world!')
"""

def __init__(self, app=None, client=None, client_cls=Client, logging=False, **defaults) -> None:
def __init__(self, app=None, client=None, client_cls=Client, **defaults) -> None:
self.app = app
self.logging = logging
if self.logging:
warnings.warn(
"Flask log shipping is deprecated. See the Flask docs for more info and alternatives.",
DeprecationWarning,
)
self.client = client or get_client()
self.client_cls = client_cls

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

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

# 0 is a valid log level (NOTSET), so we need to check explicitly for it
if self.logging or self.logging is logging.NOTSET:
if self.logging is not True:
kwargs = {"level": self.logging}
else:
kwargs = {}
setup_logging(LoggingHandler(self.client, **kwargs))

signals.got_request_exception.connect(self.handle_exception, sender=app, weak=False)

try:
Expand Down
26 changes: 0 additions & 26 deletions tests/contrib/flask/flask_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,32 +441,6 @@ def test_rum_tracing_context_processor(flask_apm_client):
assert callable(context["apm"]["span_id"])


@pytest.mark.parametrize("flask_apm_client", [{"logging": True}], indirect=True)
def test_logging_enabled(flask_apm_client):
logger = logging.getLogger()
logger.error("test")
error = flask_apm_client.client.events[ERROR][0]
assert error["log"]["level"] == "error"
assert error["log"]["message"] == "test"


@pytest.mark.parametrize("flask_apm_client", [{"logging": False}], indirect=True)
def test_logging_disabled(flask_apm_client):
logger = logging.getLogger()
logger.error("test")
assert len(flask_apm_client.client.events[ERROR]) == 0


@pytest.mark.parametrize("flask_apm_client", [{"logging": logging.ERROR}], indirect=True)
def test_logging_by_level(flask_apm_client):
logger = logging.getLogger()
logger.warning("test")
logger.error("test")
assert len(flask_apm_client.client.events[ERROR]) == 1
error = flask_apm_client.client.events[ERROR][0]
assert error["log"]["level"] == "error"


def test_flask_transaction_ignore_urls(flask_apm_client):
resp = flask_apm_client.app.test_client().get("/users/")
resp.close()
Expand Down
Loading