Adliance.AspNetCore.Buddy.OpenTelemetry
8.0.0.9
Prefix Reserved
See the version list below for details.
dotnet add package Adliance.AspNetCore.Buddy.OpenTelemetry --version 8.0.0.9
NuGet\Install-Package Adliance.AspNetCore.Buddy.OpenTelemetry -Version 8.0.0.9
<PackageReference Include="Adliance.AspNetCore.Buddy.OpenTelemetry" Version="8.0.0.9" />
paket add Adliance.AspNetCore.Buddy.OpenTelemetry --version 8.0.0.9
#r "nuget: Adliance.AspNetCore.Buddy.OpenTelemetry, 8.0.0.9"
// 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
- Frontend instrumentation
- Backend instrumentation
- Background jobs with Hangfire
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
- Adding the following code to
_ViewImports.cshtml
:
@inject Adliance.AspNetCore.Buddy.OpenTelemetry.HtmlHelper OtelHtmlHelper
- Adding the following in the
head
section of your_Layout.cshtml
before closing thebody
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 | Versions 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. |
-
net8.0
- OpenTelemetry.Exporter.Console (>= 1.8.0)
- OpenTelemetry.Exporter.OpenTelemetryProtocol (>= 1.8.0)
- OpenTelemetry.Extensions.Hosting (>= 1.8.0)
- OpenTelemetry.Instrumentation.AspNetCore (>= 1.8.1)
- OpenTelemetry.Instrumentation.EntityFrameworkCore (>= 1.0.0-beta.11)
- OpenTelemetry.Instrumentation.Hangfire (>= 1.6.0-beta.1)
- OpenTelemetry.Instrumentation.Http (>= 1.8.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.