Configurationedit

To adapt the Elastic APM agent to your needs, you can configure it using environment variables, or framework specific configuration.

Djangoedit

To configure Django, add an ELASTIC_APM dictionary to your settings.py:

ELASTIC_APM = {
    'SERVICE_NAME': 'my-app',
    'SECRET_TOKEN': 'changeme',
}

Flaskedit

To configure Flask, add an ELASTIC_APM dictonary to your app.config:

app.config['ELASTIC_APM'] = {
    'SERVICE_NAME': 'my-app',
    'SECRET_TOKEN': 'changeme',
}

apm = ElasticAPM(app)

Required optionsedit

service_nameedit

Environment Django/Flask Default Example

ELASTIC_APM_SERVICE_NAME

SERVICE_NAME

None

my-app

The name of your service. This is used to keep all the errors and transactions of your service together and is the primary filter in the Elastic APM user interface.

Note

The service name must conform to this regular expression: ^[a-zA-Z0-9 _-]+$. In less regexy terms: Your service name must only contain characters from the ASCII alphabet, numbers, dashes, underscores and spaces.

server_urledit

Environment Django/Flask Default

ELASTIC_APM_SERVER_URL

SERVER_URL

'http://localhost:8200'

The URL for your APM Server. The URL must be fully qualified, including protocol (http or https) and port.

transport_classedit

Environment

Django/Flask

Default

ELASTIC_APM_TRANSPORT_CLASS

TRANSPORT_CLASS

elasticapm.transport.http.AsyncTransport

The transport class to use when sending events to the APM server. The default AsyncTransport uses a background thread to send data. If your environment doesn’t allow background threads, you can use elasticapm.transport.http.Transport instead. Note however that this can have adverse effects on performance.

Other optionsedit

environmentedit

Environment Django/Flask Default Example

ELASTIC_APM_ENVIRONMENT

ENVIRONMENT

None

"production"

The name of the environment this service is deployed in, e.g. "production" or "staging".

secret_tokenedit

Environment Django/Flask Default Example

ELASTIC_APM_SECRET_TOKEN

SECRET_TOKEN

None

A random string

This string is used to ensure that only your agents can send data to your APM server. Both the agents and the APM server have to be configured with the same secret token. One example to generate a secure secret token is:

python -c "import uuid; print(str(uuid.uuid4()))"
Warning

secret tokens only provide any security if your APM server use TLS.

service_versionedit

Environment Django/Flask Default Example

ELASTIC_APM_SERVICE_VERSION

SERVICE_VERSION

None

A string indicating the version of the deployed service

A version string for the currently deployed version of the service. If you don’t version your deployments, the recommended value for this field is the commit identifier of the deployed revision, e.g. the output of git rev-parse HEAD.

framework_nameedit

Environment Django/Flask Default

ELASTIC_APM_FRAMEWORK_NAME

FRAMEWORK_NAME

Depending on framework

Name of the used framework. For Django and Flask, this defaults to django and flask respectively, otherwise, the default is None.

framework_versionedit

Environment Django/Flask Default

ELASTIC_APM_FRAMEWORK_VERSION

FRAMEWORK_VERSION

Depending on framework

Version number of the used framework. For Django and Flask, this defaults to the used version of the framework, otherwise, the default is None.

filter_exception_typesedit

Environment Django/Flask Default Example

ELASTIC_APM_FILTER_EXCEPTION_TYPES

FILTER_EXCEPTION_TYPES

[]

['OperationalError', 'mymodule.SomeoneElsesProblemError']

multiple values separated by commas, without spaces

A list of exception types to be filtered. Exceptions of these types will not be sent to the APM server.

transactions_ignore_patternsedit

Environment Django/Flask Default Example

ELASTIC_APM_TRANSACTIONS_IGNORE_PATTERNS

TRANSACTIONS_IGNORE_PATTERNS

[]

['^OPTIONS ', 'myviews.Healthcheck']

multiple values separated by commas, without spaces

A list of regular expressions. Transactions that match any of the of the configured patterns will be ignored and not sent to the APM server.

server_timeoutedit

Environment Django/Flask Default

ELASTIC_APM_SERVER_TIMEOUT

SERVER_TIMEOUT

5

