Skip to content

Commit 8667eb9

Browse files
committed
Implemented the v2 API wire protocol (#281)
This implements the v2 API. The largest change is that the queue moved from `TransactionStore` to `Transport`, and that instead of queuing Python objects, it queues (by default compressed) lines of JSON. Another large conceptual change is that events (errors, transactions and spans) are immediately queued when they are finished. Architecturally, `elasticapm.base.Client` does only have one single method to interact with the transport layer, `queue()`, which in turn calls the transports `queue` method. `send`, `send_remote`, `encode` etc. are all removed.
1 parent bfebda0 commit 8667eb9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1534
-1559
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog
22

3+
## v4.0.0
4+
5+
**BREAKING** Version 4 of the agent implements a new wire protocol for communicating with
6+
the APM Server. This format is only supported in APM Server 6.5+.
7+
8+
Further breaking changes:
9+
10+
* the undocumented `AsyncioHTTPTransport` has been removed.
11+
* the `flush_interval` and `max_queue_size` settings have been removed.
12+
* new settings introduced: `api_request_time` and `api_request_size`.
13+
* Some settings now require a unit for duration or size. See documentation on
14+
configuration for more information.
15+
316
## v3.0.1
417

518
[Check the diff](https://github.com/elastic/apm-agent-python/compare/v3.0.0...v3.0.1)

docs/configuration.asciidoc

Lines changed: 74 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,11 @@ Transactions that match any of the of the configured patterns will be ignored an
230230
[options="header"]
231231
|============
232232
| Environment | Django/Flask | Default
233-
| `ELASTIC_APM_SERVER_TIMEOUT` | `SERVER_TIMEOUT` | `5`
233+
| `ELASTIC_APM_SERVER_TIMEOUT` | `SERVER_TIMEOUT` | `"5s"`
234234
|============
235235

236-
A timeout in seconds.
236+
A timeout for requests to the APM Server.
237+
The setting has to be provided in *<<config-format-duration, duration format>>*.
237238
If a request to the APM server takes longer than the configured timeout,
238239
the request is cancelled and the event (exception or transaction) is discarded.
239240
Set to `None` to disable timeouts.
@@ -369,21 +370,6 @@ It contains the name of the field, and the name of the uploaded file, if provide
369370
WARNING: request bodies often contain sensitive values like passwords, credit card numbers etc.
370371
If your service handles data like this, we advise to only enable this feature with care.
371372

372-
[float]
373-
[[config-flush-interval]]
374-
==== `flush_interval`
375-
376-
|============
377-
| Environment | Django/Flask | Default
378-
| `ELASTIC_APM_FLUSH_INTERVAL` | `FLUSH_INTERVAL` | `10`
379-
|============
380-
381-
Interval with which transactions should be sent to the APM server, in seconds.
382-
A lower value will increase the load on your APM server,
383-
while a higher value can increase the memory pressure on your app.
384-
A higher value also impacts the time until transactions are indexed and searchable in Elasticsearch.
385-
386-
387373
[float]
388374
[[config-transaction-max-spans]]
389375
==== `transaction_max_spans`
@@ -402,8 +388,8 @@ Setting an upper limit will prevent overloading the agent and the APM server wit
402388
==== `span_frames_min_duration`
403389

404390
|============
405-
| Environment | Django/Flask | Default
406-
| `ELASTIC_APM_SPAN_FRAMES_MIN_DURATION` | `SPAN_FRAMES_MIN_DURATION` | `5`
391+
| Environment | Django/Flask | Default
392+
| `ELASTIC_APM_SPAN_FRAMES_MIN_DURATION` | `SPAN_FRAMES_MIN_DURATION` | `"5ms"`
407393
|============
408394

409395
In its default settings, the APM agent will collect a stack trace with every recorded span.
@@ -416,21 +402,42 @@ with durations equal or longer than the given value in milliseconds, e.g. 5 mill
416402

417403
To disable stack trace collection for spans completely, set the value to `0`.
418404

405+
Except for the special values `-1` and `0`,
406+
this setting has to be provided in *<<config-format-duration, duration format>>*.
407+
419408
[float]
420-
[[config-max-queue-size]]
421-
==== `max_queue_size`
409+
[[config-api-request-size]]
410+
==== `api_request_size`
422411

423412
|============
424-
| Environment | Django/Flask | Default
425-
| `ELASTIC_APM_MAX_QUEUE_SIZE` | `MAX_QUEUE_SIZE` | `500`
413+
| Environment | Django/Flask | Default
414+
| `ELASTIC_APM_API_REQUEST_SIZE` | `API_REQUEST_TIME` | `"724kb"`
415+
|============
416+
417+
Maximum queue length of the request buffer before sending the request to the APM server.
418+
A lower value will increase the load on your APM server,
419+
while a higher value can increase the memory pressure of your app.
420+
A higher value also impacts the time until data is indexed and searchable in Elasticsearch.
421+
422+
This setting is useful to limit memory consumption if you experience a sudden spike of traffic.
423+
It has to be provided in *<<config-format-size, size format>>*.
424+
425+
[float]
426+
[[config-api-request-time]]
427+
==== `api_request_size`
428+
429+
|============
430+
| Environment | Django/Flask | Default
431+
| `ELASTIC_APM_API_REQUEST_SIZE` | `API_REQUEST_SIZE` | `"724kb"`
426432
|============
427433

428-
Maximum queue length of transactions before sending transactions to the APM server.
434+
Maximum queue time of the request buffer before sending the request to the APM server.
429435
A lower value will increase the load on your APM server,
430436
while a higher value can increase the memory pressure of your app.
431-
A higher value also impacts the time until transactions are indexed and searchable in Elasticsearch.
437+
A higher value also impacts the time until data is indexed and searchable in Elasticsearch.
432438

433439
This setting is useful to limit memory consumption if you experience a sudden spike of traffic.
440+
It has to be provided in *<<config-format-duration, duration format>>*.
434441

435442
[float]
436443
[[config-processors]]
@@ -551,3 +558,45 @@ By default, the agent verifies the SSL certificate if you use an HTTPS connectio
551558
Verification can be disabled by changing this setting to `False`.
552559

553560
NOTE: SSL certificate verification is only available in Python 2.7.9+ and Python 3.4.3+.
561+
562+
563+
[float]
564+
[[config-formats]]
565+
=== Configuration formats
566+
567+
Some options require a unit, either duration or size.
568+
These need to be provided in a specific format.
569+
570+
[float]
571+
[[config-format-duration]]
572+
==== Duration format
573+
574+
The _duration_ format is used for options like timeouts.
575+
The unit is provided as suffix directly after the number, without and separation by whitespace.
576+
577+
*Example*: `5ms`
578+
579+
*Supported units*
580+
581+
* `ms` (milliseconds)
582+
* `s` (seconds)
583+
* `m` (minutes)
584+
585+
[float]
586+
[[config-format-size]]
587+
==== Size format
588+
589+
The _size_ format is used for options like maximum buffer sizes.
590+
The unit is provided as suffix directly after the number, without and separation by whitespace.
591+
592+
593+
*Example*: `10kb`
594+
595+
*Supported units*:
596+
597+
* `b` (bytes)
598+
* `kb` (kilobytes)
599+
* `mb` (megabytes)
600+
* `gb` (gigabytes)
601+
602+
NOTE: we use the power-of-two sizing convention, e.g. `1 kilobyte == 1024 bytes`

docs/sanitizing-data.asciidoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,19 @@ This is an example of a processor that removes the exception stacktrace from an
1212

1313
[source,python]
1414
----
15+
from elasticapm.conf.constants import ERROR
16+
from elasticapm.processors import for_events
17+
18+
@for_events(ERROR)
1519
def my_processor(client, event):
1620
if 'exception' in event and 'stacktrace' in event['exception']:
1721
event['exception'].pop('stacktrace')
1822
return event
1923
----
2024

25+
You can use the `@for_events` decorator to limit for which event type the processor should be called.
26+
Possible choices are `ERROR`, `TRANSACTION`, and `SPAN`, all of which are defined in `elasticapm.conf.constants`.
27+
2128
To use this processor, update your `ELASTIC_APM` settings like this:
2229

2330
[source,python]

docs/tuning.asciidoc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ holding on to the transaction data in a queue uses memory.
4747
If you notice that using the Python agent results in a large increase of memory use,
4848
you can use these settings:
4949

50-
* <<config-flush-interval,`flush_interval`>> to reduce the time between queue flushes
51-
* <<config-max-queue-size,`max_queue_size`>> to reduce the maximum size of the queue
50+
* <<config-api-request-time,`api_request_time`>> to reduce the time between queue flushes
51+
* <<config-api-request-size,`api_request_size`>> to reduce the maximum size of the queue
5252

53-
The first setting, `flush_interval`, is helpful if you have a sustained high number of transactions.
54-
The second setting, `max_queue_size`, can help if you experience peaks of transactions
53+
The first setting, `api_request_time`, is helpful if you have a sustained high number of transactions.
54+
The second setting, `api_request_size`, can help if you experience peaks of transactions
5555
(a large amount of transactions in a short period of time).
5656

5757
Keep in mind that reducing the value of either setting will cause the agent to send more HTTP requests to the APM Server,
@@ -78,6 +78,6 @@ Another option to reduce overhead of collecting contextual data for spans is to
7878
While this contextual data (specifically, the stack trace) can be very useful to pinpoint where exectly the span is caused in your code,
7979
it is less interesting for very short spans.
8080
You can define a minimal threshold for span duration in milliseconds,
81-
using the <<config-span-frames-min-duration,`span_frames_min_duration_ms`>> setting.
81+
using the <<config-span-frames-min-duration,`span_frames_min_duration`>> setting.
8282
If a span takes less than this duration, no stack frames will be collected for this span.
8383
Other contextual information, like the SQL query, will still be available.

0 commit comments

Comments
 (0)