Skip to content

Commit d256f2a

Browse files
committed
remaned several settings to align closer to other language agents (#145)
* removed `collect_source` setting, it is replaced by more fine grained * settings * renamed setting `disable_instrumentation` to `instrument` and inverted * meaning * remove `keyword_max_length` setting and hard-code it * renamed `max_event_queue_length` to `max_queue_size` * renamed source line settings variables * renamed `timeout` to `server_timeout` * renamed `transaction_send_frequency` to `flush_interval` closes #145
1 parent 12ca52b commit d256f2a

File tree

19 files changed

+154
-196
lines changed

19 files changed

+154
-196
lines changed

CHANGELOG.asciidoc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ https://github.com/elastic/apm-agent-python/compare/v1.0.0\...master[Check the H
2525
* switched to `time.perf_counter` as timing function on Python 3 ({pull}138[#138])
2626
* BREAKING: Several settings and APIs have been renamed ({pull}111[#111], {pull}119[#119], {pull}143[#143]):
2727
** The decorator for custom instrumentation, `elasticapm.trace`, is now `elasticapm.capture_span`
28-
** The setting `traces_send_frequency` has been renamed to `transaction_send_frequency`.
28+
** The setting `traces_send_frequency` has been renamed to `flush_interval`.
2929
The name of the analogous environment variable changed from `ELASTIC_APM_TRACES_SEND_FREQ`
30-
to `ELASTIC_APM_TRANSACTION_SEND_FREQ`
30+
to `ELASTIC_APM_FLUSH_INTERVAL`
3131
** The `app_name` setting has been renamed to `service_name`.
3232
The name of the analogous environment variable changed from `ELASTIC_APM_APP_NAME`
3333
to `ELASTIC_APM_SERVICE_NAME`.
@@ -39,6 +39,11 @@ https://github.com/elastic/apm-agent-python/compare/v1.0.0\...master[Check the H
3939
* BREAKING: added `elasticapm.set_custom_context` in favor of the more generic `set_custom_data` function ({pull}133[#133])
4040
* BREAKING: `include_patterns` and `exclude_patterns` now use shell globs instead of regular expressions, and
4141
are matched against the full path file path of the module, not against the module name ({pull}137[#137])
42+
* BREAKING: renamed several configuration options to align better with other language agents ({pull}145[#145]):
43+
** `disable_instrumentation` became `instrument` and inverted its meaning
44+
** `max_event_queue_length` became `max_queue_size`
45+
** `timeout` became `server_timeout`
46+
4247

4348
[[release-1.0.0]]
4449
[float]

docs/configuration.asciidoc

Lines changed: 35 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,13 @@ Transactions that match any of the of the configured patterns will be ignored an
195195

196196

197197
[float]
198-
[[config-timeout]]
199-
==== `timeout`
198+
[[config-server-timeout]]
199+
==== `server_timeout`
200200

201201
[options="header"]
202202
|============
203-
| Environment | Django/Flask | Default
204-
| `ELASTIC_APM_TIMEOUT` | `TIMEOUT` | `5`
203+
| Environment | Django/Flask | Default
204+
| `ELASTIC_APM_SERVER_TIMEOUT` | `SERVER_TIMEOUT` | `5`
205205
|============
206206

207207
A timeout in seconds.
@@ -255,7 +255,7 @@ logger.info('something happened', extra={'stack': False})
255255
| `ELASTIC_APM_COLLECT_LOCAL_VARIABLES` | `COLLECT_LOCAL_VARIABLES` | `errors`
256256
|============
257257

258-
Possible values: `errors`, `transactions`, `all`, `none`
258+
Possible values: `errors`, `transactions`, `all`, `off`
259259

260260
The Elastic APM Python agent can collect local variables for stack frames.
261261
By default, this is only done for errors.
@@ -288,42 +288,26 @@ With this setting, you can limit the length of resulting string.
288288

289289
With this setting, you can limit the length of lists in local variables.
290290

291-
[float]
292-
[[config-collect-source]]
293-
==== `collect_source`
294-
295-
|============
296-
| Environment | Django/Flask | Default
297-
| `ELASTIC_APM_COLLECT_SOURCE` | `COLLECT_SOURCE` | `all`
298-
|============
299-
300-
Possible values: `errors`, `transactions`, `all`, `none`
301-
302-
The Elastic APM Python agent can collect source code for stack frames.
303-
304-
NOTE: collecting the source code for frames has a non-trivial overhead.
305-
If you notice a performance impact when running Elastic APM, changing
306-
this setting to `errors` can help.
307291

308292
[float]
309-
[[config-source_lines_app_frames_errors]]
310-
==== `source_lines_app_frames_errors`
293+
[[config-source-lines-error-app-frames]]
294+
==== `source_lines_error_app_frames`
311295
[float]
312-
[[config-source_lines_app_frames_transactions]]
313-
==== `source_lines_app_frames_transactions`
296+
[[config-source-lines-span-app-frames]]
297+
==== `source_lines_span_app_frames`
314298
[float]
315-
[[config-source_lines_library_frames_errors]]
316-
==== `source_lines_library_frames_errors`
299+
[[config-source-lines-error-library-frames]]
300+
==== `source_lines_error_library_frames`
317301
[float]
318-
[[config-source_lines_library_frames_transactions]]
319-
==== `source_lines_library_frames_transactions`
302+
[[config-source-lines-span-library-frames]]
303+
==== `source_lines_span_library_frames`
320304

321305
|============
322-
| Environment | Django/Flask | Default
323-
| `ELASTIC_APM_SOURCE_LINES_APP_FRAMES_ERRORS` | `SOURCE_LINES_APP_FRAMES_ERRORS` | `5`
324-
| `ELASTIC_APM_SOURCE_LINES_APP_FRAMES_TRANSACTIONS` | `SOURCE_LINES_APP_FRAMES_TRANSACTIONS` | `5`
325-
| `ELASTIC_APM_SOURCE_LINES_LIBRARY_FRAMES_ERRORS` | `SOURCE_LINES_LIBRARY_FRAMES_ERRORS` | `5`
326-
| `ELASTIC_APM_SOURCE_LINES_LIBRARY_FRAMES_TRANSACTIONS` | `SOURCE_LINES_LIBRARY_FRAMES_TRANSACTIONS` | `0`
306+
| Environment | Django/Flask | Default
307+
| `ELASTIC_APM_SOURCE_LINES_ERROR_APP_FRAMES` | `SOURCE_LINES_ERROR_APP_FRAMES` | `5`
308+
| `ELASTIC_APM_SOURCE_LINES_SPAN_APP_FRAMES` | `SOURCE_LINES_SPAN_APP_FRAMES` | `5`
309+
| `ELASTIC_APM_SOURCE_LINES_ERROR_LIBRARY_FRAMES` | `SOURCE_LINES_ERROR_LIBRARY_FRAMES` | `5`
310+
| `ELASTIC_APM_SOURCE_LINES_SPAN_LIBRARY_FRAMES` | `SOURCE_LINES_SPAN_LIBRARY_FRAMES` | `0`
327311
|============
328312

329313
By default, the APM agent collects source code snippets for
@@ -332,20 +316,21 @@ By default, the APM agent collects source code snippets for
332316
* transaction spans, only for in-app frames.
333317

334318
With the above settings, you can modify how many lines of source code is collected.
335-
Note however that especially for transactions, collecting source code can have a large impact on storage use in your Elasticsearch cluster.
319+
320+
WARNING: Especially for transactions, collecting source code can have a large impact on storage use in your Elasticsearch cluster.
336321

337322
[float]
338-
[[config-transaction-send-frequency]]
339-
==== `transaction_send_frequency`
323+
[[config-flush-interval]]
324+
==== `flush_interval`
340325

341326
|============
342-
| Environment | Django/Flask | Default
343-
| `ELASTIC_APM_TRANSACTION_SEND_FREQ` | `TRANSACTION_SEND_FREQ` | `60`
327+
| Environment | Django/Flask | Default
328+
| `ELASTIC_APM_FLUSH_INTERVAL` | `FLUSH_INTERVAL` | `60`
344329
|============
345330

346331
Interval with which transactions should be sent to the APM server, in seconds.
347332
A lower value will increase the load on your APM server,
348-
while a higher value can increase the memory pressure of your app.
333+
while a higher value can increase the memory pressure on your app.
349334
A higher value also impacts the time until transactions are indexed and searchable in Elasticsearch.
350335

351336

@@ -364,12 +349,12 @@ Setting an upper limit will prevent overloading the agent and the APM server wit
364349

365350

366351
[float]
367-
[[config-max-event-queue-length]]
368-
==== `max_event_queue_length`
352+
[[config-max-queue-size]]
353+
==== `max_queue_size`
369354

370355
|============
371-
| Environment | Django/Flask | Default
372-
| `ELASTIC_APM_MAX_EVENT_QUEUE_LENGTH` | `MAX_EVENT_QUEUE_LENGTH` | `500`
356+
| Environment | Django/Flask | Default
357+
| `ELASTIC_APM_MAX_EVENT_QUEUE_LENGTH` | `MAX_QUEUE_SIZE` | `500`
373358
|============
374359

375360
Maximum queue length of transactions before sending transactions to the APM server.
@@ -462,22 +447,22 @@ If set to `True`, the agent won't send any events to the APM server, independent
462447

463448

464449
[float]
465-
[[config-disable-instrumentation]]
466-
==== `disable_instrumentation`
450+
[[config-instrument]]
451+
==== `instrument`
467452
|============
468-
| Environment | Django/Flask | Default
469-
| `ELASTIC_APM_DISABLE_INSTRUMENTATION` | `DISABLE_INSTRUMENTATION` | `False`
453+
| Environment | Django/Flask | Default
454+
| `ELASTIC_APM_INSTRUMENT` | `INSTRUMENT` | `True`
470455
|============
471456

472-
If set to `True`, the agent won't instrument any code.
457+
If set to `False`, the agent won't instrument any code.
473458
This disables most of the tracing functionality, but can be useful to debug possible instrumentation issues.
474459

475460

476461
[float]
477462
[[config-verify-server-cert]]
478463
==== `verify_server_cert`
479464
|============
480-
| Environment | Django/Flask | Default
465+
| Environment | Django/Flask | Default
481466
| `ELASTIC_APM_VERIFY_SERVER_CERT` | `VERIFY_SERVER_CERT` | `True`
482467
|============
483468

elasticapm/base.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,20 +130,19 @@ def __init__(self, config=None, **defaults):
130130
self.instrumentation_store = TransactionsStore(
131131
lambda: self._get_stack_info_for_trace(
132132
stacks.iter_stack_frames(),
133-
with_source_context=self.config.collect_source in ('all', 'transactions'),
134-
library_frame_context_lines=self.config.source_lines_library_frames_transactions,
135-
in_app_frame_context_lines=self.config.source_lines_app_frames_transactions,
133+
library_frame_context_lines=self.config.source_lines_span_library_frames,
134+
in_app_frame_context_lines=self.config.source_lines_span_app_frames,
136135
with_locals=self.config.collect_local_variables in ('all', 'transactions'),
137136
locals_processor_func=lambda local_var: varmap(lambda k, v: shorten(
138137
v,
139138
list_length=self.config.local_var_list_max_length,
140139
string_length=self.config.local_var_max_length,
141140
), local_var)
142141
),
143-
collect_frequency=self.config.transaction_send_frequency,
142+
collect_frequency=self.config.flush_interval,
144143
sample_rate=self.config.transaction_sample_rate,
145144
max_spans=self.config.transaction_max_spans,
146-
max_queue_length=self.config.max_event_queue_length,
145+
max_queue_size=self.config.max_queue_size,
147146
ignore_patterns=self.config.transactions_ignore_patterns,
148147
)
149148
self.include_paths_re = stacks.get_path_regex(self.config.include_paths) if self.config.include_paths else None
@@ -245,7 +244,7 @@ def end_transaction(self, name, result=''):
245244
self._collect_transactions()
246245
if not self._send_timer:
247246
# send first batch of data after config._wait_to_first_send
248-
self._start_send_timer(timeout=min(self.config._wait_to_first_send, self.config.transaction_send_frequency))
247+
self._start_send_timer(timeout=min(self.config._wait_to_first_send, self.config.flush_interval))
249248
return transaction
250249

251250
def close(self):
@@ -302,7 +301,7 @@ def _collect_transactions(self):
302301
self._start_send_timer()
303302

304303
def _start_send_timer(self, timeout=None):
305-
timeout = timeout or self.config.transaction_send_frequency
304+
timeout = timeout or self.config.flush_interval
306305
self._send_timer = threading.Timer(timeout, self._collect_transactions)
307306
self._send_timer.start()
308307

@@ -323,7 +322,7 @@ def _send_remote(self, url, data, headers=None):
323322
fail_callback=self.handle_transport_fail
324323
)
325324
else:
326-
url = transport.send(data, headers, timeout=self.config.timeout)
325+
url = transport.send(data, headers, timeout=self.config.server_timeout)
327326
self.handle_transport_success(url=url)
328327

329328
def get_service_info(self):
@@ -429,10 +428,9 @@ def _build_msg_for_logging(self, event_type, date=None, context=None, custom=Non
429428
frames = stack
430429
frames = stacks.get_stack_info(
431430
frames,
432-
with_source_context=self.config.collect_source in ('errors', 'all'),
433431
with_locals=self.config.collect_local_variables in ('errors', 'all'),
434-
library_frame_context_lines=self.config.source_lines_library_frames_errors,
435-
in_app_frame_context_lines=self.config.source_lines_app_frames_errors,
432+
library_frame_context_lines=self.config.source_lines_error_library_frames,
433+
in_app_frame_context_lines=self.config.source_lines_error_app_frames,
436434
include_paths_re=self.include_paths_re,
437435
exclude_paths_re=self.exclude_paths_re,
438436
locals_processor_func=lambda local_var: varmap(lambda k, v: shorten(
@@ -530,15 +528,13 @@ def _get_transport(self, parsed_url):
530528
return self._transports[parsed_url]
531529

532530
def _get_stack_info_for_trace(self, frames,
533-
with_source_context=True,
534531
library_frame_context_lines=None,
535532
in_app_frame_context_lines=None,
536533
with_locals=True,
537534
locals_processor_func=None):
538535
"""Overrideable in derived clients to add frames/info, e.g. templates"""
539536
return stacks.get_stack_info(
540537
frames,
541-
with_source_context=with_source_context,
542538
library_frame_context_lines=library_frame_context_lines,
543539
in_app_frame_context_lines=in_app_frame_context_lines,
544540
with_locals=with_locals,

elasticapm/conf/__init__.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,9 @@ class Config(_ConfigBase):
142142
include_paths = _ListConfigValue('INCLUDE_PATHS')
143143
exclude_paths = _ListConfigValue('EXCLUDE_PATHS', default=compat.get_default_library_patters())
144144
filter_exception_types = _ListConfigValue('FILTER_EXCEPTION_TYPES')
145-
timeout = _ConfigValue('TIMEOUT', type=float, default=5)
145+
server_timeout = _ConfigValue('SERVER_TIMEOUT', type=float, default=5)
146146
hostname = _ConfigValue('HOSTNAME', default=socket.gethostname())
147147
auto_log_stacks = _BoolConfigValue('AUTO_LOG_STACKS', default=True)
148-
keyword_max_length = _ConfigValue('KEYWORD_MAX_LENGTH', type=int, default=1024)
149148
transport_class = _ConfigValue('TRANSPORT_CLASS', default='elasticapm.transport.http.AsyncTransport',
150149
required=True)
151150
processors = _ListConfigValue('PROCESSORS', default=[
@@ -156,17 +155,15 @@ class Config(_ConfigBase):
156155
'elasticapm.processors.sanitize_http_request_querystring',
157156
'elasticapm.processors.sanitize_http_request_body',
158157
])
159-
transaction_send_frequency = _ConfigValue('TRACES_SEND_FREQ', type=int, default=60)
158+
flush_interval = _ConfigValue('FLUSH_INTERVAL', type=int, default=60)
160159
transaction_sample_rate = _ConfigValue('TRANSACTION_SAMPLE_RATE', type=float, default=1.0)
161160
transaction_max_spans = _ConfigValue('TRANSACTION_MAX_SPANS', type=int, default=500)
162-
max_event_queue_length = _ConfigValue('MAX_EVENT_QUEUE_LENGTH', type=int, default=500)
161+
max_queue_size = _ConfigValue('MAX_QUEUE_SIZE', type=int, default=500)
163162
collect_local_variables = _ConfigValue('COLLECT_LOCAL_VARIABLES', default='errors')
164-
collect_source = _ConfigValue('COLLECT_SOURCE', default='all')
165-
source_lines_library_frames_errors = _ConfigValue('SOURCE_LINES_LIBRARY_FRAMES_ERRORS', type=int, default=5)
166-
source_lines_library_frames_transactions = _ConfigValue('SOURCE_LINES_LIBRARY_FRAMES_TRANSACTIONS', type=int,
167-
default=0)
168-
source_lines_app_frames_errors = _ConfigValue('SOURCE_LINES_APP_FRAMES_ERRORS', type=int, default=5)
169-
source_lines_app_frames_transactions = _ConfigValue('SOURCE_LINES_APP_FRAMES_TRANSACTIONS', type=int, default=5)
163+
source_lines_error_library_frames = _ConfigValue('SOURCE_LINES_ERROR_LIBRARY_FRAMES', type=int, default=5)
164+
source_lines_span_library_frames = _ConfigValue('SOURCE_LINES_SPAN_LIBRARY_FRAMES', type=int, default=0)
165+
source_lines_error_app_frames = _ConfigValue('SOURCE_LINES_ERROR_APP_FRAMES', type=int, default=5)
166+
source_lines_span_app_frames = _ConfigValue('SOURCE_LINES_SPAN_APP_FRAMES', type=int, default=5)
170167
local_var_max_length = _ConfigValue('LOCAL_VAR_MAX_LENGTH', type=int, default=200)
171168
local_var_list_max_length = _ConfigValue('LOCAL_VAR_LIST_MAX_LENGTH', type=int, default=10)
172169
async_mode = _BoolConfigValue('ASYNC_MODE', default=True)
@@ -176,7 +173,7 @@ class Config(_ConfigBase):
176173
framework_name = _ConfigValue('FRAMEWORK_NAME', default=None)
177174
framework_version = _ConfigValue('FRAMEWORK_VERSION', default=None)
178175
disable_send = _BoolConfigValue('DISABLE_SEND', default=False)
179-
disable_instrumentation = _BoolConfigValue('DISABLE_INSTRUMENTATION', default=False)
176+
instrument = _BoolConfigValue('DISABLE_INSTRUMENTATION', default=True)
180177

181178
# undocumented configuration
182179
_wait_to_first_send = _ConfigValue('_WAIT_TO_FIRST_SEND', type=int, default=5)

elasticapm/conf/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
TRANSACTIONS_API_PATH = '/v1/transactions'
66

77
TIMESTAMP_FORMAT = '%Y-%m-%dT%H:%M:%S.%fZ'
8+
9+
KEYWORD_MAX_LENGTH = 1024

elasticapm/contrib/asyncio/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ def _send_remote(self, url, data, headers=None):
2121
transport = self._get_transport(parsed)
2222
loop = asyncio.get_event_loop()
2323
task = loop.create_task(
24-
transport.send(data, headers, timeout=self.config.timeout))
24+
transport.send(data, headers, timeout=self.config.server_timeout))
2525
task.add_done_callback(self.handle_transport_response)
2626

2727
def _start_send_timer(self, timeout=None):
28-
timeout = timeout or self.config.transaction_send_frequency
28+
timeout = timeout or self.config.flush_interval
2929
self._send_timer = AsyncTimer(timeout, self._collect_transactions)
3030

3131
def _stop_send_timer(self):

elasticapm/contrib/django/apps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ def __init__(self, *args, **kwargs):
1717
def ready(self):
1818
self.client = get_client()
1919
register_handlers(self.client)
20-
if not self.client.config.disable_instrumentation:
20+
if self.client.config.instrument:
2121
instrument(self.client)
2222
else:
23-
self.client.logger.debug("Skipping instrumentation. DISABLE_INSTRUMENTATION is set.")
23+
self.client.logger.debug("Skipping instrumentation. INSTRUMENT is set to False.")
2424

2525

2626
def register_handlers(client):

elasticapm/contrib/django/client.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ def capture(self, event_type, request=None, **kwargs):
173173
return result
174174

175175
def _get_stack_info_for_trace(self, frames,
176-
with_source_context=True,
177176
library_frame_context_lines=None,
178177
in_app_frame_context_lines=None,
179178
with_locals=True,
@@ -182,7 +181,6 @@ def _get_stack_info_for_trace(self, frames,
182181
frames until some other module comes up."""
183182
frames = list(iterate_with_template_sources(
184183
frames,
185-
with_source_context=with_source_context,
186184
with_locals=with_locals,
187185
library_frame_context_lines=library_frame_context_lines,
188186
in_app_frame_context_lines=in_app_frame_context_lines,

elasticapm/contrib/django/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Template(object):
99
pass
1010

1111

12-
def iterate_with_template_sources(frames, with_source_context=True, with_locals=True,
12+
def iterate_with_template_sources(frames, with_locals=True,
1313
library_frame_context_lines=None, in_app_frame_context_lines=None,
1414
include_paths_re=None, exclude_paths_re=None, locals_processor_func=None):
1515
template = None
@@ -40,7 +40,6 @@ def iterate_with_template_sources(frames, with_source_context=True, with_locals=
4040

4141
yield get_frame_info(
4242
frame, lineno,
43-
with_source_context=with_source_context,
4443
library_frame_context_lines=library_frame_context_lines,
4544
in_app_frame_context_lines=in_app_frame_context_lines,
4645
with_locals=with_locals,

elasticapm/contrib/flask/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ def init_app(self, app, **defaults):
113113
pass
114114

115115
# Instrument to get spans
116-
if self.client.config.disable_instrumentation:
117-
logger.debug("Skipping instrumentation. DISABLE_INSTRUMENTATION is set.")
118-
else:
116+
if self.client.config.instrument:
119117
elasticapm.instrumentation.control.instrument()
120118

121119
signals.request_started.connect(self.request_started, sender=app)
@@ -125,6 +123,8 @@ def init_app(self, app, **defaults):
125123
register_instrumentation(self.client)
126124
except ImportError:
127125
pass
126+
else:
127+
logger.debug("Skipping instrumentation. INSTRUMENT is set to False.")
128128

129129
def request_started(self, app):
130130
if not (self.app.debug and not self.client.config.debug):

0 commit comments

Comments
 (0)