Skip to content

Latest commit

 

History

History
1031 lines (791 loc) · 36.4 KB

configuration.asciidoc

File metadata and controls

1031 lines (791 loc) · 36.4 KB
Note
For the best reading experience, please view this documentation at elastic.co

Configuration

You can utilize configuration options to adapt the Elastic APM agent to your needs. There are multiple configuration sources, each with different naming conventions for the property key.

By default, the agent uses environment variables. Additionally, on ASP.NET Core, the agent can plug into the Microsoft.Extensions.Configuration infrastructure.

Dynamic configuration

Configuration options marked with the dynamic config badge can be changed at runtime when set from a supported source.

The .NET Agent supports {apm-app-ref}/agent-configuration.html[Central configuration], which allows you to fine-tune certain configurations via the APM app. This feature is enabled in the Agent by default, with CentralConfig (added[1.1]).

Configuration on ASP.NET Core

The UseElasticApm() extension method offers an overload to pass an IConfiguration instance to the APM Agent. To use this type of setup, which is typical in an ASP.NET Core application, your application’s Startup.cs file should contain code similar to the following:

using Elastic.Apm.AspNetCore;

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        //Registers the agent with an IConfiguration instance:
        app.UseElasticApm(Configuration);

        //Rest of the Configure() method...
    }
}

With this setup, the Agent is able to be configured in the same way as any other library in your application. For example, any configuration source that has been configured on the IConfiguration instance being passed to the APM Agent can be used to set Agent configuration values.

More information is available in the official Microsoft .NET Core configuration docs You can find the key for each APM configuration option in this documentation, under the IConfiguration or Web.config key column of the option’s description.

Note
It is also possible to call UseElasticApm() without the overload. In this case, the agent will only read configurations from environment variables.
Note
The UseElasticApm method only turns on ASP.NET Core monitoring. To turn on tracing for everything supported by the Agent on .NET Core, including HTTP and database monitoring, use the UseAllElasticApm method from the Elastic.Apm NetCoreAll package. Learn more in ASP.NET Core setup.

Sample configuration file

Here is a sample appsettings.json configuration file for a typical ASP.NET Core application that has been activated with UseElasticApm(). There are two important takeaways, which are listed as callouts below the example:

{
  "Logging": {
    "LogLevel": { (1)
      "Default": "Warning",
      "Elastic.Apm": "Debug"
    }
  },
  "AllowedHosts": "*",
  "ElasticApm": (2)
    {
      "ServerUrl":  "http://myapmserver:8200",
      "SecretToken":  "apm-server-secret-token",
      "TransactionSampleRate": 1.0
    }
}
  1. With ASP.NET Core, you must set LogLevel for the internal APM logger in the standard Logging section with the Elastic.Apm category name.

  2. The configurations below ElasticApm are fetched by the agent if the corresponding IConfiguration is passed to the agent.

In certain scenarios—​like when you’re not using ASP.NET Core—​you won’t activate the agent with the UseElasticApm() method. In this case, you can set the agent’s log level with ElasticApm:LogLevel, as shown in the following appsettings.json file:

