1
- [[configuration]]
2
- == Configuration
1
+ ---
2
+ slug : /otel-dotnet/configure
3
+ title : Configure
4
+ ---
3
5
4
- Configuration of the OpenTelemetry SDK should be performed through the
5
- mechanisms https://opentelemetry.io/docs/languages/net/automatic/configuration/[documented on the OpenTelemetry website] .
6
+ Configuration of the OpenTelemetry SDK should be performed through the
7
+ mechanisms [ documented on the OpenTelemetry website ] ( https://opentelemetry.io/docs/languages/net/automatic/configuration/ ) .
6
8
7
- The Elastic distribution can be further configured using advanced settings when
9
+ The Elastic distribution can be further configured using advanced settings when
8
10
you need complete control of its behaviour. Configuration can be achieved by setting environment variables,
9
11
using the ` IConfiguration ` integration, or manually configuring the Elastic distribution.
10
12
11
- === Environment variables
13
+ ## Environment variables
12
14
13
15
The Elastic distribution can be configured using environment variables. This is a cross-platform
14
16
way to configure the Elastic distribution and is especially useful in containerized environments.
15
17
16
18
Environment variables are read at startup and can be used to configure the Elastic distribution.
17
- For details of the various options available and their corresponding environment variable names,
18
- see << configuration-options>> .
19
+ For details of the various options available and their corresponding environment variable names,
20
+ see [ configuration otpions ] ( #configuration_options ) .
19
21
20
22
Environment variables always take precedence over configuration provided by the ` IConfiguration `
21
23
system.
22
24
23
- === IConfiguration integration
25
+ ## IConfiguration integration
24
26
25
- In applications that use the "host" pattern, such as ASP.NET Core and worker service, the Elastic
27
+ In applications that use the "host" pattern, such as ASP.NET Core and worker service, the Elastic
26
28
distribution can be configured using the ` IConfiguration ` integration. This is done by passing an
27
29
` IConfiguration ` instance to the ` AddElasticOpenTelemetry ` extension method on the ` IServiceCollection ` .
28
30
29
31
When using an ` IHostApplicationBuilder ` such as modern ASP.NET Core applications, the current ` IConfiguration `
30
32
can be accessed via the ` Configuration ` property on the builder.
31
33
32
- [source,csharp]
33
- ----
34
+ ``` csharp
34
35
var builder = WebApplication .CreateBuilder (args );
35
- var currentConfig = builder.Configuration; <1>
36
- ----
37
- <1> Access the current `IConfiguration` instance from the builder.
36
+ var currentConfig = builder .Configuration ; [^1]
37
+ ```
38
+ [ ^ 1 ] : Access the current ` IConfiguration ` instance from the builder.
38
39
39
- By default, at this stage, the configuration will be populated from the default configuration sources,
40
- including the `appsettings.json` file(s) and command-line arguments. You may use these sources to define
40
+ By default, at this stage, the configuration will be populated from the default configuration sources,
41
+ including the ` appsettings.json ` file(s) and command-line arguments. You may use these sources to define
41
42
the configuration for the Elastic distribution.
42
43
43
44
For example, you can define the configuration for the Elastic distribution in the ` appsettings.json ` file:
44
45
45
- [source,json]
46
- ----
46
+ ``` json
47
47
{
48
48
"Elastic" : {
49
49
"OpenTelemetry" : {
50
- "FileLogDirectory": "C:\\Logs" <1>
50
+ "FileLogDirectory" : " C:\\ Logs" [ ^1 ]
51
51
}
52
52
}
53
53
}
54
- ----
55
- <1> This example sets the file log directory to `C:\Logs` which enables diagnostic file logging.
54
+ ```
55
+ [ ^ 1 ] : This example sets the file log directory to ` C:\Logs ` which enables diagnostic file logging.
56
56
57
- Configuration from the "Elastic:OpenTelemetry" section of the `IConfiguration` instance will be
57
+ Configuration from the "Elastic:OpenTelemetry" section of the ` IConfiguration ` instance will be
58
58
bound to the ` ElasticOpenTelemetryOptions ` instance used to configure the Elastic distribution.
59
59
60
- To learn more about the Microsoft configuration system, see
61
- https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration[Configuration in ASP.NET Core] .
60
+ To learn more about the Microsoft configuration system, see
61
+ [ Configuration in ASP.NET Core ] ( https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration ) .
62
62
63
- === Manual configuration
63
+ ## Manual configuration
64
64
65
- In all other scenarios, configuration can be achieved manually in code. This is done by creating
66
- an instance of `ElasticOpenTelemetryBuilderOptions` and passing it to the `ElasticOpenTelemetryBuilder` constructor
65
+ In all other scenarios, configuration can be achieved manually in code. This is done by creating
66
+ an instance of ` ElasticOpenTelemetryBuilderOptions ` and passing it to the ` ElasticOpenTelemetryBuilder ` constructor
67
67
or an overload of the ` AddElasticOpenTelemetry ` extension method on the ` IServiceCollection ` .
68
68
69
69
For example, in traditional console applications, you can configure the Elastic distribution like this:
70
70
71
- [source,csharp]
72
- ----
71
+ ``` csharp
73
72
using Elastic .OpenTelemetry ;
74
73
using Elastic .OpenTelemetry .Configuration ;
75
74
using Elastic .OpenTelemetry .Extensions ;
@@ -78,95 +77,73 @@ using OpenTelemetry;
78
77
79
78
var services = new ServiceCollection ();
80
79
81
- var builderOptions = new ElasticOpenTelemetryBuilderOptions <1>
80
+ var builderOptions = new ElasticOpenTelemetryBuilderOptions [ ^ 1 ]
82
81
{
83
- DistroOptions = new ElasticOpenTelemetryOptions <2>
82
+ DistroOptions = new ElasticOpenTelemetryOptions [ ^ 2 ]
84
83
{
85
- FileLogDirectory = "C:\\Logs", <3>
84
+ FileLogDirectory = " C:\\ Logs" , [ ^ 3 ]
86
85
}
87
86
};
88
87
89
- await using var session = new ElasticOpenTelemetryBuilder(builderOptions) <4>
88
+ await using var session = new ElasticOpenTelemetryBuilder (builderOptions ) [ ^ 4 ]
90
89
.WithTracing (b => b .AddSource (" MySource" ))
91
90
.Build ();
92
- ----
93
- <1> Create an instance of `ElasticOpenTelemetryBuilderOptions`
94
- <2> Create an instance of `ElasticOpenTelemetryOptions` and configure the file log directory by
91
+ ```
92
+ [ ^ 1 ] : Create an instance of ` ElasticOpenTelemetryBuilderOptions `
93
+ [ ^ 2 ] : Create an instance of ` ElasticOpenTelemetryOptions ` and configure the file log directory by
95
94
setting the corresponding property.
96
- <3> This example sets the file log directory to `C:\Logs` which enables diagnostic file logging.
97
- <4> Pass the `ElasticOpenTelemetryBuilderOptions` instance to the `ElasticOpenTelemetryBuilder` constructor
95
+ [ ^ 3 ] : This example sets the file log directory to ` C:\Logs ` which enables diagnostic file logging.
96
+ [ ^ 4 ] : Pass the ` ElasticOpenTelemetryBuilderOptions ` instance to the ` ElasticOpenTelemetryBuilder ` constructor
98
97
to configure the Elastic distribution.
99
98
100
- [[configuration-options]]
101
- === Configuration options
99
+ ## Configuration options
102
100
103
- [float]
104
- [[config-filelogdirectory]]
105
- ==== `FileLogDirectory`
101
+ ### ` FileLogDirectory `
106
102
107
- A string specifying the directory where the Elastic distribution will write diagnostic log files.
103
+ A string specifying the directory where the Elastic distribution will write diagnostic log files.
108
104
When not provided, no file logging will occur. Each new .NET process will create a new log file in the
109
105
specified directory.
110
106
111
- [options="header"]
112
- |============
113
- | Environment variable name | IConfiguration key
114
- | `ELASTIC_OTEL_FILE_LOG_DIRECTORY` | `Elastic:OpenTelemetry:FileLogDirectory`
115
- |============
116
-
117
- [options="header"]
118
- |============
119
- | Default | Type
120
- | `string.Empty` | String
121
- |============
107
+ | Environment variable name | IConfiguration key |
108
+ | ------------- | -------------|
109
+ | ` ELASTIC_OTEL_FILE_LOG_DIRECTORY ` | ` Elastic:OpenTelemetry:FileLogDirectory ` |
122
110
111
+ | Default | Type |
112
+ | ------------- | -------------|
113
+ | ` string.Empty ` | String |
123
114
124
- [float]
125
- [[config-fileloglevel]]
126
- ==== `FileLogLevel`
115
+ ### ` FileLogLevel `
127
116
128
117
Sets the logging level for the distribtuion.
129
118
130
119
Valid options: ` Critical ` , ` Error ` , ` Warning ` , ` Information ` , ` Debug ` , ` Trace ` and ` None ` (` None ` disables the logging).
131
120
132
- [options="header"]
133
- |============
134
- | Environment variable name | IConfiguration key
135
- | `ELASTIC_OTEL_FILE_LOG_LEVEL` | `Elastic:OpenTelemetry:FileLogLevel`
136
- |============
121
+ | Environment variable name | IConfiguration key |
122
+ | ------------- | -------------|
123
+ | ` ELASTIC_OTEL_FILE_LOG_LEVEL ` | ` Elastic:OpenTelemetry:FileLogLevel ` |
137
124
138
- [options="header"]
139
- |============
140
- | Default | Type
141
- | `Information` | String
142
- |============
125
+ | Default | Type |
126
+ | ------------- | -------------|
127
+ | ` Information ` | String |
143
128
129
+ ### ` SkipOtlpExporter `
144
130
145
- [float]
146
- [[config-skipotlpexporter]]
147
- ==== `SkipOtlpExporter`
148
-
149
- Allows the distribution to used with its defaults, but without enabling the export of telemetry data to
131
+ Allows the distribution to used with its defaults, but without enabling the export of telemetry data to
150
132
an OTLP endpoint. This can be useful when you want to test applications without sending telemetry data.
151
133
152
- [options="header"]
153
- |============
154
- | Environment variable name | IConfiguration key
155
- | `ELASTIC_OTEL_SKIP_OTLP_EXPORTER` | `Elastic:OpenTelemetry:SkipOtlpExporter`
156
- |============
157
-
158
- [options="header"]
159
- |============
160
- | Default | Type
161
- | `false` | Bool
162
- |============
134
+ | Environment variable name | IConfiguration key |
135
+ | ------------- | -------------|
136
+ | ` ELASTIC_OTEL_SKIP_OTLP_EXPORTER ` | ` Elastic:OpenTelemetry:SkipOtlpExporter ` |
163
137
138
+ | Default | Type |
139
+ | ------------- | -------------|
140
+ | ` false ` | Bool |
164
141
165
142
[ float]
166
143
[[ config-enabledelasticdefaults]]
167
- ==== `EnabledElasticDefaults`
144
+ ### ` EnabledElasticDefaults `
168
145
169
- A comma-separated list of Elastic defaults to enable. This can be useful when you want to enable
146
+ A comma-separated list of Elastic defaults to enable. This can be useful when you want to enable
170
147
only some of the Elastic distribution opinionated defaults.
171
148
172
149
Valid options: ` None ` , ` Tracing ` , ` Metrics ` , ` Logging ` .
@@ -178,20 +155,16 @@ When this setting is not configured or the value is `string.Empty`, all Elastic
178
155
When ` None ` is specified, no Elastic distribution defaults will be enabled, and you will need to manually
179
156
configure the OpenTelemetry SDK to enable collection of telemetry signals. In this mode, the Elastic distribution
180
157
does not provide any opinionated defaults, nor register any processors, allowing you to start with the "vanilla"
181
- OpenTelemetry SDK configuration. You may then choose to configure the various providers and register processors
158
+ OpenTelemetry SDK configuration. You may then choose to configure the various providers and register processors
182
159
as required.
183
160
184
- In all other cases, the Elastic distribution will enable the specified defaults. For example, to enable only
161
+ In all other cases, the Elastic distribution will enable the specified defaults. For example, to enable only
185
162
Elastic defaults only for tracing and metrics, set this value to ` Tracing,Metrics ` .
186
163
187
- [options="header"]
188
- |============
189
- | Environment variable name | IConfiguration key
190
- | `ELASTIC_OTEL_ENABLE_ELASTIC_DEFAULTS` | `Elastic:OpenTelemetry:EnabledElasticDefaults`
191
- |============
192
-
193
- [options="header"]
194
- |============
195
- | Default | Type
196
- | `string.Empty` | String
197
- |============
164
+ | Environment variable name | IConfiguration key |
165
+ | ------------- | -------------|
166
+ | ` ELASTIC_OTEL_ENABLE_ELASTIC_DEFAULTS ` | ` Elastic:OpenTelemetry:EnabledElasticDefaults ` |
167
+
168
+ | Default | Type |
169
+ | ------------- | -------------|
170
+ | ` string.Empty ` | String |
0 commit comments