Add OpenTelemetry to your .NET application and export the traces to Aspecto's collector
dotnet add package OpenTelemetry.Extensions.Hosting --prerelease
dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol
Then, install instrumentations libraries that are relevant to your applications, for example:
dotnet add package OpenTelemetry.Instrumentation.AspNetCore --prerelease
You can browse all available instrumentation libraries in opentelemetry-dotnet repo and opentelemetry-dotnet-contrib repo
Steps:
- Initialize OpenTelemetry
- Set the OpenTelemetry Resource, which must include your
service.name
- Add Instrumentation Libraries which you installed
- 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
:
public void ConfigureServices(IServiceCollection services)
{
// your existing code here
services.AddOpenTelemetryTracing((builder) => builder
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(YOUR_SERVICE_NAME))
.AddAspNetCoreInstrumentation()
// Add other instrumentation libraries here, for example AddHttpClientInstrumentation()
.AddOtlpExporter(otlpOptions =>
{
otlpOptions.Endpoint = new Uri("https://otelcol.aspecto.io:4317");
otlpOptions.Headers = "Authorization={YOUR_ASPECTO_TOKEN}";
}));
}
You can see more examples and documentation in the project's github repo