-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Improve configuration story * Update test assertion * Ensure we fallback to logging section and event listener respects value
- Loading branch information
1 parent
abf079c
commit 596bd9c
Showing
27 changed files
with
1,198 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
[[configuration]] | ||
== Configuration | ||
|
||
Configuration of the OpenTelemetry SDK should be performed through the | ||
mechanisms https://opentelemetry.io/docs/languages/net/automatic/configuration/[documented on the OpenTelemetry website]. | ||
|
||
The Elastic distribution can be further configured using advanced settings when | ||
you need complete control of its behaviour. Configuration can be achieved by setting environment variables, | ||
using the `IConfiguration` integration, or manually configuring the Elastic distribution. | ||
|
||
=== Environment variables | ||
|
||
The Elastic distribution can be configured using environment variables. This is a cross-platform | ||
way to configure the Elastic distribution and is especially useful in containerized environments. | ||
|
||
Environment variables are read at startup and can be used to configure the Elastic distribution. | ||
For details of the various options available and their corresponding environment variable names, | ||
see <<configuration-options>>. | ||
|
||
Environment variables always take precedence over configuration provided by the `IConfiguration` | ||
system. | ||
|
||
=== IConfiguration integration | ||
|
||
In applications that use the "host" pattern, such as ASP.NET Core and worker service, the Elastic | ||
distribution can be configured using the `IConfiguration` integration. This is done by passing an | ||
`IConfiguration` instance to the `AddElasticOpenTelemetry` extension method on the `IServiceCollection`. | ||
|
||
When using an `IHostApplicationBuilder` such as modern ASP.NET Core applications, the current `IConfiguration` | ||
can be accessed via the `Configuration` property on the builder. | ||
|
||
[source,csharp] | ||
---- | ||
var builder = WebApplication.CreateBuilder(args); | ||
var currentConfig = builder.Configuration; <1> | ||
---- | ||
<1> Access the current `IConfiguration` instance from the builder. | ||
|
||
By default, at this stage, the configuration will be populated from the default configuration sources, | ||
including the `appsettings.json` file(s) and command-line arguments. You may use these sources to define | ||
the configuration for the Elastic distribution. | ||
|
||
For example, you can define the configuration for the Elastic distribution in the `appsettings.json` file: | ||
|
||
[source,json] | ||
---- | ||
{ | ||
"Elastic": { | ||
"OpenTelemetry": { | ||
"FileLogDirectory": "C:\\Logs" <1> | ||
} | ||
} | ||
} | ||
---- | ||
<1> This example sets the file log directory to `C:\Logs` which enables diagnostic file logging. | ||
|
||
Configuration from the "Elastic:OpenTelemetry" section of the `IConfiguration` instance will be | ||
bound to the `ElasticOpenTelemetryOptions` instance used to configure the Elastic distribution. | ||
|
||
To learn more about the Microsoft configuration system, see | ||
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration[Configuration in ASP.NET Core]. | ||
|
||
=== Manual configuration | ||
|
||
In all other scenarios, configuration can be achieved manually in code. This is done by creating | ||
an instance of `ElasticOpenTelemetryBuilderOptions` and passing it to the `ElasticOpenTelemetryBuilder` constructor | ||
or an overload of the `AddElasticOpenTelemetry` extension method on the `IServiceCollection`. | ||
|
||
For example, in traditional console applications, you can configure the Elastic distribution like this: | ||
|
||
[source,csharp] | ||
---- | ||
using Elastic.OpenTelemetry; | ||
using Elastic.OpenTelemetry.Configuration; | ||
using Elastic.OpenTelemetry.Extensions; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using OpenTelemetry; | ||
var services = new ServiceCollection(); | ||
var builderOptions = new ElasticOpenTelemetryBuilderOptions <1> | ||
{ | ||
DistroOptions = new ElasticOpenTelemetryOptions <2> | ||
{ | ||
FileLogDirectory = "C:\\Logs", <3> | ||
} | ||
}; | ||
await using var session = new ElasticOpenTelemetryBuilder(builderOptions) <4> | ||
.WithTracing(b => b.AddSource("MySource")) | ||
.Build(); | ||
---- | ||
<1> Create an instance of `ElasticOpenTelemetryBuilderOptions` | ||
<2> Create an instance of `ElasticOpenTelemetryOptions` and configure the file log directory by | ||
setting the corresponding property. | ||
<3> This example sets the file log directory to `C:\Logs` which enables diagnostic file logging. | ||
<4> Pass the `ElasticOpenTelemetryBuilderOptions` instance to the `ElasticOpenTelemetryBuilder` constructor | ||
to configure the Elastic distribution. | ||
|
||
[[configuration-options]] | ||
=== Configuration options | ||
|
||
[float] | ||
[[config-filelogdirectory]] | ||
==== `FileLogDirectory` | ||
|
||
A string specifying the directory where the Elastic distribution will write diagnostic log files. | ||
When not provided, no file logging will occur. Each new .NET process will create a new log file in the | ||
specified directory. | ||
|
||
[options="header"] | ||
|============ | ||
| Environment variable name | IConfiguration key | ||
| `ELASTIC_OTEL_FILE_LOG_DIRECTORY` | `Elastic:OpenTelemetry:FileLogDirectory` | ||
|============ | ||
|
||
[options="header"] | ||
|============ | ||
| Default | Type | ||
| `string.Empty` | String | ||
|============ | ||
|
||
|
||
[float] | ||
[[config-fileloglevel]] | ||
==== `FileLogLevel` | ||
|
||
Sets the logging level for the distribtuion. | ||
|
||
Valid options: `Critical`, `Error`, `Warning`, `Information`, `Debug`, `Trace` and `None` (`None` disables the logging). | ||
|
||
[options="header"] | ||
|============ | ||
| Environment variable name | IConfiguration key | ||
| `ELASTIC_OTEL_FILE_LOG_LEVEL` | `Elastic:OpenTelemetry:FileLogLevel` | ||
|============ | ||
|
||
[options="header"] | ||
|============ | ||
| Default | Type | ||
| `Information` | String | ||
|============ | ||
|
||
|
||
[float] | ||
[[config-skipotlpexporter]] | ||
==== `SkipOtlpExporter` | ||
|
||
Allows the distribution to used with its defaults, but without enabling the export of telemetry data to | ||
an OTLP endpoint. This can be useful when you want to test applications without sending telemetry data. | ||
|
||
[options="header"] | ||
|============ | ||
| Environment variable name | IConfiguration key | ||
| `ELASTIC_OTEL_SKIP_OTLP_EXPORTER` | `Elastic:OpenTelemetry:SkipOtlpExporter` | ||
|============ | ||
|
||
[options="header"] | ||
|============ | ||
| Default | Type | ||
| `false` | Bool | ||
|============ | ||
|
||
|
||
[float] | ||
[[config-enabledelasticdefaults]] | ||
==== `EnabledElasticDefaults` | ||
|
||
A comma-separated list of Elastic defaults to enable. This can be useful when you want to enable | ||
only some of the Elastic distribution opinionated defaults. | ||
|
||
Valid options: `None`, `Tracing`, `Metrics`, `Logging`. | ||
|
||
Except for the `None` option, all other options can be combined. | ||
|
||
When this setting is not configured or the value is `string.Empty`, all Elastic distribution defaults will be enabled. | ||
|
||
When `None` is specified, no Elastic distribution defaults will be enabled, and you will need to manually | ||
configure the OpenTelemetry SDK to enable collection of telemetry signals. In this mode, the Elastic distribution | ||
does not provide any opinionated defaults, nor register any processors, allowing you to start with the "vanilla" | ||
OpenTelemetry SDK configuration. You may then choose to configure the various providers and register processors | ||
as required. | ||
|
||
In all other cases, the Elastic distribution will enable the specified defaults. For example, to enable only | ||
Elastic defaults only for tracing and metrics, set this value to `Tracing,Metrics`. | ||
|
||
[options="header"] | ||
|============ | ||
| Environment variable name | IConfiguration key | ||
| `ELASTIC_OTEL_ENABLE_ELASTIC_DEFAULTS` | `Elastic:OpenTelemetry:EnabledElasticDefaults` | ||
|============ | ||
|
||
[options="header"] | ||
|============ | ||
| Default | Type | ||
| `string.Empty` | String | ||
|============ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.