Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
90 changes: 90 additions & 0 deletions docs/file-based-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,93 @@ resource:
process: # Detects process-level attributes (process.*)
processruntime: # Detects process runtime attributes (process.runtime.*)
```

## Instrumentation Configuration

You can configure traces, metrics, and logs instrumentations.
For more details and updates, see: [Instrumentation list and documentation](config.md#instrumentations)

``` yaml
instrumentation/development:
dotnet:
traces:
aspnet: # ASP.NET (.NET Framework) MVC/WebApi [Framework only]
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:
entityframeworkcore:
# Whether the Entity Framework Core 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
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
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=Value"
# 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=Value"
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=Value"
# 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=Value"
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=Value"
# 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=Value"
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=Value"
# 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=Value"
```
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 object? 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