Skip to content

Commit

Permalink
Ensure we respect OTEL instrumentation/signal configuration (#131)
Browse files Browse the repository at this point in the history
* simplify our defaults enablement a tad

* Ensure we listen to OTEL_*_INSTRUMENTATION_ENABLED

* move parsers into their own files and started on infra for enabled instrumentations

* Add env and config parsers to clean up Options

* cleanup

* dotnet format

* EnabledDefaults => ElasticDefaults

* ELASTIC_OTEL_ENABLE_ELASTIC_DEFAULTS => ELASTIC_OTEL_DEFAULTS_ENABLE

* ENABLE => ENABLED

* EnabledSignals => Signals
  • Loading branch information
Mpdreamz committed Jul 18, 2024
1 parent b7ab23f commit 3d093c9
Show file tree
Hide file tree
Showing 22 changed files with 1,399 additions and 507 deletions.
8 changes: 4 additions & 4 deletions docs/configure.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ an OTLP endpoint. This can be useful when you want to test applications without

[float]
[[config-enabledelasticdefaults]]
### `EnabledElasticDefaults`
### `ElasticDefaults`

A comma-separated list of Elastic defaults to enable. This can be useful when you want to enable
only some of the Elastic Distribution for OpenTelemetry .NET opinionated defaults.

Valid options: `None`, `Tracing`, `Metrics`, `Logging`.
Valid options: `None`, `Traces`, `Metrics`, `Logs`, `All`.

Except for the `None` option, all other options can be combined.

Expand All @@ -159,11 +159,11 @@ OpenTelemetry SDK configuration. You may then choose to configure the various pr
as required.

In all other cases, the Elastic Distribution for OpenTelemetry .NET will enable the specified defaults. For example, to enable only
Elastic defaults only for tracing and metrics, set this value to `Tracing,Metrics`.
Elastic defaults only for tracing and metrics, set this value to `Traces,Metrics`.

| Environment variable name | IConfiguration key |
| ------------- |-------------|
| `ELASTIC_OTEL_ENABLE_ELASTIC_DEFAULTS` | `Elastic:OpenTelemetry:EnabledElasticDefaults` |
| `ELASTIC_OTEL_DEFAULTS_ENABLED` | `Elastic:OpenTelemetry:ElasticDefaults` |

| Default | Type |
| ------------- |-------------|
Expand Down
28 changes: 28 additions & 0 deletions src/Elastic.OpenTelemetry/Configuration/ConfigCell.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

namespace Elastic.OpenTelemetry.Configuration;

internal class ConfigCell<T>(string key, T value)
{
public string Key { get; } = key;
public T? Value { get; private set; } = value;
public ConfigSource Source { get; set; } = ConfigSource.Default;

public void Assign(T value, ConfigSource source)
{
Value = value;
Source = source;
}

public override string ToString() => $"{Key}: '{Value}' from [{Source}]";
}
internal enum ConfigSource
{
Default, // Default value assigned within this class
Environment, // Loaded from an environment variable
// ReSharper disable once InconsistentNaming
IConfiguration, // Bound from an IConfiguration instance
Property // Set via property initializer
}
29 changes: 29 additions & 0 deletions src/Elastic.OpenTelemetry/Configuration/ElasticDefaults.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

namespace Elastic.OpenTelemetry.Configuration;

/// <summary>
/// Control which elastic defaults you want to include.
/// <para>NOTE: this is an expert level option only use this if you want to take full control of the OTEL configuration</para>
/// <para>defaults to <see cref="ElasticDefaults.All"/></para>
/// </summary>
[Flags]
public enum ElasticDefaults
{
/// <summary> No Elastic defaults will be included, acting effectively as a vanilla OpenTelemetry </summary>
None,

/// <summary> Include Elastic Distribution for OpenTelemetry .NET tracing defaults</summary>
Traces = 1 << 0, //1

/// <summary> Include Elastic Distribution for OpenTelemetry .NET metrics defaults</summary>
Metrics = 1 << 1, //2

/// <summary> Include Elastic Distribution for OpenTelemetry .NET logging defaults</summary>
Logs = 1 << 2, //4

/// <summary> (default) Include all Elastic Distribution for OpenTelemetry .NET logging defaults</summary>
All = ~0
}
Loading

0 comments on commit 3d093c9

Please sign in to comment.