Note
|
For the best reading experience, please view this documentation at elastic.co |
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.
Configuration options marked with the 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]).
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.
|
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
}
}
-
With ASP.NET Core, you must set
LogLevel
for the internal APM logger in the standardLogging
section with theElastic.Apm
category name. -
The configurations below
ElasticApm
are fetched by the agent if the correspondingIConfiguration
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
}
}
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.
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.
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 |
---|---|
|
|
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.
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 |
---|---|
|
|
Default | Type |
---|---|
|
Boolean |
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 |
---|---|
|
|
Default | Type |
---|---|
|
Boolean |
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 |
---|---|
|
|
Default | Type |
---|---|
Name of the entry assembly |
String |
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 |
---|---|
|
|
Default | Type |
---|---|
|
String |
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 |
---|---|
|
|
Default | Type |
---|---|
Informational version of the entry assembly |
String |
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 |
---|---|
|
|
Default | Type |
---|---|
|
String |
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 |
---|---|
|
|
Default | Type |
---|---|
See note below |
String |
Note
|
On ASP.NET Core application the agent uses EnvironmentName from IHostingEnvironment as default environment name. |
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 |
---|---|
|
|
Default | Type |
---|---|
1.0 |
Double |
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 |
---|---|
|
|
Default | Type |
---|---|
|
Integer |
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 |
---|---|
|
|
Default | Type |
---|---|
true |
Boolean |
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 |
---|---|
|
|
Default | Type |
---|---|
|
List<string> |
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 |
---|---|
|
|
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. |
Environment variable name | IConfiguration or Web.config key |
---|---|
|
|
Default | Type |
---|---|
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 .
|
Environment variable name | IConfiguration or Web.config key |
---|---|
|
|
Default | Type |
---|---|
|
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.
|
Environment variable name | IConfiguration or Web.config key |
---|---|
|
|
Default | Type |
---|---|
|
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.
|
Environment variable name | IConfiguration or Web.config key |
---|---|
|
|
Default | Type |
---|---|
|
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.
Environment variable name | IConfiguration or Web.config key |
---|---|
|
|
Default | Type |
---|---|
|
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.
Environment variable name | IConfiguration or Web.config key |
---|---|
|
|
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.
Environment variable name | IConfiguration or Web.config key |
---|---|
|
|
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.
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 |
---|---|
|
TimeDuration |
Environment variable name | IConfiguration or Web.config key |
---|---|
|
|
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 |
---|---|
|
|
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 |
---|---|
|
|
Default | Type |
---|---|
|
String |
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 With ASP.NET Core 3.0 onwards, |
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 |
---|---|
|
|
Default | Type |
---|---|
|
String |
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 |
---|---|
|
|
Default | Type |
---|---|
|
List<string> |
Environment variable name | IConfiguration or Web.config key |
---|---|
|
|
Default | Type |
---|---|
|
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.
|
Environment variable name | IConfiguration or Web.config key |
---|---|
|
|
Default | Type |
---|---|
|
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. |
Environment variable name | IConfiguration or Web.config key |
---|---|
|
|
Default | Type |
---|---|
|
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.
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 |
---|---|
|
|
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 |
---|---|
|
|
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 |
---|---|
|
Integer |
Environment variable name | IConfiguration or Web.config key |
---|---|
|
|
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 |
---|---|
|
TimeDuration |
Environment variable name | IConfiguration or Web.config key |
---|---|
|
|
Environment variable name | IConfiguration or Web.config key |
---|---|
|
|
Default | Type |
---|---|
|
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.
|