Skip to content
Open
Show file tree
Hide file tree
Changes from 20 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
92 changes: 92 additions & 0 deletions docs/file-based-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,98 @@ propagator:
composite_list: ${OTEL_PROPAGATORS}
```

## Instrumentation Configuration

You can configure traces, metrics, and logs instrumentations.
For more details and updates, see: [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 (.NET Framework) MVC/WebApi [Framework only]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that you should put here a name from the config.md tables.
I would like to avoid 2 places to maintain same data.

aspnetcore: # ASP.NET Core [Core only]
azure: # Azure SDK [Core & Framework]
elasticsearch: # Elastic.Clients.Elasticsearch [Core & Framework]
elastictransport: # Elastic.Transport (>=0.4.16) [Core & Framework]
entityframeworkcore: # Entity Framework Core (>=6.0.12) [Core only]
graphql: # GraphQL (>=7.5.0) [Core only]
grpcnetclient: # Grpc.Net.Client (>=2.52.0 & <3.0.0) [Core & Framework]
httpclient: # System.Net.Http.HttpClient [Core & Framework]
kafka: # Confluent.Kafka (>=1.4.0 & <3.0.0) [Core & Framework]
masstransit: # MassTransit (>=8.0.0) [Core only]
mongodb: # MongoDB.Driver (>=2.7.0 <4.0.0) [Core & Framework]
mysqlconnector: # MySqlConnector (>=2.0.0) [Core only]
mysqldata: # MySql.Data (>=8.1.0) [Core only]
npgsql: # Npgsql (>=6.0.0) [Core only]
nservicebus: # NServiceBus (>=8.0.0 & <10.0.0) [Core & Framework]
oraclemda: # Oracle.ManagedDataAccess (>=23.4.0) [Core only]
rabbitmq: # RabbitMQ.Client (>=6.0.0) [Core & Framework]
quartz: # Quartz (>=3.4.0, not supported < .NET Framework 4.7.2)
sqlclient: # Microsoft.Data.SqlClient & System.Data.SqlClient [Core & Framework]
stackexchangeredis: # StackExchange.Redis (>=2.6.122 & <3.0.0) [Core only]
wcfclient: # WCF Client [Core & Framework]
wcfservice: # WCF Service [Framework only]
metrics:
aspnet: # ASP.NET metrics [Framework only]
aspnetcore: # ASP.NET Core metrics [Core only]
httpclient: # HttpClient metrics [Core & Framework]
netruntime: # .NET Runtime metrics [Core only]
nservicebus: # NServiceBus metrics [Core & Framework]
process: # Process metrics [Core & Framework]
sqlclient: # SQL Client metrics [Core & Framework]
logs:
ilogger: # Microsoft.Extensions.Logging (>=9.0.0) [Core & Framework]
log4net: # log4net (>=2.0.13 && <4.0.0) [Core & Framework]
```

## 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
sqlclient:
# Whether the SQL 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.
# Not supported on .NET Framework for System.Data.SqlClient.
# Default is false
set_db_statement_for_text: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

already dropped?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ea047c0

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