Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
10d1342
[FileBased] Add Instrumentation
ysolomchenko Sep 29, 2025
a5ac594
[File-Based] Add Instrumentation option tests
ysolomchenko Oct 1, 2025
9038aef
Merge branch 'main' into FileBasedConfiguration-Instrumentation
ysolomchenko Oct 1, 2025
bde4ef5
[File-Based] Add instrumentation docs
ysolomchenko Oct 1, 2025
bb63fe8
fix
ysolomchenko Oct 1, 2025
0eab3d1
fix
ysolomchenko Oct 1, 2025
255c2e5
git ignore regex
ysolomchenko Oct 1, 2025
b9833e3
Update .gitignore for RegexGenerator file
ysolomchenko Oct 1, 2025
9bf9d1e
Fix formatting and spacing in RegexGenerator.g.cs
ysolomchenko Oct 1, 2025
bffc31d
Remove gitignore
ysolomchenko Oct 1, 2025
ee5baf5
fix test
ysolomchenko Oct 1, 2025
4eabeac
fix docs
ysolomchenko Oct 1, 2025
a929a87
Merge branch 'main' into FileBasedConfiguration-Instrumentation
ysolomchenko Oct 1, 2025
f5f1396
[File-Based] Fix capture headers
ysolomchenko Oct 13, 2025
241ea19
docs disable nstrumentation
ysolomchenko Oct 16, 2025
548f7e4
multiple headers in example
ysolomchenko Oct 16, 2025
2c36af4
`GraphQLSetDocumentConfiguration` instead of `SetDocumentConfiguration`.
ysolomchenko Oct 16, 2025
65692bc
[FileBased] Add Log4Net Bridge support
ysolomchenko Oct 16, 2025
2b1b8dd
Merge branch 'main' into FileBasedConfiguration-Instrumentation
ysolomchenko Oct 24, 2025
8e7658e
remove set_db_statement_for_text for Entity Framework
ysolomchenko Oct 24, 2025
0ec2986
fix log4net bridge
ysolomchenko Oct 24, 2025
ea047c0
update docs
ysolomchenko Oct 24, 2025
554d0b2
update docs
ysolomchenko Oct 24, 2025
138a943
fix
ysolomchenko Oct 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions docs/file-based-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,94 @@ propagator:
composite_list: ${OTEL_PROPAGATORS}
```

## Instrumentation Configuration

You can configure traces, metrics, and logs instrumentations.
Each entry in the example list below is equivalent to setting the corresponding
environment variable described in the [Instrumentation list and documentation](config.md#instrumentations).
To disable a instrumentation, comment out or remove its corresponding entry.

``` yaml
instrumentation/development:
dotnet:
traces:
aspnet: # ASP.NET
aspnetcore: # ASP.NET Core
azure: # Azure SDK
elasticsearch: # Elastic.Clients.Elasticsearch
elastictransport: # Elastic.Transport
entityframeworkcore: # Entity Framework Core
graphql: # GraphQL
grpcnetclient: # Grpc.Net.Client
httpclient: # System.Net.Http.HttpClient
kafka: # Confluent.Kafka
masstransit: # MassTransit
mongodb: # MongoDB.Driver
mysqlconnector: # MySqlConnector
mysqldata: # MySql.Data
npgsql: # Npgsql
nservicebus: # NServiceBus
oraclemda: # Oracle.ManagedDataAccess
rabbitmq: # RabbitMQ.Client
quartz: # Quartz
sqlclient: # Microsoft.Data.SqlClient & System.Data.SqlClient
stackexchangeredis: # StackExchange.Redis
wcfclient: # WCF Client
wcfservice: # WCF Service
metrics:
aspnet: # ASP.NET metrics
aspnetcore: # ASP.NET Core metrics
httpclient: # HttpClient metrics
netruntime: # .NET Runtime metrics
nservicebus: # NServiceBus metrics
process: # Process metrics
sqlclient: # SQL Client metrics
logs:
ilogger: # Microsoft.Extensions.Logging
log4net: # Log4Net
```

## Instrumentation options

``` yaml
instrumentation/development:
dotnet:
traces:
graphql:
# Whether the GraphQL instrumentation can pass raw queries through the graphql.document attribute. Queries might contain sensitive information.
# Default is false
set_document: false
oraclemda:
# Whether the Oracle Client instrumentation can pass SQL statements through the db.statement attribute. Queries might contain sensitive information. If set to false, db.statement is recorded only for executing stored procedures.
# Default is false
set_db_statement_for_text: false
aspnet:
# A comma-separated list of HTTP header names. ASP.NET instrumentations will capture HTTP request header values for all configured header names.
capture_request_headers: "X-Key,X-Custom-Header,X-Header-Example"
# A comma-separated list of HTTP header names. ASP.NET instrumentations will capture HTTP response header values for all configured header names.
capture_response_headers: "X-Key,X-Custom-Header,X-Header-Example"
aspnetcore:
# A comma-separated list of HTTP header names. ASP.NET Core instrumentations will capture HTTP request header values for all configured header names.
capture_request_headers: "X-Key,X-Custom-Header,X-Header-Example"
# A comma-separated list of HTTP header names. ASP.NET Core instrumentations will capture HTTP response header values for all configured header names.
capture_response_headers: "X-Key,X-Custom-Header,X-Header-Example"
httpclient:
# A comma-separated list of HTTP header names. HTTP Client instrumentations will capture HTTP request header values for all configured header names.
capture_request_headers: "X-Key,X-Custom-Header,X-Header-Example"
# A comma-separated list of HTTP header names. HTTP Client instrumentations will capture HTTP response header values for all configured header names.
capture_response_headers: "X-Key,X-Custom-Header,X-Header-Example"
grpcnetclient:
# A comma-separated list of gRPC metadata names. Grpc.Net.Client instrumentations will capture gRPC request metadata values for all configured metadata names.
capture_request_metadata: "X-Key,X-Custom-Header,X-Header-Example"
# A comma-separated list of gRPC metadata names. Grpc.Net.Client instrumentations will capture gRPC response metadata values for all configured metadata names.
capture_response_metadata: "X-Key,X-Custom-Header,X-Header-Example"
logs:
log4net:
# Logs bridge is disabled by default
# More info about log4net bridge can be found at https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/blob/main/docs/log4net-bridge.md
bridge_enabled: true
```

### Configuration based instrumentation

Documentation for configuration based instrumentation can be found in [nocode-instrumentation.md](nocode-instrumentation.md).
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public static IReadOnlyList<string> ParseList(this Configuration source, string

if (string.IsNullOrWhiteSpace(values))
{
return Array.Empty<string>();
return [];
}

return values!.Split(new[] { valueSeparator }, StringSplitOptions.RemoveEmptyEntries);
return values!.Split([valueSeparator], StringSplitOptions.RemoveEmptyEntries);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

using OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration.Parser;
using Vendors.YamlDotNet.Serialization;

namespace OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration;

[EmptyObjectOnEmptyYaml]
internal class CaptureHeadersConfiguration
{
/// <summary>
/// Gets or sets a comma-separated list of HTTP header names.
/// Instrumentations will capture HTTP request header values for all configured header names.
/// </summary>
[YamlMember(Alias = "capture_request_headers")]
public string? CaptureRequestHeaders { get; set; }

/// <summary>
/// Gets or sets a comma-separated list of HTTP header names.
/// Instrumentations will capture HTTP response header values for all configured header names.
/// </summary>
[YamlMember(Alias = "capture_response_headers")]
public string? CaptureResponseHeaders { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

using OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration.Parser;
using Vendors.YamlDotNet.Serialization;

namespace OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration;

[EmptyObjectOnEmptyYaml]
internal class CaptureMetadataConfiguration
{
/// <summary>
/// Gets or sets a comma-separated list of gRPC metadata names.
/// Grpc.Net.Client instrumentations will capture gRPC request metadata values for all configured metadata names.
/// </summary>
[YamlMember(Alias = "capture_request_metadata")]
public string? CaptureRequestMetadata { get; set; }

/// <summary>
/// Gets or sets a comma-separated list of gRPC metadata names.
/// Grpc.Net.Client instrumentations will capture gRPC response metadata values for all configured metadata names.
/// </summary>
[YamlMember(Alias = "capture_response_metadata")]
public string? CaptureResponseMetadata { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

using Vendors.YamlDotNet.Serialization;

namespace OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration;

internal class DotNetInstrumentation
{
/// <summary>
/// Gets or sets the configuration for .NET traces instrumentation.
/// </summary>
[YamlMember(Alias = "traces")]
public DotNetTraces? Traces { get; set; }

/// <summary>
/// Gets or sets the configuration for .NET metrics instrumentation.
/// </summary>
[YamlMember(Alias = "metrics")]
public DotNetMetrics? Metrics { get; set; }

/// <summary>
/// Gets or sets the configuration for .NET logs instrumentation.
/// </summary>
[YamlMember(Alias = "logs")]
public DotNetLogs? Logs { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

using Vendors.YamlDotNet.Serialization;

namespace OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration;

internal class DotNetLogs
{
/// <summary>
/// Gets or sets the ILogger logs instrumentation configuration.
/// </summary>
[YamlMember(Alias = "ilogger")]
public object? ILogger { get; set; }

/// <summary>
/// Gets or sets the Log4Net logs instrumentation configuration.
/// </summary>
[YamlMember(Alias = "log4net")]
public Log4NetBridgeEnabled? Log4Net { get; set; }

/// <summary>
/// Returns the list of enabled log instrumentations.
/// </summary>
public IReadOnlyList<LogInstrumentation> GetEnabledInstrumentations()
{
var result = new List<LogInstrumentation>();

if (ILogger != null)
{
result.Add(LogInstrumentation.ILogger);
}

if (Log4Net != null)
{
result.Add(LogInstrumentation.Log4Net);
}

return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

using System.Reflection;
using Vendors.YamlDotNet.Serialization;

namespace OpenTelemetry.AutoInstrumentation.Configurations.FileBasedConfiguration;

internal class DotNetMetrics
{
#if NETFRAMEWORK
/// <summary>
/// Gets or sets the ASP.NET metrics instrumentation configuration.
/// </summary>
[YamlMember(Alias = "aspnet")]
public object? AspNet { get; set; }
#endif

#if NET
/// <summary>
/// Gets or sets the ASP.NET Core metrics instrumentation configuration.
/// </summary>
[YamlMember(Alias = "aspnetcore")]
public object? AspNetCore { get; set; }
#endif

/// <summary>
/// Gets or sets the HttpClient metrics instrumentation configuration.
/// </summary>
[YamlMember(Alias = "httpclient")]
public object? HttpClient { get; set; }

/// <summary>
/// Gets or sets the .NET runtime metrics instrumentation configuration.
/// </summary>
[YamlMember(Alias = "netruntime")]
public object? NetRuntime { get; set; }

/// <summary>
/// Gets or sets the NServiceBus metrics instrumentation configuration.
/// </summary>
[YamlMember(Alias = "nservicebus")]
public object? NServiceBus { get; set; }

/// <summary>
/// Gets or sets the process metrics instrumentation configuration.
/// </summary>
[YamlMember(Alias = "process")]
public object? Process { get; set; }

/// <summary>
/// Gets or sets the SqlClient metrics instrumentation configuration.
/// </summary>
[YamlMember(Alias = "sqlclient")]
public object? SqlClient { get; set; }

/// <summary>
/// Returns the list of enabled metric instrumentations.
/// </summary>
public IReadOnlyList<MetricInstrumentation> GetEnabledInstrumentations()
{
var enabled = new List<MetricInstrumentation>();
var properties = typeof(DotNetMetrics).GetProperties(BindingFlags.Instance | BindingFlags.Public);

foreach (var prop in properties)
{
var value = prop.GetValue(this);
if (value != null)
{
if (Enum.TryParse<MetricInstrumentation>(prop.Name, out var instrumentation))
{
enabled.Add(instrumentation);
}
}
}

return enabled;
}
}
Loading
Loading