{
  "Logging": {
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "AllowedHosts": "*",
  "ElasticApm":
    {
      "LogLevel":  "Debug",
      "ServerUrl":  "http://myapmserver:8200",
      "SecretToken":  "apm-server-secret-token",
      "TransactionSampleRate": 1.0
    }
}

Configuration on ASP.NET

When monitoring ASP.NET applications the agent uses two source of configuration: Web.config and environment variables. Web.config has precedence over environment variables which means that the agent first tries to find a configuration option value by its key in Web.config. Only if it’s not present then the agent tries to look for it among environment variables and if it’s not present there as well the agent falls back on the option’s default value.

You can find the key of each configuration option in the IConfiguration or Web.config key column of the corresponding option’s description.

Sample configuration file

Below is a sample Web.config configuration file for a ASP.NET application.

<?xml version="1.0" encoding="utf-8"?>
<!-- ... -->
<configuration>
    <!-- ... -->
    <appSettings>
        <!-- ... -->
        <add key="ElasticApm:ServerUrl" value="https://my-apm-server:8200" />
        <add key="ElasticApm:SecretToken" value="apm-server-secret-token" />
        <!-- ... -->
    </appSettings>
    <!-- ... -->
</configuration>

Additionally, on ASP.NET, you can implement your own configuration reader. To do this, implement the IConfigurationReader interface from the Elastic.Apm.Config namespace. Once implemented, you can make use of the FullFrameworkConfigurationReaderType setting.

FullFrameworkConfigurationReaderType

This setting is .NET Full Framework only.

With this setting you can point an agent to a custom IConfigurationReader implementation and the agent will read configuration from your IConfigurationReader implementation.

Use type name in AssemblyQualifiedName format (e.g: MyClass, MyNamespace).

Environment variable name Web.config key

ELASTIC_APM_FULL_FRAMEWORK_CONFIGURATION_READER_TYPE

ElasticApm:FullFrameworkConfigurationReaderType

Default Type

None

String

If this setting is set in both the web.config file and as an environment variable, then the web.config file has precedence.

Core configuration options

Recording (added[1.7.0])

A boolean specifying if the agent should be recording or not. When recording, the agent captures HTTP requests, tracks errors, and collects and sends metrics. When not recording, the agent works as a noop, not collecting data and not communicating with the APM server, except for polling the central configuration endpoint. As this is a reversible switch, agent threads are not being killed when inactivated, but they will be mostly idle in this state, so the overhead should be negligible.

You can use this setting to dynamically disable Elastic APM at runtime.

Environment variable name IConfiguration or Web.config key

ELASTIC_APM_RECORDING

ElasticApm:Recording

Default Type

true

Boolean

Enabled (added[1.7.0])

Setting to false will completely disable the agent, including instrumentation and remote config polling. If you want to dynamically change the status of the agent, use recording instead.

Environment variable name IConfiguration or Web.config key

ELASTIC_APM_ENABLED

ElasticApm:Enabled

Default Type

true

Boolean

ServiceName

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. Characters in service name which don’t match regular expression will be replaced by symbol.
Environment variable name IConfiguration or Web.config key

ELASTIC_APM_SERVICE_NAME

ElasticApm:ServiceName

Default Type

Name of the entry assembly

String

ServiceNodeName (added[1.3])

Optional name used to differentiate between nodes in a service. If not set, data aggregations will be done based on a container ID (where valid) or on the reported hostname (automatically discovered).

Note
This feature requires APM Server versions >= 7.5
Environment variable name IConfiguration or Web.config key

ELASTIC_APM_SERVICE_NODE_NAME

ElasticApm:ServiceNodeName

Default Type

<none>

String

ServiceVersion

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.

Environment variable name IConfiguration or Web.config key

ELASTIC_APM_SERVICE_VERSION

ElasticApm:ServiceVersion

Default Type

Informational version of the entry assembly

String

HostName (added[1.7])

Allows for the reported hostname to be manually specified. If unset, the hostname will be looked up.

Environment variable name IConfiguration or Web.config key

ELASTIC_APM_HOSTNAME

ElasticApm:HostName

Default Type

<none>

String

Environment (added[1.1])

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

Environments allow you to easily filter data on a global level in the APM app. It’s important to be consistent when naming environments across agents. See {apm-app-ref}/filters.html#environment-selector[environment selector] in the Kibana UI for more information.

Note
This feature is fully supported in the APM app in Kibana versions >= 7.2. You must use the query bar to filter for a specific environment in versions prior to 7.2.
Environment variable name IConfiguration or Web.config key

ELASTIC_APM_ENVIRONMENT

ElasticApm:Environment

Default Type

See note below

String

Note
On ASP.NET Core application the agent uses EnvironmentName from IHostingEnvironment as default environment name.

TransactionSampleRate

By default, the agent will sample every transaction (e.g. a 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. The agent will still record the overall time and result for unsampled transactions, but no context information, labels, or spans will be recorded.

Note
When parsing the value for this option, the agent doesn’t consider the current culture. It also expects that a period (.) is used to separate the integer and the fraction of a floating-point number.

This setting can be changed after agent’s start.

Environment variable name IConfiguration or Web.config key

ELASTIC_APM_TRANSACTION_SAMPLE_RATE

ElasticApm:TransactionSampleRate

Default Type

1.0

Double

TransactionMaxSpans (performance) (added[1.1.1])

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, for example, thousands of SQL queries. Setting an upper limit helps prevent overloading the Agent and APM server in these edge cases.

Note
A value of 0 means that spans will never be collected. Setting -1 means that spans will never be dropped. The Agent will revert to the default value if the value is set below -1.

This setting can be changed after agent’s start.

Environment variable name IConfiguration key

ELASTIC_APM_TRANSACTION_MAX_SPANS

ElasticApm:TransactionMaxSpans

Default Type

500

Integer

CentralConfig (added[1.1])

If set to true, the agent makes periodic requests to the APM Server to fetch the latest {apm-app-ref}/agent-configuration.html[APM Agent configuration].

Environment variable name IConfiguration key

ELASTIC_APM_CENTRAL_CONFIG

ElasticApm:CentralConfig

Default Type

true

Boolean

SanitizeFieldNames (added[1.2])

Sometimes it is necessary to sanitize, i.e., remove, sensitive data sent to Elastic APM. This config accepts a list of wildcard patterns of field names which should be sanitized. These apply for example to HTTP headers and application/x-www-form-urlencoded data.

Important
This setting only applies to values that are captured automatically by the agent. If you capture the request body manually with the public API, this configuration doesn’t apply, and the agent won’t sanitize the body.

The wildcard, , matches zero or more characters, and matching is case insensitive by default. Prepending an element with (?-i) makes the matching case sensitive. Examples: /foo//bar//baz, foo.

You should review the data captured by Elastic APM carefully to make sure it does not contain sensitive information. If you do find sensitive data in your Elasticsearch index, you should add an additional entry to this list. Make sure to include the default entries as well, as setting a value here will overwrite the defaults.

Note
Data in the query string is considered non-sensitive, as sensitive information should not be sent in the query string. See owasp.org for more information.
Environment variable name IConfiguration key

ELASTIC_APM_SANITIZE_FIELD_NAMES

ElasticApm:SanitizeFieldNames

Default Type

password, passwd, pwd, secret, key, *token, session, credit, card, authorization, set-cookie

List<string>

GlobalLabels (added[1.2])

Labels added to all events, with the format key=value[,key=value[,…​]]. Any labels set by the application via the agent’s public API will override global labels with the same keys.

Environment variable name IConfiguration key

ELASTIC_APM_GLOBAL_LABELS

ElasticApm:GlobalLabels

Default Type

<empty map>

Map of string to string

Note
This option requires APM Server 7.2 or later. It will have no effect on older versions.

Reporter configuration options

ServerUrl

Environment variable name IConfiguration or Web.config key

ELASTIC_APM_SERVER_URL

ElasticApm:ServerUrl

Default Type

http://localhost:8200

String

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

Important
Use of ServerUrls is deprecated. Use ServerUrl.

SecretToken

Environment variable name IConfiguration or Web.config key

ELASTIC_APM_SECRET_TOKEN

ElasticApm:SecretToken

Default Type

<none>

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. Use this setting in case the APM Server requires a token (e.g. APM Server in Elastic Cloud).

Warning
the SecretToken is sent as plain-text in every request to the server, so you should also secure your communications using HTTPS. Unless you do so, your API Key could be observed by an attacker.

ApiKey (added[1.4])

Environment variable name IConfiguration or Web.config key

ELASTIC_APM_API_KEY

ElasticApm:ApiKey

Default Type

<none>

A base64-encoded string

This base64-encoded string is used to ensure that only your agents can send data to your APM server. You must have created the API key using the APM server’s {apm-server-ref-v}/api-key.html[command line tool].

Note
This feature is fully supported in the APM Server versions >= 7.6.
Warning
the APIKey is sent as plain-text in every request to the server, so you should also secure your communications using HTTPS. Unless you do so, your API Key could be observed by an attacker.

VerifyServerCert (added[1.3])

Environment variable name IConfiguration or Web.config key

ELASTIC_APM_VERIFY_SERVER_CERT

ElasticApm:VerifyServerCert

Default Type

true

Boolean

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.

FlushInterval (added[1.1])

Environment variable name IConfiguration or Web.config key

ELASTIC_APM_FLUSH_INTERVAL

ElasticApm:FlushInterval

Default Type

10s

TimeDuration

The maximal amount of time events are held in the queue until there is enough to send a batch. It’s possible for a batch to contain less than MaxBatchEventCount events if there are events that need to be sent out because they were held for too long. 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.

Supports the duration suffixes ms, s and m. Example: 30s. The default unit for this option is s.

If FlushInterval is set to 0 (or 0s, 0ms, etc.) and there’s no event sending operation still in progress then the Agent won’t hold events in the queue and instead will send them immediately.

Setting FlushInterval to a negative value (for example -1, -54s, -89ms, etc.) is invalid and in that case agent uses the default value instead.

MaxBatchEventCount (added[1.1])

Environment variable name IConfiguration or Web.config key

ELASTIC_APM_MAX_BATCH_EVENT_COUNT

ElasticApm:MaxBatchEventCount

Default Type

10

Integer

The maximal number of events to send in a batch. It’s possible for a batch to contain less then the maximum events if there are events that need to be sent out because they were held for too long (see FlushInterval).

Setting MaxBatchEventCount to 0 or a negative value is invalid and in that case the Agent will use the default value instead.

MaxQueueEventCount (added[1.1])

Environment variable name IConfiguration or Web.config key

ELASTIC_APM_MAX_QUEUE_EVENT_COUNT

ElasticApm:MaxQueueEventCount

Default Type

1000

Integer

The maximal number of events to hold in the queue as candidates to be sent. If the queue is at its maximum capacity then the agent discards the new events until the queue has free space.

Setting MaxQueueEventCount to 0 or a negative value is invalid and in that case the Agent will use the default value instead.

MetricsInterval (added[1.0.0-beta1])

The interval at which the agent sends metrics to the APM Server. Must be at least 1s. Set to 0s to deactivate.

Supports the duration suffixes ms, s and m. Example: 30s. The default unit for this option is s.

Default Type

30s

TimeDuration

Environment variable name IConfiguration or Web.config key

ELASTIC_APM_METRICS_INTERVAL

ElasticApm:MetricsInterval

DisableMetrics (added[1.3.0])

Disables the collection of certain metrics. If the name of a metric matches any of the wildcard expressions, it will not be collected. Example: foo.,bar.

You can find the name of the available metrics in [metrics].

This option supports the wildcard , which matches zero or more characters. Examples: /foo//bar//baz, foo. Matching is case insensitive by default. Prepending an element with (?-i) makes the matching case sensitive.

Default Type

<none>

List<string>

Environment variable name IConfiguration or Web.config key

ELASTIC_APM_DISABLE_METRICS

ElasticApm:DisableMetrics

CloudProvider (added[1.7.0])

Allows you to specify which cloud provider should be assumed for metadata collection. By default, the agent will attempt to detect the cloud provider and, if that fails, use trial and error to collect the metadata.

Valid options are "auto", "aws", "gcp", "azure", and "none". If this config value is set to "none", no cloud metadata will be collected. If set to any of "aws", "gcp", or "azure", attempts to collect metadata will only be performed from the chosen provider.

Environment variable name IConfiguration or Web.config key

ELASTIC_APM_CLOUD_PROVIDER

ElasticApm:CloudProvider

Default Type

auto

String

HTTP configuration options

CaptureBody (performance) (added[1.0.1])

For transactions that are HTTP requests, the agent can optionally capture the request body, e.g., POST variables. If the request has a body and this setting is disabled, the body will be shown as [REDACTED]. This option is case-insensitive.

Important

To allow capturing request bodies, the agent sets AllowSynchronousIO to true on a per request basis in ASP.NET Core, since capturing can occur in synchronous code paths.

With ASP.NET Core 3.0 onwards, AllowSynchronousIO is false by default because a large number of blocking synchronous I/O operations can lead to thread pool starvation, which makes the application unresponsive. If your application becomes unresponsive with this feature enabled, consider disabling capturing.

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. Turning on body capturing can also significantly increase the overhead in terms of heap usage, network utilization, and Elasticsearch index size.

Possible options are off, errors, transactions and all:

  • off - request bodies will never be reported

  • errors - request bodies will only be reported with errors

  • transactions - request bodies will only be reported with request transactions

  • all - request bodies will be reported with both errors and request transactions

This setting can be changed after agent’s start.

Environment variable name IConfiguration or Web.config key

ELASTIC_APM_CAPTURE_BODY

ElasticApm:CaptureBody

Default Type

off

String

CaptureBodyContentTypes (performance) (added[1.0.1])

Configures which content types should be captured.

This option supports the wildcard , which matches zero or more characters. Examples: /foo//bar//baz, foo. Matching is case insensitive.

This setting can be changed after agent’s start.

Environment variable name IConfiguration or Web.config key

ELASTIC_APM_CAPTURE_BODY_CONTENT_TYPES

ElasticApm:CaptureBodyContentTypes

Default Type

application/x-www-form-urlencoded*, text/, application/json, application/xml*

List<string>

CaptureHeaders (performance)

Environment variable name IConfiguration or Web.config key

ELASTIC_APM_CAPTURE_HEADERS

ElasticApm:CaptureHeaders

Default Type

true

Boolean

If set to true, the agent will capture request and response headers, including cookies.

Note
Setting this to false reduces memory allocations, network bandwidth and disk space used by Elasticsearch.

TransactionIgnoreUrls (performance)

Environment variable name IConfiguration or Web.config key

ELASTIC_APM_TRANSACTION_IGNORE_URLS

ElasticApm:TransactionIgnoreUrls

Default Type

/VAADIN/, /heartbeat, /favicon.ico", *.js", *.css", *.jpg", *.jpeg", *.png", *.gif", *.webp", *.svg", *.woff", *.woff2

List<string>

Used to restrict requests to certain URLs from being instrumented.

This property should be set to a list containing one or more strings. When an incoming HTTP request is detected, its request path will be tested against each element in this list. For example, adding /home/index to this list would match and remove instrumentation from the following URLs:

https://www.mycoolsite.com/home/index
http://localhost/home/index
http://whatever.com/home/index?value1=123

This option supports the wildcard , which matches zero or more characters. Examples: /foo//bar//baz, foo. Matching is case insensitive by default. Prepending an element with (?-i) makes the matching case sensitive.

Note
All errors that are captured during a request to an ignored URL are still sent to the APM Server regardless of this setting.

UseElasticTraceparentHeader (added[1.3.0])

Environment variable name IConfiguration or Web.config key

ELASTIC_APM_USE_ELASTIC_TRACEPARENT_HEADER

ElasticApm:UseElasticTraceparentHeder

Default Type

true

Boolean

To enable {apm-overview-ref-v}/distributed-tracing.html[distributed tracing], the agent adds trace context headers to outgoing HTTP requests made with the HttpClient type. These headers (traceparent and tracestate) are defined in the W3C Trace Context specification.

When this setting is true, the agent will also add the header elasticapm-traceparent for backwards compatibility with older versions of Elastic APM agents. Versions prior to 1.3.0 only read the elasticapm-traceparent header.

Stacktrace configuration options

ApplicationNamespaces (added[1.5])

Used to determine whether a stack trace frame is an in-app frame or a library frame. When defined, all namespaces that do not start with one of the values of this collection are ignored when determining error culprit.

Multiple namespaces can be configured as a comma separated list. For example: "MyAppA, MyAppB".

This suppresses any configuration of ExcludedNamespaces.

Default Type

<empty string>

String

Environment variable name IConfiguration or Web.config key

ELASTIC_APM_APPLICATION_NAMESPACES

ElasticApm:ApplicationNamespaces

ExcludedNamespaces (added[1.5])

A list of namespaces to exclude when reading an exception’s StackTrace to determine the culprit.

Namespaces are checked with string.StartsWith(), so "System." matches all System namespaces.

Default Type

"System., Microsoft., MS., FSharp., Newtonsoft.Json, Serilog, NLog, Giraffe."

String

Environment variable name IConfiguration or Web.config key

ELASTIC_APM_EXCLUDED_NAMESPACES

ElasticApm:ExcludedNamespaces

StackTraceLimit (performance)

Setting it to 0 will disable stack trace collection. Any positive integer value will be used as the maximum number of frames to collect. Setting it to -1 means that all frames will be collected.

Default Type

50

Integer

Environment variable name IConfiguration or Web.config key

ELASTIC_APM_STACK_TRACE_LIMIT

ElasticApm:StackTraceLimit

SpanFramesMinDuration (performance)

In its default settings, the APM agent collects a stack trace for every recorded span with duration longer than 5ms. 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. When setting this option to a negative value, like -1ms, stack traces will be collected for all spans. Setting it to a positive value, e.g. 5ms, will limit stack trace collection to spans with durations equal to or longer than the given value, e.g. 5 milliseconds.

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

Supports the duration suffixes ms, s and m. Example: 5ms. The default unit for this option is ms

Default Type

5ms

TimeDuration

Environment variable name IConfiguration or Web.config key

ELASTIC_APM_SPAN_FRAMES_MIN_DURATION

ElasticApm:SpanFramesMinDuration

Supportability configuration options

LogLevel

Environment variable name IConfiguration or Web.config key

ELASTIC_APM_LOG_LEVEL

ElasticApm:LogLevel

Default Type

Error

String

Sets the logging level for the agent.

Valid options: Critical, Error, Warning, Info, Debug, Trace and None (None disables the logging).

Important
The UseElasticApm() extension offers an overload to pass an IConfiguration instance to the agent. When configuring your agent in this way, as is typical in an ASP.NET Core application, you must instead set the LogLevel for the internal APM logger under the Logging section of appsettings.json. More details, including a sample configuration file are available in Configuration on ASP.NET Core.

All options summary

Option name dynamic config Keywords

ApiKey

No

Reporter

ApplicationNamespaces

No

Stacktrace

CaptureBody

Yes

HTTP, Performance

CaptureBodyContentTypes

Yes

HTTP, Performance

CaptureHeaders

No

HTTP, Performance

CentralConfig

No

Core

CloudProvider

No

Reporter

DisableMetrics

No

Reporter

Environment

No

Core

Enabled

No

Core

ExcludedNamespaces

No

Stacktrace

FlushInterval

No

Reporter

GlobalLabels

No

Core

HostName

No

Core

LogLevel

No

Supportability

MaxBatchEventCount

No

Reporter

MaxQueueEventCount

No

Reporter

MetricsInterval

No

Reporter

Recording

Yes

Core

SanitizeFieldNames

No

Core

SecretToken

No

Reporter

ServerUrl

No

Reporter

ServiceName

No

Core

ServiceNodeName

No

Core

ServiceVersion

No

Core

SpanFramesMinDuration

No

Stacktrace, Performance

StackTraceLimit

No

Stacktrace, Performance

TransactionIgnoreUrls

No

HTTP, Performance

TransactionMaxSpans

Yes

Core, Performance

TransactionSampleRate

Yes

Core, Performance

UseElasticTraceparentHeader

No

HTTP

VerifyServerCert

No

Reporter