A timeout in seconds. If a request to the APM server takes longer than the configured timeout, the request is cancelled and the event (exception or transaction) is discarded. Set to None to disable timeouts.

Warning

If timeouts are disabled or set to a high value, your app could experience memory issues if the APM server times out.

hostnameedit

Environment Django/Flask Default Example

ELASTIC_APM_HOSTNAME

HOSTNAME

socket.gethostname()

app-server01.example.com

The host name to use when sending error and transaction data to the APM server.

auto_log_stacksedit

Environment Django/Flask Default

ELASTIC_APM_AUTO_LOG_STACKS

AUTO_LOG_STACKS

True

set to "true" / "false"

If set to True (the default), the agent will add a stack trace to each log event, indicating where the log message has been issued.

This setting can be overridden on an individual basis by setting the extra-key stack:

logger.info('something happened', extra={'stack': False})

collect_local_variablesedit

Environment

Django/Flask

Default

ELASTIC_APM_COLLECT_LOCAL_VARIABLES

COLLECT_LOCAL_VARIABLES

errors

Possible values: errors, transactions, all, off

The Elastic APM Python agent can collect local variables for stack frames. By default, this is only done for errors.

Note

collecting local variables has a non-trivial overhead. Collecting local variables for transactions in production environments can have adverse effects for the performance of your service.

local_var_max_lengthedit

Environment

Django/Flask

Default

ELASTIC_APM_LOCAL_VAR_MAX_LENGTH

LOCAL_VAR_MAX_LENGTH

200

When collecting local variables, they will be converted to strings. With this setting, you can limit the length of resulting string.

local_var_list_max_lengthedit

Environment

Django/Flask

Default

ELASTIC_APM_LOCAL_VAR_LIST_MAX_LENGTH

LOCAL_VAR_LIST_MAX_LENGTH

10

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

source_lines_error_app_framesedit

source_lines_error_library_framesedit

source_lines_span_app_framesedit

source_lines_span_library_framesedit

Environment

Django/Flask

Default

ELASTIC_APM_SOURCE_LINES_ERROR_APP_FRAMES

SOURCE_LINES_ERROR_APP_FRAMES

5

ELASTIC_APM_SOURCE_LINES_ERROR_LIBRARY_FRAMES

SOURCE_LINES_ERROR_LIBRARY_FRAMES

5

ELASTIC_APM_SOURCE_LINES_SPAN_APP_FRAMES

SOURCE_LINES_SPAN_APP_FRAMES

0

ELASTIC_APM_SOURCE_LINES_SPAN_LIBRARY_FRAMES

SOURCE_LINES_SPAN_LIBRARY_FRAMES

0

By default, the APM agent collects source code snippets for errors. With the above settings, you can modify how many lines of source code is collected.

We differ between errors and spans, as well as library frames and app frames.

Warning

Especially for spans, collecting source code can have a large impact on storage use in your Elasticsearch cluster.

capture_bodyedit

Environment

Django/Flask

Default

ELASTIC_APM_CAPTURE_BODY

CAPTURE_BODY

off

For transactions that are HTTP requests, the Python agent can optionally capture the request body (e.g. POST variables).

Possible values: errors, transactions, all, off.

If the request has a body and this setting is disabled, the body will be shown as [REDACTED].

For requests with a content type of multipart/form-data, any uploaded files will be referenced in a special _files key. It contains the name of the field, and the name of the uploaded file, if provided.

Warning

request bodies often contain sensitive values like passwords, credit card numbers etc. If your service handles data like this, we advise to only enable this feature with care.

flush_intervaledit

Environment

Django/Flask

Default

ELASTIC_APM_FLUSH_INTERVAL

FLUSH_INTERVAL

10

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

transaction_max_spansedit

Environment

Django/Flask

Default

ELASTIC_APM_TRANSACTION_MAX_SPANS

TRANSACTION_MAX_SPANS

500

Limits the amount of spans that are recorded per transaction. This is helpful in cases where a transaction creates a very high amount of spans (e.g. thousands of SQL queries). Setting an upper limit will prevent overloading the agent and the APM server with too much work for such edge cases.

span_frames_min_durationedit

Environment

Django/Flask

Default

