Adliance.AspNetCore.Buddy.OpenTelemetry 8.0.0.9

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
dotnet add package Adliance.AspNetCore.Buddy.OpenTelemetry --version 8.0.0.9
NuGet\Install-Package Adliance.AspNetCore.Buddy.OpenTelemetry -Version 8.0.0.9
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="Adliance.AspNetCore.Buddy.OpenTelemetry" Version="8.0.0.9" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Adliance.AspNetCore.Buddy.OpenTelemetry --version 8.0.0.9
#r "nuget: Adliance.AspNetCore.Buddy.OpenTelemetry, 8.0.0.9"
#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 Adliance.AspNetCore.Buddy.OpenTelemetry as a Cake Addin
#addin nuget:?package=Adliance.AspNetCore.Buddy.OpenTelemetry&version=8.0.0.9

// Install Adliance.AspNetCore.Buddy.OpenTelemetry as a Cake Tool
#tool nuget:?package=Adliance.AspNetCore.Buddy.OpenTelemetry&version=8.0.0.9

Adliance.AspNetCore.Buddy.OpenTelemetry

The OpenTelemetry Buddy makes instrumentation of ASP.NET Core web services easy.

Features

Setup library in an ASP.NET project

The package offers the AddBuddyOpenTelemetry extensions to add the instrumentation and exporter.

using Adliance.AspNetCore.Buddy.OpenTelemetry.Extensions;

// ...

public void ConfigureServices(IServiceCollection services)
{
  //...
  services.AddBuddyOpenTelemetry(Configuration.GetSection("OpenTelemetry"))    
  // if you use Hangfire, also add
  services.AddBuddyOpenTelemetryHangfire(Configuration.GetSection("OpenTelemetry"));
}

public void Configure(IApplicationBuilder app)
{
    // if you want to instrument the frontend
    app.UseBuddyOpenTelemetryBrowserAssets();
}

To also send log messages from Microsoft.Extensions.Logging, the package offers another AddBuddyOpenTelemetry extension.

using Adliance.AspNetCore.Buddy.OpenTelemetry.Extensions;

// ...

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.UseStartup<Startup>();
            webBuilder.ConfigureLogging((context, builder) =>
            {
                builder.AddBuddyOpenTelemetry(context.Configuration.GetSection("OpenTelemetry"));
            });
        });

Configuration (appsettings.json)

Add a section in the configuration of your project and add at least the following configuration:

{
  "OpenTelemetry": {
    "ServiceName": "example server"
  }
}

It is also possible to overwrite defaults for the exporter like this:

{
  "OpenTelemetry": {
    "ServiceName": "example server",
    "OtlpExporter": {
      "Endpoint": "http://localhost:4317",
      "Protocol": "0", // 0 ... gRPC, 1 ... http/protobuf
      "Headers": "X-Api-Key=123,X-Api-Version=1.0",
      "TimeoutMilliseconds": 60000
    }
  }
}

Frontend instrumentation

It is important to pass a trace parent to the frontend tracing SDK, such that the spans can be grouped together later on. This can be achieved by adding a meta tag to the head section of the HTML by

  1. Adding the following code to _ViewImports.cshtml:
@inject Adliance.AspNetCore.Buddy.OpenTelemetry.HtmlHelper OtelHtmlHelper
  1. Adding the following in the head section of your _Layout.cshtml before closing the body section:
@Html.Raw(OtelHtmlHelper.TraceParentTag)

The UseBuddyOpenTelemetryBrowserAssets extension method adds a middleware to serve the necessary JavaScript file at the /otel-$version/telemetry.js endpoint. This must also be referenced in your _Layout.cshtml:

@Html.Raw(OtelHtmlHelper.IncludeAndInitializeJavascript)


<script>
    
    window.buddyTelemetry.traceSpan("example span", () => "the result");
</script>
Product Compatible and additional computed target framework versions.
.NET 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. 
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
8.0.0.9 83 4/16/2024
8.0.0.7 42 4/11/2024
8.0.0.6 44 4/11/2024
8.0.0.5 46 4/11/2024
8.0.0.4 64 4/10/2024
8.0.0.3 46 4/10/2024
8.0.0.2 39 4/10/2024