• /
  • Log in
  • Free account

.NET agent configuration

You'll be able to configure our .NET agent to suit your environnment after you create a New Relic account (it's free, forever) and install the .NET agent.

Configuration overview

APM agent configuration options allow you to control some aspects of how the agent behaves. Some of these config options are part of the basic install process (like setting your license key and app name), but most are more advanced settings, such as setting a log level, setting up proxy host access, excluding certain attributes, and enabling distributed tracing.

The .NET agent gets its configuration from the newrelic.config file, which is generated as part of the install process. By default, only a global newrelic.config file is created, but you can also create app-local newrelic.config files for finer control over a multi-app system. Other ways to set config options include: using environment variables, or setting server-side configuration from the UI. For more on the various config options and what overrides what, see Config settings precedence.

Support for both .NET Framework and .NET Core use the same configuration options and have the same APM features, unless otherwise stated.

If you make changes to the config file and want to validate that it's in the right format, you can check it against the XSD file (for example, at C:\ProgramData\New Relic\.NET Agent\newrelic.xsd for Windows) with any XSD validator.

Important

For IIS: after you change your newrelic.config or app.config file, perform an IISRESET from an administrative command prompt. Log level adjustments do not require a reset.

Configuration methods and precedence levels

Upon installation, the .NET agent's configuration file (newrelic.config) applies to all monitored applications, but you can configure the agent in other ways. Here's a diagram showing how different configuration options take precedence over one another:

New Relic .NET agent configuration settings precedence

This diagram explains the order of precedence for different ways you might configure the .NET agent.

Here are details about the configuration methods shown in the diagram, and their precedence levels:

.NET configuration

Details and precedence

web.config or app.config or appsettings.json

Configuration settings set in these files take highest precedence.

However, if the agent is disabled in the local or global newrelic.config, the NewRelic.AgentEnabled settings in these files will be ignored.

Environment variables

Second-highest precedence. For more about these, see .NET environment variables.

Server-side configuration

Third-highest precedence. A limited number of server-side configuration settings are available; the other settings will come from other configuration sources.

App-local newrelic.config

Fourth-highest precedence. You can create app-local newrelic.config files to configure individual apps on a multi-app system. These local configuration files override settings in the global newrelic.config file.

The agent looks for app-local config files in the following directories, in this order:

  • A directory specified in your web.config or app.config file with the NewRelic.ConfigFile property

  • The web app's root directory (with the app.config or web.config)

  • The directory containing your app's executable file

    Note that the app-local config file must be complete and validate against the XSD file (for example, at C:\ProgramData\New Relic\.NET Agent\newrelic.xsd for Windows).

Default (global) newrelic.config

Default source and the lowest precedence. Will configure all applications on a host in the absence of other config files. The global config file is located in the New Relic agent home directory: %PROGRAMDATA%\New Relic\.NET Agent

Required environment variables

New Relic's .NET agent relies on environment variables to tell the .NET Common Language Runtime (CLR) to attach New Relic to your processes. Some .NET agent install procedures (like the MSI installer) will automatically set these variables for you; some procedures will require you to manually set them.

Caution

Security recommendation: You should consider what users can set system environment variables. You should also secure the accounts under which your applications execute to prevent user environment variables overriding system environment variables

If your system has previously used monitoring services (non-New Relic), you may have a "profiler conflict" when trying to install and use the New Relic agent. More details:

For specific install instructions, see the .NET agent install documentation.

Optional environment variables

Some configuration options in New Relic's .NET agent can be set via environment variables as an alternative to setting them in a config file. Below is a list of environment variables recognized by the .NET agent with example values.

