Skip to content

Commit 21849ae

Browse files
Bump FileBasedConfiguration to 1.0 (#4883)
Co-authored-by: Robert Pająk <pellared@hotmail.com>
1 parent 2dd570a commit 21849ae

34 files changed

+83
-27
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ This component adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.h
99

1010
### Added
1111

12+
- Add support for file-based configuration file format version `1.0`.
13+
- Add support for `OTEL_CONFIG_FILE` environment variable for file-based configuration.
14+
This variable takes precedence over the deprecated
15+
`OTEL_EXPERIMENTAL_CONFIG_FILE` environment variable.
16+
1217
### Changed
1318

1419
- MongoDB instrumentation is updated to comply with v1.39.0 Semantic Convention
@@ -21,6 +26,9 @@ This component adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.h
2126

2227
### Deprecated
2328

29+
- `OTEL_EXPERIMENTAL_CONFIG_FILE` environment variable for file-based
30+
configuration is deprecated. Use `OTEL_CONFIG_FILE` instead.
31+
2432
### Removed
2533

2634
### Fixed

docs/file-based-configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ By default, the value is false.
1717
You can also specify the configuration file path (default: `config.yaml`):
1818

1919
```bash
20-
OTEL_EXPERIMENTAL_CONFIG_FILE=/path/to/config.yaml
20+
OTEL_CONFIG_FILE=/path/to/config.yaml
2121
```
2222

2323
In your config file you can use environment variables in the format `${ENVIRONMENT_VARIABLE}`
@@ -139,7 +139,7 @@ file-based configuration to include these parameters.
139139
# The yaml format is documented at
140140
# <https://github.com/open-telemetry/opentelemetry-configuration/tree/main/schema>
141141
# By default, the latest version is used.
142-
file_format: "1.0-rc.1"
142+
file_format: "1.0"
143143
# Configure if the SDK is disabled or not.
144144
# If omitted or null, false is used
145145
disabled: false

docs/nocode-instrumentation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ The no-code instrumentation configuration is defined under the
4545
`no_code/development` section in your YAML configuration file:
4646

4747
```yaml
48-
file_format: "1.0-rc.1"
48+
file_format: "1.0"
4949

5050
instrumentation/development:
5151
dotnet:

examples/file-based-configuration-files/default-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# The yaml format is documented at
55
# <https://github.com/open-telemetry/opentelemetry-configuration/tree/main/schema>
66
# By default, the latest version is used.
7-
file_format: "1.0-rc.1"
7+
file_format: "1.0"
88

99
# Propagator Configuration
1010
propagator:

examples/file-based-configuration-files/kitchen-sink.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# The yaml format is documented at
1010
# <https://github.com/open-telemetry/opentelemetry-configuration/tree/main/schema>
1111
# By default, the latest version is used.
12-
file_format: "1.0-rc.1"
12+
file_format: "1.0"
1313
# Configure if the SDK is disabled or not.
1414
# If omitted or null, false is used
1515
disabled: false

examples/file-based-configuration-files/sdk-migration-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
# The yaml format is documented at
3232
# <https://github.com/open-telemetry/opentelemetry-configuration/tree/main/schema>
3333
# By default, the latest version is used.
34-
file_format: "1.0-rc.1"
34+
file_format: "1.0"
3535
# Configure if the SDK is disabled or not.
3636
# If omitted or null, false is used
3737
# This setting is inverted (if OTEL_DOTNET_AUTO_SETUP_SDK is true, the SDK is disabled)

src/OpenTelemetry.AutoInstrumentation/Configurations/ConfigurationKeys.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,17 @@ public static class FileBasedConfiguration
7878
/// </summary>
7979
public const string Enabled = "OTEL_EXPERIMENTAL_FILE_BASED_CONFIGURATION_ENABLED";
8080

81+
/// <summary>
82+
/// Configuration key for the deprecated path to the configuration file.
83+
/// Default is <c>"config.yaml"</c>.
84+
/// </summary>
85+
public const string ExperimentalFileName = "OTEL_EXPERIMENTAL_CONFIG_FILE";
86+
8187
/// <summary>
8288
/// Configuration key for the path to the configuration file.
8389
/// Default is <c>"config.yaml"</c>.
8490
/// </summary>
85-
public const string FileName = "OTEL_EXPERIMENTAL_CONFIG_FILE";
91+
public const string FileName = "OTEL_CONFIG_FILE";
8692
}
8793

8894
/// <summary>

src/OpenTelemetry.AutoInstrumentation/Configurations/Settings.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration;
55
using OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration.Parser;
6+
using OpenTelemetry.AutoInstrumentation.Logging;
67

78
namespace OpenTelemetry.AutoInstrumentation.Configurations;
89

@@ -13,6 +14,7 @@ internal abstract class Settings
1314
{
1415
private static readonly bool IsYamlConfigEnabled = Environment.GetEnvironmentVariable(ConfigurationKeys.FileBasedConfiguration.Enabled) == "true";
1516
private static readonly Lazy<YamlConfiguration> YamlConfiguration = new(ReadYamlConfiguration);
17+
private static readonly IOtelLogger Logger = OtelLogging.GetLogger();
1618

1719
public static T FromDefaultSources<T>(bool failFast)
1820
where T : Settings, new()
@@ -58,7 +60,28 @@ public void LoadFile(YamlConfiguration configuration)
5860

5961
private static YamlConfiguration ReadYamlConfiguration()
6062
{
61-
var configFile = Environment.GetEnvironmentVariable(ConfigurationKeys.FileBasedConfiguration.FileName) ?? "config.yaml";
63+
var experimentalConfigFile = Environment.GetEnvironmentVariable(ConfigurationKeys.FileBasedConfiguration.ExperimentalFileName);
64+
65+
var configFile = Environment.GetEnvironmentVariable(ConfigurationKeys.FileBasedConfiguration.FileName);
66+
67+
if (!string.IsNullOrEmpty(configFile))
68+
{
69+
if (!string.IsNullOrEmpty(experimentalConfigFile))
70+
{
71+
Logger.Warning("Both OTEL_EXPERIMENTAL_CONFIG_FILE (deprecated) and OTEL_CONFIG_FILE are set. " +
72+
"Using OTEL_CONFIG_FILE and ignoring the deprecated variable.");
73+
}
74+
}
75+
else if (!string.IsNullOrEmpty(experimentalConfigFile))
76+
{
77+
Logger.Warning("OTEL_EXPERIMENTAL_CONFIG_FILE is deprecated. Please use OTEL_CONFIG_FILE instead.");
78+
configFile = experimentalConfigFile;
79+
}
80+
else
81+
{
82+
configFile = "config.yaml";
83+
}
84+
6285
// TODO validate file existence
6386

6487
var config = Parser.ParseYaml<YamlConfiguration>(configFile);

test/OpenTelemetry.AutoInstrumentation.Tests/Configurations/FileBased/Files/NoCodeFile.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
file_format: "1.0"
2+
13
instrumentation/development:
24
dotnet:
35
no_code:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
file_format: "1.0-rc.1"
1+
file_format: "1.0"
22
disabled: false
33
fail_fast: false
44
flush_on_unhandled_exception: false

0 commit comments

Comments
 (0)