Skip to content

Commit 02b3248

Browse files
authored
Remove log shipping from Flask docs, start deprecation (#1918)
1 parent ead8d8b commit 02b3248

File tree

3 files changed

+22
-61
lines changed

3 files changed

+22
-61
lines changed

CHANGELOG.asciidoc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ endif::[]
3636
[float]
3737
===== Features
3838
39+
* Add Python 3.12 support
3940
* Collect the `configured_hostname` and `detected_hostname` separately, and switch to FQDN for the `detected_hostname`. {pull}1891[#1891]
4041
* Improve postgres dollar-quote detection to be much faster {pull}1905[#1905]
4142
@@ -45,7 +46,13 @@ endif::[]
4546
* Fix url argument fetching in aiohttp_client instrumentation {pull}1890[#1890]
4647
* Fix a bug in the AWS Lambda instrumentation when `event["headers"] is None` {pull}1907[#1907]
4748
* Fix a bug in AWS Lambda where metadata could be incomplete, causing validation errors with the APM Server {pull}1914[#1914]
48-
* Fix a bug in AWS Lambda where sending the partial transaction would be recorded as an extra span {pull}1914[#1914]
49+
* Fix a bug in AWS Lambda where sending the partial transaction would be
50+
recorded as an extra span {pull}1914[#1914]
51+
52+
[float]
53+
===== Pending Deprecations
54+
55+
* The log shipping feature in the Flask instrumentation will be removed in version 7.0.0 of the agent.
4956
5057
5158

docs/flask.asciidoc

Lines changed: 8 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -138,75 +138,27 @@ apm.capture_message('hello, world!')
138138
[[flask-logging]]
139139
==== Shipping Logs to Elasticsearch
140140

141-
Enable automatic log shipping by passing `logging=LEVEL` to the ElasticAPM
142-
constructor. The agent will then ship all log messages with the given
143-
log-level or higher, from Python's built-in `logging` module to
144-
Elasticsearch. `LEVEL` must be one of the levels defined in the
145-
https://docs.python.org/3/library/logging.html#logging-levels[`logging`]
146-
module.
141+
This feature has been deprecated and will be removed in a future version.
147142

148-
[source,python]
149-
----
150-
import logging
143+
Please see our <<logs,Logging>> documentation for other supported ways to ship
144+
logs to Elasticsearch.
151145

152-
from elasticapm.contrib.flask import ElasticAPM
153-
154-
apm = ElasticAPM(app, logging=logging.ERROR)
155-
----
156-
157-
To ship all log messages independent of log levels to Elastic APM, pass
158-
`logging=True` to the constructor:
146+
Note that you can always send exceptions and messages to the APM Server with
147+
<<client-api-capture-exception,`capture_exception`>> and and
148+
<<client-api-capture-message,`capture_message`>>.
159149

160150
[source,python]
161151
----
162-
from elasticapm.contrib.flask import ElasticAPM
163-
164-
apm = ElasticAPM(app, logging=True)
165-
----
166-
167-
NOTE: using `logging=True` can lead to high number of logs being sent to Elastic APM.
168-
We recommend to always limit logging with Elastic APM to a high level (`WARNING` or `ERROR`).
169-
For shipping of less urgent logs, we recommend to use {filebeat-ref}[filebeat].
170-
171-
For fine-grained control, you can initialize a logging handler and add it,
172-
just as you would with any other handler.
152+
from elasticapm import get_client
173153
174-
For information on how to increase the log verbosity from the APM agent, see
175-
<<agent-logging,troubleshooting agent logging>>.
176-
177-
[source,python]
178-
----
179-
from flask import Flask
180-
181-
from elasticapm.contrib.flask import ElasticAPM
182-
from elasticapm.handlers.logging import LoggingHandler
183-
184-
app = Flask(__name__)
185-
186-
apm = ElasticAPM(app)
187-
188-
if __name__ == '__main__':
189-
# Create a logging handler and attach it.
190-
handler = LoggingHandler(client=apm.client)
191-
handler.setLevel(logging.WARN)
192-
app.logger.addHandler(handler)
193-
----
194-
195-
You can also capture exceptions and send them explicitly:
196-
197-
[source,python]
198-
----
199154
@app.route('/')
200155
def bar():
201156
try:
202157
1 / 0
203158
except ZeroDivisionError:
204-
app.logger.error( 'I cannot math', exc_info=True)
159+
get_client().capture_exception()
205160
----
206161

207-
NOTE: `exc_info=True` adds the exception info to the data that gets sent to the APM Server.
208-
Without it, only the message is sent.
209-
210162
[float]
211163
[[flask-extra-data]]
212164
===== Extra data

elasticapm/contrib/flask/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from __future__ import absolute_import
3333

3434
import logging
35+
import warnings
3536

3637
import flask
3738
from flask import request, signals
@@ -68,10 +69,6 @@ class ElasticAPM(object):
6869
6970
>>> elasticapm = ElasticAPM(app, client=client)
7071
71-
Automatically configure logging::
72-
73-
>>> elasticapm = ElasticAPM(app, logging=True)
74-
7572
Capture an exception::
7673
7774
>>> try:
@@ -87,6 +84,11 @@ class ElasticAPM(object):
8784
def __init__(self, app=None, client=None, client_cls=Client, logging=False, **defaults) -> None:
8885
self.app = app
8986
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+
PendingDeprecationWarning,
91+
)
9092
self.client = client or get_client()
9193
self.client_cls = client_cls
9294

0 commit comments

Comments
 (0)