Crucible.Common.ServiceDefaults
0.0.2
dotnet add package Crucible.Common.ServiceDefaults --version 0.0.2
NuGet\Install-Package Crucible.Common.ServiceDefaults -Version 0.0.2
<PackageReference Include="Crucible.Common.ServiceDefaults" Version="0.0.2" />
<PackageVersion Include="Crucible.Common.ServiceDefaults" Version="0.0.2" />
<PackageReference Include="Crucible.Common.ServiceDefaults" />
paket add Crucible.Common.ServiceDefaults --version 0.0.2
#r "nuget: Crucible.Common.ServiceDefaults, 0.0.2"
#:package Crucible.Common.ServiceDefaults@0.0.2
#addin nuget:?package=Crucible.Common.ServiceDefaults&version=0.0.2
#tool nuget:?package=Crucible.Common.ServiceDefaults&version=0.0.2
Crucible.Common.ServiceDefaults
Default service configuration for Crucible API apps. Right now, this is mostly just configuration for OpenTelemetry, but may involve more stuff as we get going.
Quick start
var builder = Host.CreateApplicationBuilder(args);
builder.AddServiceDefaults(openTelemetryOptions =>
{
openTelemetryOptions.AddConsoleExporter = builder.Environment.IsDevelopment();
openTelemetryOptions.CustomActivitySources = ["Player.Api"];
});
For Startup-style apps, call services.AddServiceDefaults(env, Configuration); during service registration.
Required environment variables
OTEL_EXPORTER_OTLP_ENDPOINTEndpoint for the OTLP collector that receives logs, metrics, and traces. Use anhttp://orhttps://URL such ashttp://otel-collector:4317. If this is omitted the SDK still wires instrumentation, but nothing is sent to an external collector unless an optional exporter is enabled.
Optional environment variables
The OpenTelemetry SDK honors additional standard variables (for example OTEL_RESOURCE_ATTRIBUTES, OTEL_EXPORTER_OTLP_HEADERS, OTEL_EXPORTER_OTLP_TIMEOUT), although this library does not set defaults for them. Configure these when you need to pass authentication headers, tweak timeouts, or add extra resource attributes.
Optional library settings
Pass an Action<OpenTelemetryOptions> when calling AddServiceDefaults (or the specific AddOpenTelemetryServiceDefaults overloads) to customize:
AddAlwaysOnTracingSampler– force sampling of every trace span.AddConsoleExporter– write telemetry to console for local debugging.AddPrometheusExporter– surface metrics through the built-in Prometheus endpoint.CustomActivitySources– register additional activity sources to trace.CustomMeters– register additional meters to collect metrics from.IncludeDefaultActivitySources– toggle the built-in sources (Microsoft.AspNetCore,Microsoft.EntityFrameworkCore,System.Net.Http).IncludeDefaultMeters– toggle the default meters described below.
What is enabled by default
- Structured logging with OTLP or console exporters.
- Metrics from the .NET runtime, the hosting stack, ASP.NET Core, HttpClient, Entity Framework Core, and process CPU/memory usage.
- Traces for ASP.NET Core, HttpClient, and Entity Framework Core operations.
Adjust the options or supply additional instrumentation packages to tailor telemetry for your service.
Default metrics and meters
The metrics pipeline wires several OpenTelemetry instrumentations:
AddRuntimeInstrumentationpublishesSystem.Runtimemetrics for garbage collection, thread pool saturation, and exception rates.AddProcessInstrumentationreports process CPU usage, working set, and other host-level resource counters.AddHttpClientInstrumentationrecords dependency call duration, size, and error metrics for outgoing HTTP requests.AddAspNetCoreInstrumentationcaptures request duration, size, and other server metrics for incoming ASP.NET Core traffic.
When IncludeDefaultMeters remains true, the provider also subscribes to these built-in meters:
Microsoft.AspNetCore.Hosting– high-level hosting metrics such as request queue depth and current requests.Microsoft.AspNetCore.Server.Kestrel– Kestrel transport metrics for connections, TLS handshakes, and request/response throughput.Microsoft.EntityFrameworkCore– database command execution counts and timings.System.Net.Http– outgoing request rate, duration, and failure counts from the .NET networking stack.System.Net.NameResolution– DNS cache and lookup timings surfaced by the .NET networking stack
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.Hosting (>= 10.0.2)
- OpenTelemetry.Exporter.Console (>= 1.15.0)
- OpenTelemetry.Exporter.OpenTelemetryProtocol (>= 1.15.0)
- OpenTelemetry.Exporter.Prometheus.AspNetCore (>= 1.15.0-beta.1)
- OpenTelemetry.Extensions.Hosting (>= 1.15.0)
- OpenTelemetry.Instrumentation.AspNetCore (>= 1.15.0)
- OpenTelemetry.Instrumentation.EntityFrameworkCore (>= 1.15.0-beta.1)
- OpenTelemetry.Instrumentation.Http (>= 1.15.0)
- OpenTelemetry.Instrumentation.Process (>= 1.15.0-beta.1)
- OpenTelemetry.Instrumentation.Runtime (>= 1.15.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.