Observability

February 3, 2025 ยท View on GitHub

OpenTelemetry is the open-source standard for distributed tracing. SolrNet offers OpenTelemetry Tracing support out-of-the-box.

Tracing

ASP.NET Core application

This example is using the following packages:

  • OpenTelemetry.Extensions.Hosting
  • OpenTelemetry.Exporter.Console
var builder = WebApplication.CreateBuilder(args);

void ConfigureResource(ResourceBuilder r)
{
    r.AddService("Service Name",
        serviceVersion: "Version",
        serviceInstanceId: Environment.MachineName);
}

builder.Services.AddOpenTelemetry()
    .ConfigureResource(ConfigureResource)
    .WithTracing(b => b
        .AddSource(SolrNet.DiagnosticHeaders.DefaultSourceName) // SolrNet ActivitySource
        .AddConsoleExporter() // Any OTEL supportable exporter can be used here
    );

Console application

This example is using the following packages:

  • OpenTelemetry
  • OpenTelemetry.Exporter.Console
void ConfigureResource(ResourceBuilder r)
{
    r.AddService("Service Name",
        serviceVersion: "Version",
        serviceInstanceId: Environment.MachineName);
}

using var tracerProvider = Sdk.CreateTracerProviderBuilder()
    .ConfigureResource(ConfigureResource)
    .AddSource(SolrNet.DiagnosticHeaders.DefaultSourceName) // SolrNet ActivitySource
    .AddConsoleExporter() // Any OTEL supportable exporter can be used here
    .Build();

SolrNet spans contain the following attributes:

AttributeDescriptionExamples
db.systemThe database product identifiersolr
db.collection.nameThe solr core being targeted (optional)techproducts
db.query.textThe request parameters as a json string (optional)[{"q":"ipad"},{"rows":"100"},{"fq":"price:[0 TO 8]"},{"facet":"true"},{"facet.field":"cat"},{"sort":"price asc"}]
db.operation.nameThe name of the operation or command being executedquery, commit, add, delete, ...
http.request.methodThe underlying HTTP request methodGET, POST
server.addressHost name of the solr serverlocalhost
server.portPort of the solr server8983
url.fullThe full underlying request URLhttp://localhost:8983/solr/techproducts/select?q=ipad&rows=100&fq=price%3A%5B0+TO+8%5D&facet=true&facet.field=cat&sort=price+asc&version=2.2&wt=xml
solr.statusStatus header from the solr response (optional)0 means success
solr.qtimeQuery time header from the solr response (optional)42
error.typeError message (optional)The remote server returned an error: (404) Not Found.