.NET
Add OpenTelemetry to your .NET application and export the traces to Aspecto's collector

Installation

1
dotnet add package Opentelemetry.Extensions.Hosting --prerelease
2
dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol
Copied!
Then, install instrumentations libraries that are relevant to your applications, for example:
1
dotnet add package OpenTelemetry.Instrumentation.AspNetCore --prerelease
Copied!
You can browse all available instrumentation libraries in opentelemetry-dotnet repo and opentelemetry-dotnet-contrib repo

Setup OpenTelemetry SDK in Code

Steps:
  1. 1.
    Initialize OpenTelemetry
  2. 2.
    Set the OpenTelemetry Resource, which must include your service.name
  3. 3.
    Add Instrumentation Libraries which you installed
  4. 4.
    Configure OTLP exporter to send traces to Aspecto. You can find your Aspecto Token here​
For ASP.NET Core, you need to add this code to the ConfigureServices function in Startup.cs:
1
public void ConfigureServices(IServiceCollection services)
2
{
3
// your existing code here
4
5
services.AddOpenTelemetryTracing((builder) => builder
6
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(YOUR_SERVICE_NAME))
7
.AddAspNetCoreInstrumentation()
8
// Add other instrumentation libraries here, for example AddHttpClientInstrumentation()
9
.AddOtlpExporter(otlpOptions =>
10
{
11
otlpOptions.Endpoint = new Uri("https://otelcol.aspecto.io:4317");
12
otlpOptions.Headers = "Authorization={YOUR_ASPECTO_TOKEN}";
13
}));
14
}
Copied!

More Info

You can see more examples and documentation in the project's github repo​
Last modified 1mo ago