ELASTIC_APM_SPAN_FRAMES_MIN_DURATION

SPAN_FRAMES_MIN_DURATION

-1

In its default settings, the APM agent will collect a stack trace with every recorded span. While this is very helpful to find the exact place in your code that causes the span, collecting this stack trace does have some overhead.

With the default setting, -1, stack traces will be collected for all spans. Setting it to a positive value, e.g. 5, will limit stack trace collection to spans with durations equal or longer than the given value in milliseconds, e.g. 5 milliseconds.

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

max_queue_sizeedit

Environment

Django/Flask

Default

ELASTIC_APM_MAX_QUEUE_SIZE

MAX_QUEUE_SIZE

500

Maximum queue length of transactions before sending transactions to the APM server. A lower value will increase the load on your APM server, while a higher value can increase the memory pressure of your app. A higher value also impacts the time until transactions are indexed and searchable in Elasticsearch.

This setting is useful to limit memory consumption if you experience a sudden spike of traffic.

processorsedit

Environment

Django/Flask

Default

ELASTIC_APM_PROCESSORS

PROCESSORS

['elasticapm.processors.sanitize_stacktrace_locals', 'elasticapm.processors.sanitize_http_request_cookies', 'elasticapm.processors.sanitize_http_headers', 'elasticapm.processors.sanitize_http_wsgi_env', 'elasticapm.processors.sanitize_http_request_querystring', 'elasticapm.processors.sanitize_http_request_body']

A list of processors to process transactions and errors. For more information, see Sanitizing Data.

Warning

We recommend to always include the default set of validators if you customize this setting.

transaction_sample_rateedit

Environment

Django/Flask

Default

ELASTIC_APM_TRANSACTION_SAMPLE_RATE

TRANSACTION_SAMPLE_RATE

1.0

By default, the agent will sample every transaction (e.g. request to your service). To reduce overhead and storage requirements, you can set the sample rate to a value between 0.0 and 1.0. We still record overall time and the result for unsampled transactions, but no context information, tags, or spans.

include_pathsedit

Environment

Django/Flask

Default

ELASTIC_APM_INCLUDE_PATHS

INCLUDE_PATHS

[]

multiple values separated by commas, without spaces

A set of paths, optionally using shell globs (see fnmatch for a description of the syntax). These are matched against the absolute filename of every frame, and if a pattern matches, the frame is considered to be an "in-app frame".

include_paths takes precedence over exclude_paths.

exclude_pathsedit

Environment

Django/Flask

Default

ELASTIC_APM_EXCLUDE_PATHS

EXCLUDE_PATHS

Varies on Python version and implementation

multiple values separated by commas, without spaces

A set of paths, optionally using shell globs (see fnmatch for a description of the syntax). These are matched against the absolute filename of every frame, and if a pattern matches, the frame is considered to be a "library frame".

include_paths takes precedence over exclude_paths.

The default value varies based on your Python version and implementation, e.g.:

  • PyPy3: ['\*/lib-python/3/*', '\*/site-packages/*']
  • CPython 2.7: ['\*/lib/python2.7/*', '\*/lib64/python2.7/*']

debugedit

Environment

Django/Flask

Default

ELASTIC_APM_DEBUG

DEBUG

False

If your app is in debug mode (e.g. in Django with settings.DEBUG = True or in Flask with app.debug = True), the agent won’t send any data to the APM server. You can override it by changing this setting to True.

disable_sendedit

Environment

Django/Flask

Default

ELASTIC_APM_DISABLE_SEND

DISABLE_SEND

False

If set to True, the agent won’t send any events to the APM server, independent of any debug state.

instrumentedit

Environment

Django/Flask

Default

ELASTIC_APM_INSTRUMENT

INSTRUMENT

True

If set to False, the agent won’t instrument any code. This disables most of the tracing functionality, but can be useful to debug possible instrumentation issues.

verify_server_certedit

Environment

Django/Flask

Default

ELASTIC_APM_VERIFY_SERVER_CERT

VERIFY_SERVER_CERT

True

By default, the agent verifies the SSL certificate if you use an HTTPS connection to the APM server. Verification can be disabled by changing this setting to False.

Note

SSL certificate verification is only available in Python 2.7.9+ and Python 3.4.3+.