NEW_RELIC_LICENSE_KEY=XXXXXXXX
NEW_RELIC_LOG=MyApp.log
NEW_RELIC_APP_NAME=Descriptive Name
MAX_TRANSACTION_SAMPLES_STORED=500
MAX_EVENT_SAMPLES_STORED=500
NEW_RELIC_DISTRIBUTED_TRACING_ENABLED=true
NEW_RELIC_SPAN_EVENTS_ENABLED=false
NEW_RELIC_SPAN_EVENTS_MAX_SAMPLES_STORED=2000
NEW_RELIC_LABELS=foo:bar;zip:zap
NEW_RELIC_CONFIG_OBSCURING_KEY=XXXXXXXX
NEW_RELIC_DISABLE_SAMPLERS=true
NEWRELIC_PROFILER_LOG_DIRECTORY=path\to\a\directory (not configurable via config file)
NEWRELIC_LOG_DIRECTORY=path\to\a\directory (Insert a directory where you want to put the agent and profiler logs. You can't set this directory for both agent and profiler logs in the configuration file.)
NEWRELIC_LOG_LEVEL=off|error|warn|info|debug|finest|all

Setup options, newrelic.config

Use these options to setup and configure your agent via the newrelic.config file. The New Relic .NET agent supports the following categories of setup options:

Configuration element

The root element of the configuration document is a configuration element.

<configuration xmlns="urn:newrelic-config"
agentEnabled="true"
maxStackTraceLines="50"
timingPrecision="low">

The configuration element supports the following attributes:

Service element

The first child of the configuration element is a service element. The service element configures the agent's connection to the New Relic service.

<service licenseKey="YOUR_LICENSE_KEY"
  sendEnvironmentInfo="true"
  syncStartup="false"
  sendDataOnExit="false"
  sendDataOnExitThreshold="60000"
  autoStart="true"/>

The service element supports the following attributes:

Obscuring key element

The obscuringKey element is an optional child of the service element. The .NET Agent uses this value to deobfuscate supported configuration values. For example, when an obfuscated proxy password is supplied, it will be deobfuscated using this key.

<service licenseKey="YOUR_LICENSE_KEY">
    <obscuringKey>OBSCURING_KEY</obscuringKey>
</service>

The obscuring key may also be configured by setting the NEW_RELIC_CONFIG_OBSCURING_KEY environment variable.

Caution

Security recommendation: The placement of the obscuring Key in the same configuration file as an obfuscated value may pose a security risk. Consider placing the obscuring key in an environment variable and limiting access to environment variables within your environment.

Proxy element

The proxy element is an optional child of the service element. The proxy element is used when the agent communicates to the New Relic back-end service via a proxy.

<service licenseKey="YOUR_LICENSE_KEY">
 <proxy
   host="hostname"
   port="PROXY_PORT"
   uriPath="path/to/something.aspx"
   domain="mydomain.com"
   user="PROXY_USERNAME"
   password="PROXY_PASSWORD"
   passwordObfuscated="OBFUSCATED_PROXY_PASSWORD"/>
</service>

The proxy element supports the following attributes:

Log element

The log element is a child of the configuration element. The log element configures New Relic's logging . The agent generates its own log file to keep its logging information separate from your application's logs.

<log level="info"
  auditLog="false"
  console="false"
  directory="PATH\TO\LOG\DIRECTORY"
  fileName="FILENAME.log" />

The log element supports the following attributes:

Application element (required)

The application element is a child of the configuration element. This required element defines your application name, and disables or enables sampling.

Data transmission element

The dataTransmission element is a child of the configuration element. This element affects how data is sent to New Relic and can be used if you have specific data transmission requirements.

<dataTransmission
putForDataSend="false"
compressedContentEncoding="deflate"/>

The dataTransmission element supports the following attributes:

Host name

If the default host name label in the APM UI is not useful, you can decorate that name in the New Relic UI with a display name. After the application process is restarted and the .NET agent is reporting again, the display name will appear in the Servers drop-down list. This host name setting does not affect the list of hosts on your application's Summary page.

crop-cosmetic-label-hostname.png

To set a display name, choose one of the following options. The environment variable takes precedence over the config file value. Then restart your application to see your changes in the New Relic UI.

Cloud platform utilization

Configures the utilization configuration element to control how the agent collects utilization information and sends it to the New Relic service to determine pricing. The agent can collect information from Amazon Web Services (AWS) EC2 instances, Docker containers, Azure, Google Cloud Platform, Pivotal Cloud Foundry, and Kubernetes.

Instrumentation options

Use these options to configure which elements of your application and environment to instrument. New Relic for .NET supports the following categories of instrumentation options:

Instrumentation element

The instrumentation element is a child of the configuration element. By default, the .NET agent instruments IIS asp worker processes and Azure web and worker roles. To instrument other processes, see Instrumenting custom applications.

Applications element (instrumentation)

The applications element is a child of the instrumentation element. The applications element specifies which non-web apps to instrument. It contains a name attribute.

Important

This is not the same as the application (configuration) element, which is a child of the configuration element.

<instrumentation>
  <applications>
    <application name="MyService1.exe" />
    <application name="MyService2.exe" />
    <application name="MyService3.exe" />
  </applications>
</instrumentation>

Attributes element

An attribute is a key/value pair that determines the properties of an event or transaction. Each attribute is sent to APM transaction traces, APM error traces, Transaction events, TransactionError events, or PageView events. The primary attributes element enables or disables attribute collection for the .NET agent, and defines specific attributes to collect or exclude. You can also configure attribute settings based on their destination: Error collection, transaction traces, browser instrumentation, and transaction events.

In this example, the agent excludes all attributes whose key begins with myApiKey (myApiKey.bar, myApiKey.value), but collects the custom attribute myApiKey.foo.

<attributes enabled="true">
  <exclude>myApiKey.*</exclude>
  <include>myApiKey.foo</include>
</attributes>

You can view the .NET APM attributes on the .NET agent attributes page. You can also define custom attributes with the agent API call AddCustomAttribute.

Feature options

Use these options to enable, disable, and configure New Relic features. New Relic for .NET allows you to configure the following features:

App pools

Important

This is only applicable to a system's global config file.

The applicationPools element is a child of the configuration element. The applicationPools element specifies for the profiler exactly which application pools to instrument and uses the same name as the IIS application pool name. This configuration element is useful when you may need to instrument only a small subset of your app pools. For example, a given server might have several hundred application pools, but only a few of those pools need to be instrumented by the .NET agent.

Here is an example of disabling instrumentation for specific application pools:

<applicationPools>
  <applicationPool name="Foo" instrument="false"/>
  <applicationPool name="Bar" instrument="false"/>
</applicationPools>

Here is an example of disabling instrumentation for all application pools currently executing on the server and enabling instrumentation for specific application pools:

<applicationPools>
  <defaultBehavior instrument="false"/>
  <applicationPool name="Foo" instrument="true"/>
  <applicationPool name="Bar" instrument="true"/>
</applicationPools>

The applicationPools element supports the following elements:

Cross application traces

The crossApplicationTracer element is a child of the configuration element. crossApplicationTracer links transaction traces across applications. When linked in a service-oriented architecture, all instrumented applications that communicate with each other via HTTP will now "link" transaction traces with the applications that they call and the applications they are called by. Cross application tracing makes it easier to understand the performance relationship between services and applications.

<crossApplicationTracer enabled="true"/>

The crossApplicationTracer element supports the following attribute:

Error collection

The errorCollector element is a child of the configuration element. errorCollector configures error collection, which captures information about uncaught exceptions and sends them to New Relic.

<errorCollector enabled="true" captureEvents="true" maxEventSamplesStored="100">
  <ignoreClasses>
    <errorClass>System.IO.FileNotFoundException</errorClass>
    <errorClass>System.Threading.ThreadAbortException</errorClass>
  </ignoreClasses>
  <ignoreMessages>
    <errorClass name="System.Exception">
       <message>Ignore message</message>
       <message>Ignore too</message>
    </errorClass>
  </ignoreMessages>
  <ignoreStatusCodes>
    <code>401</code>
    <code>404</code>
  </ignoreStatusCodes>
  <expectedClasses>
    <errorClass>System.ArgumentNullException</errorClass>
    <errorClass>System.ArgumentOutOfRangeException</errorClass>
  </expectedClasses>
  <expectedMessages>
    <errorClass name="System.Exception">
       <message>Expected message</message>
       <message>Expected too</message>
    </errorClass>
  </expectedMessages>
  <expectedStatusCodes>403,500-505</expectedStatusCodes>
  <attributes enabled="true">
    <exclude>myApiKey.*</exclude>
    <include>myApiKey.foo</include>
  </attributes>
</errorCollector>

Tip

For an overview of error configuration in APM, see Manage errors in APM.

Important

expectedClasses, expectedMessages, and expectedStatusCodes configuration settings require .NET agent version 8.31.0.0 or higher.

The errorCollector element supports the following elements and attributes:

High security mode

The highSecurity element is a child of the configuration element. To enable high security mode, set this property to true and enable the high security property in the New Relic user interface. Enabling high security turns SSL on; request parameters, custom parameters and HTTP request headers are not collected; strip exception messages is enabled; and queries can't be sent to New Relic in their raw form.

Strip exception messages

The stripExceptionMessages element is a child of the configuration element. To enable strip exception messages, set this property to true. By default, this is set to false, which means that the agent sends messages from all exceptions to the New Relic collector. If you enable high security mode, this is automatically changed to true, and the agent strips the messages from exceptions.

Transaction events

The transactionEvents element is a child of the configuration element. Use transactionEvents to configure transaction events.

<transactionEvents enabled="true"
  maximumSamplesStored="10000">
 <attributes enabled="true">
    <exclude>myApiKey.*</exclude>
    <include>myApiKey.foo</include>
  </attributes>
</transactionEvents>

The transactionEvents element supports the following attributes:

Custom events

The customEvents element is a child of the configuration element. Use customEvents to configure custom events.

<customEvents enabled="true" maximumSamplesStored="10000"/>

The CustomEvents element supports the following attributes:

Custom parameters

The customParameters element is a child of the configuration element. Use customParameters to configure custom parameters.

<customParameters enabled="true" />

The CustomParameters element supports the following attributes:

Labels (tags)

The labels element is a child of the configuration element.

This sets tag names and values. The list is a semicolon delimited list of colon-separated name and value pairs. You can also use with the NEW_RELIC_LABELS environment variable. Example:

<labels>foo:bar;zip:zap</labels>

Browser instrumentation

The browserMonitoring element is a child of the configuration element. browserMonitoring configures browser monitoring in your .NET application. Browser gives you insight your end users' performance experience. This is accomplished by measuring the time it takes for your users' browsers to download and render your webpages by injecting a small amount of JavaScript code into the header and footer of each page.

// If you use both the Exclude and Attribute elements
// the Exclude element must be listed first.
<browserMonitoring autoInstrument="true">
  <requestPathsExcluded>
    <path regex="url-regex-1"/>
    <path regex="url-regex-2"/>
    ...
    <path regex="url-regex-n"/>
  </requestPathsExcluded>
  <attributes enabled="true">
    <exclude>myApiKey.*</exclude>
    <include>myApiKey.foo</include>
  </attributes>
</browserMonitoring>

The browserMonitoring element supports the following attributes:

Slow queries

The slowSql element is a child of the configuration element. slowSql configures capturing information about slow query executions, and captures and obfuscates explain plans for these queries.

<slowSql enabled="true"/>

The slowSql element supports the following attribute:

Transaction traces

The transactionTracer element is a child of the configuration element. transactionTracer configures transaction traces. Included in the trace is the exact call sequence of the transactions, including any query statements issued.

<transactionTracer enabled="true"
    transactionThreshold="apdex_f"
    recordSql="obfuscated"
    explainEnabled="true"
    explainThreshold="500"
    maxSegments="3000"
    maxExplainPlans="20">
  <attributes enabled="true">
    <exclude>myApiKey.*</exclude>
    <include>myApiKey.foo</include>
  </attributes>
 </transactionTracer>

The transactionTracer element supports the following attributes:

Datastore tracer

The datastoreTracer element is a child of the configuration element.

<datastoreTracer>
<instanceReporting enabled="true" />
<databaseNameReporting enabled="true" />
<queryParameters enabled="false" />
</datastoreTracer>

The datastoreTracer element supports the following sub-elements:

Distributed tracing

The distributedTracing element is a child of the configuration element.

<distributedTracing enabled="false"
excludeNewrelicHeader="false"/>

Distributed tracing lets you see the path that a request takes as it travels through a distributed system. Enabling distributed tracing disables cross application tracing, and has other effects on APM features. Before enabling, read the planning guide.

The distributedTracing element supports the following attributes:

To enable or disable, see Enable distributed tracing.

Distributed tracing reports span events. Span event reporting is enabled by default, but distributed tracing must be enabled for spans to be reported. To disable span events, choose one of the following options:

Infinite Tracing

Infinite Tracing extends the distributed tracing service by employing a trace observer that is external to the agent. It observes 100% of your application traces across various services and provides actionable data so you can solve issues faster.

Important

Infinite Tracing requires .NET Agent version 8.30 or higher.

To turn on Infinite Tracing, enable distributed tracing and add the additional settings below

<configuration . . . >
   <distributedTracing enabled="true" />
   <infiniteTracing>
      <trace_observer host="YOUR_TRACE_OBSERVER_HOST" />
   </infiniteTracing>
</configuration>

The infiniteTracing element supports the following elements:

Span events

The spanEvents element is a child of the configuration element. Use spanEvents to configure span events.

<spanEvents enabled="true">
 <attributes enabled="true">
    <exclude>myApiKey.*</exclude>
    <include>myApiKey.foo</include>
  </attributes>
</spanEvents>

The spanEvents element supports the following attributes:

Capture HTTP Request Headers

The allowAllHeaders element is a child of the configuration element. Set this to true to allow the .NET Agent to capture all HTTP request headers as request.headers.{http-header-name} attributes. Set this to false to only allow the .NET agent to collect the following HTTP request headers:

request.headers.referer
request.headers.accept
request.headers.content-length
request.headers.host
request.headers.user-agent

Important

The allowAllHeaders setting is only available in the .NET Agent version 8.40.0+. When using allowAllHeaders to capture attributes, the captured request header attributes are still being controlled by the root level and destination level attributes settings. Without setting the request.header.* in the include list under the attributes element (see the following), the .NET Agent still filters out all header attributes. The default newrelic.config is set to include the request.header.*.

<allowAllHeaders enabled="true" />
<attributes enabled="true">
<include>request.headers.*</include>
...
</attributes>

The default newrelic.config is also set to explicitly exclude the following HTTP request headers to prevent the .NET Agent collecting unwanted data.

<attributes enabled="true">
<exclude>request.headers.cookie</exclude>
<exclude>request.headers.authorization</exclude>
<exclude>request.headers.proxy-authorization</exclude>
<exclude>request.headers.x-*</exclude>
</attributes>

Settings in app.config or web.config

For ASP.NET and .NET Framework console apps you can also configure the following settings in your app's app.config or web.config, within the outermost element, <configuration>:

Settings in appsettings.json

For .NET Core apps, you can configure the following settings in appsettings.json if the following is true:

For more help

If you need more help, check out these support and learning resources:

Create issueEdit page
Copyright © 2021 New Relic Inc.