Jaahas.OpenTelemetry.Extensions 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Jaahas.OpenTelemetry.Extensions --version 1.0.0                
NuGet\Install-Package Jaahas.OpenTelemetry.Extensions -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Jaahas.OpenTelemetry.Extensions" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Jaahas.OpenTelemetry.Extensions --version 1.0.0                
#r "nuget: Jaahas.OpenTelemetry.Extensions, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Jaahas.OpenTelemetry.Extensions as a Cake Addin
#addin nuget:?package=Jaahas.OpenTelemetry.Extensions&version=1.0.0

// Install Jaahas.OpenTelemetry.Extensions as a Cake Tool
#tool nuget:?package=Jaahas.OpenTelemetry.Extensions&version=1.0.0                

About

Jaahas.OpenTelemetry.Extensions defines extension methods to simplify the configuration of OpenTelemetry in .NET applications.

Registering Service Metadata via Attributes

You can annotate an assembly with the [Jaahas.OpenTelemetry.OpenTelemetryService] attribute to mark it as containing an OpenTelemetry service:

[assembly: Jaahas.OpenTelemetry.OpenTelemetryService("my-service")]

When you construct your OpenTelemetry ResourceBuilder, you can easily register the service with the resource builder as follows:

services.AddOpenTelemetry()
    .ConfigureResource(builder => builder.AddService(typeof(MyServiceType).Assembly));

This will register the service using the name specified in the attribute, and the version of the assembly in MAJOR.MINOR.PATCH format. You can also optionally specify a service instance ID:

services.AddOpenTelemetry()
    .ConfigureResource(builder => builder.AddService(typeof(MyServiceType).Assembly, "some-id"));

OpenTelemetry Protocol (OTLP) Exporter Configuration

Jaahas.OpenTelemetry.Extensions makes it easy to configure an OpenTelemetry Protocol (OTLP) exporter via the .NET configuration system. The exporter can be configured to export traces, metrics or logs, or any combination of the three:

// Assumes that configuration is an instance of your application's 
// IConfiguration.

services.AddOpenTelemetry()
    .ConfigureResource(builder => builder.AddService(typeof(MyServiceType).Assembly))
    .WithTracing(builder => {
        // TODO: configure tracing
        builder.ConfigureOtlpExporter(configuration);
    })
    .WithMetrics(builder => {
        // TODO: configure metrics
        builder.ConfigureOtlpExporter(configuration);
    })
    .WithLogging(configureBuilder: null, configureOptions: options => {
        options.IncludeScopes = true;
        options.ConfigureOtlpExporter(configuration);
    });

By default, the ConfigureOtlpExporter extension method will bind against a configuration section named OpenTelemetry:Exporters:OTLP to configure an instance of JaahasOtlpExporterOptions.

The default configuration used is as follows:

{
    "OpenTelemetry": {
        "Exporters": {
            "OTLP": {
                // OTLP exporter is disabled by default.
                "Enabled": false,

                // Protocol can be "Grpc" or "HttpProtobuf".
                "Protocol": "Grpc",

                // Endpoint is inferred from the export protocol if not 
                // specified.
                "Endpoint": null,

                // The OpenTelemetry signals to export. Possible values are: 
                //     Traces 
                //     Logs 
                //     Metrics 
                //     TracesAndLogsAndMetrics 
                //     TracesAndLogs 
                //     TracesAndMetrics 
                //     LogsAndMetrics
                "Signals": "Traces",

                // Optional headers to include in export requests (such as API 
                // keys) are specified as a JSON dictionary.
                "Headers": null,

                // Timeout for export requests.
                "Timeout": "00:00:10",

                // When true and the Protocol is "HttpProtobuf", the exporter 
                // ensures that the standard OTLP signal path is appended to 
                // the endpoint when exporting a given signal type. The 
                // standard OTLP signal path is "/v1/traces", "/v1/logs", and 
                // "/v1/metrics" for traces, logs, and metrics, respectively.
                "AppendSignalPathToEndpoint": true
            }
        }
    }
}

Note that the default configuration means that the OTLP exporter is disabled by default and calls to the ConfigureOtlpExporter extension method have no effect until it is enabled.

Example Configuration

To export logs and traces to Seq using the HTTP protobuf export format, you could use the following configuration:

{
    "OpenTelemetry": {
        "Exporters": {
            "OTLP": {
                "Enabled": true,
                "Protocol": "HttpProtobuf",
                "Endpoint": "http://localhost:5341/ingest/otlp",
                "Signals": "TracesAndLogs",
                "Headers": {
                    "X-Seq-ApiKey": "your-api-key"
                }
            }
        }
    }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.3.0 105 10/31/2024
2.2.0 88 10/31/2024
2.1.0 114 9/27/2024
2.0.2 119 9/24/2024
2.0.1 96 9/24/2024
2.0.0 81 9/19/2024
1.0.0 93 9/18/2024