Troubleshooting Common Issues with the Instrumentation .Net PackageInstrumentation is crucial for observing and diagnosing applications. The Instrumentation .Net Package provides telemetry, metrics, and tracing for .NET applications, but like any library it can present integration and runtime issues. This article covers common problems, how to identify their causes, and practical steps to resolve them. It assumes familiarity with .NET (Core/5+/Framework), dependency injection, and basic observability concepts.
1. Installation and versioning problems
Symptom: Package restore fails, NuGet errors, or runtime type conflicts.
Causes:
- Missing or incorrect package reference in your project file.
- Incompatible package version with your target framework.
- Transitive dependency conflicts (different packages referencing different versions).
- NuGet cache or restore issues.
Troubleshooting steps:
- Check your .csproj for a correct PackageReference:
<PackageReference Include="Instrumentation.Net.Package" Version="x.y.z" />
- Ensure your TargetFramework is supported (e.g., net6.0, net7.0). Update the package or target framework if incompatible.
- Run dotnet restore with diagnostics:
dotnet restore -v diag
Inspect logs for version conflicts.
- Clear NuGet caches if corrupted:
dotnet nuget locals all --clear
- Use
dotnet list package --vulnerable
anddotnet list package --outdated
to surface version problems. - If transitive conflicts persist, add explicit PackageReference entries for the affected dependency versions, or use binding redirects (for .NET Framework) or assembly versioning strategies.
2. Initialization and configuration errors
Symptom: Telemetry isn’t emitted, or initialization exceptions occur (e.g., null reference, type load).
Causes:
- Instrumentation not registered with the DI container or host.
- Missing configuration keys or malformed configuration values.
- Startup ordering issues where instrumentation is started before required services are available.
Troubleshooting steps:
- Verify registration (example for Generic Host / ASP.NET Core): “`csharp using Instrumentation.Net.Package;
builder.Services.AddInstrumentationNetPackage(options => {
options.ConnectionString = configuration["Instrumentation:ConnectionString"]; // other options
});
2. Confirm configuration values exist and are valid. Log the options during startup (avoid logging secrets). 3. Ensure registration occurs before building the host, and that any required services (e.g., IHttpClientFactory, ILoggerFactory) are available. 4. Catch and inspect exceptions during startup; consider wrapping initialization in try/catch and logging full exception details. 5. For ASP.NET Core, ensure middleware or hosted services provided by the package are added in the correct order (e.g., before authentication if it needs to capture unauthenticated requests). --- ### 3. No telemetry or missing spans/metrics Symptom: Application runs but no traces, spans, or metrics appear in your backend. Causes: - Exporter/collector misconfiguration (wrong endpoint, port, protocol). - Network/firewall blocking telemetry traffic. - Sampling settings too aggressive (drop most data). - Telemetry being filtered out by filters or processors. - Time synchronization issues causing backend to reject data. Troubleshooting steps: 1. Confirm exporter configuration: - Check endpoint URL, port, API key, and protocol (HTTP/GRPC). - For OpenTelemetry collectors, ensure OTLP exporter settings match collector expectations. 2. Test connectivity from the host to your backend:
curl -v http://collector:4317/v1/traces
Or use tcp/udp checks for non-HTTP transports. 3. Reduce sampling to ensure data is captured: ```csharp options.Sampler = new AlwaysOnSampler();
- Temporarily disable filters/processors that might drop telemetry.
- Check logs from the instrumentation package — enable debug/verbose logging to see internal exporter activity.
- Verify system time / NTP sync; large clock skew can cause telemetry to be rejected.
- Use an in-process or local exporter (console exporter, file exporter) to confirm that spans/metrics are produced by the instrumentation before they leave the app.
4. Duplicate or missing attributes and resource identification
Symptom: Duplicate spans, duplicated resource attributes, or missing service names/host attributes in your backend.
Causes:
- Multiple instrumentation initializations creating duplicated telemetry.
- Conflicting resource attribute settings from different libraries.
- Environment variables and code-based configuration both setting attributes.
Troubleshooting steps:
- Ensure instrumentation is initialized exactly once. Audit startup code and any libraries that may auto-instrument.
- Consolidate resource attribute setup in one place. For OpenTelemetry:
var resource = ResourceBuilder.CreateDefault() .AddService("my-service-name"); Sdk.CreateTracerProviderBuilder() .SetResourceBuilder(resource) ...
- Check environment variables (OTEL_SERVICENAME, other OTEL* vars) for overrides.
- If duplicates persist, add logic to detect/reuse existing providers/tracers instead of creating new ones.
5. High CPU, memory usage, or leaks after adding instrumentation
Symptom: App experiences higher resource usage, GC pressure, or memory leaks.
Causes:
- High-volume synchronous exporters blocking threads.
- Large in-memory buffers or unbounded queues.
- Retained references in custom processors or samplers.
- Excessive metric cardinality causing heavy aggregation and memory growth.
Troubleshooting steps:
- Use a local profiler (dotnet-counters, dotnet-trace, dotnet-dump, or Visual Studio profiler) to identify hotspots and retention paths.
- Prefer asynchronous exporters and configure batch sizes and timeouts:
options.BatchExportProcessorOptions = new BatchExportProcessorOptions { MaxQueueSize = 2048, ScheduledDelayMilliseconds = 5000, ExportTimeoutMilliseconds = 30000 };
- Reduce metric cardinality: avoid high-cardinality labels (user ids, request ids).
- Dispose providers/tracers correctly on shutdown to flush buffers.
- Review custom processors and ensure they don’t keep large caches or static references.
6. Authorization and authentication failures
Symptom: Backend rejects telemetry with ⁄403 errors or tokens are invalid.
Causes:
- Incorrect API key or token configuration.
- Token expiry or clock skew.
- Wrong header format or missing required headers.
Troubleshooting steps:
- Verify API keys/tokens are configured correctly and not expired.
- Ensure the instrumentation sends credentials in the expected header (Authorization: Bearer … or x-api-key).
- Check if the exporter supports credential refresh; if not, implement token refresh logic or use a credential provider that does.
- Inspect network traces or exporter logs to see the exact request and response codes.
7. Instrumentation conflicts with other libraries or frameworks
Symptom: Exceptions or inconsistent telemetry when used with other instrumentation libraries.
Causes:
- Multiple tracing libraries or instrumentations registering global/static providers.
- Conflicting middleware ordering.
- Different OpenTelemetry SDK versions causing behavior mismatch.
Troubleshooting steps:
- Align on a single instrumentation strategy/library where possible.
- If multiple are needed, ensure they interoperate by sharing the same TracerProvider or by using adapters.
- Upgrade/downgrade to compatible OpenTelemetry SDK versions across packages.
- Review middleware order and ensure request pipelines are instrumented only once.
8. Data format or schema mismatches in backend
Symptom: Backend shows malformed spans, missing fields, or misinterpreted metric types.
Causes:
- Mismatch between exporter format and backend ingestion expectations (e.g., OTLP version differences).
- Custom attributes using non-primitive types or unsupported formats.
- Backend expects specific semantic conventions not followed.
Troubleshooting steps:
- Confirm the exporter protocol and version match backend requirements (OTLP/gRPC vs OTLP/HTTP, JSON schema versions).
- Ensure attributes use supported types (string, bool, numeric) and follow semantic conventions where possible.
- If sending custom payloads, validate them with a local parser or tools provided by the backend.
9. Testing and local development pitfalls
Symptom: Tests fail or produce noisy telemetry; local dev doesn’t match production behavior.
Causes:
- Tests unintentionally sending telemetry to production endpoints.
- Instrumentation adding non-determinism in unit/integration tests.
- Environment-specific configuration differences.
Troubleshooting steps:
- Use environment-specific configuration: point local/test environments to a local collector, file/console exporter, or a no-op exporter.
if (env.IsDevelopment()) builder.Services.AddInstrumentationNetPackage(o => o.Exporter = ExporterType.Console);
- Mock or isolate instrumentation in unit tests; use no-op implementations where telemetry isn’t under test.
- For integration tests, capture telemetry to local files and assert expected spans rather than sending to external services.
10. Observability gaps: missing context propagation
Symptom: Traces don’t correlate across services; parent/child relationships missing.
Causes:
- Missing context propagation (HTTP headers not forwarded, background tasks losing Activity).
- Using libraries that don’t automatically flow System.Diagnostics.Activity or AsyncLocal context.
- Incorrect propagation formats between heterogeneous systems.
Troubleshooting steps:
- Ensure HTTP clients forward trace headers (e.g., inject propagation handler):
builder.Services.AddHttpClient("api") .AddHttpMessageHandler(sp => new HttpClientTracingHandler(sp.GetRequiredService<Tracer>()));
- Use built-in propagation APIs (System.Diagnostics.Activity, ActivityContext) and ensure instrumentation uses the same propagator (W3C TraceContext).
- For background tasks, explicitly pass Activity.Current or use ActivitySource.StartActivity to create new spans with the correct parent.
- Verify cross-process header names (traceparent, tracestate) and ensure intermediaries (proxies, gateways) do not strip them.
Practical checklist for troubleshooting
- Reproduce the issue locally with minimal setup.
- Enable debug/verbose logging for the instrumentation package.
- Switch to a local exporter to confirm telemetry is produced.
- Verify network connectivity and endpoint configuration.
- Validate sampling and filters.
- Check for duplicate initialization.
- Profile resource usage if performance degrades.
- Ensure correct credential/token usage.
- Confirm context propagation across boundaries.
Conclusion
Troubleshooting the Instrumentation .Net Package requires systematic checks across installation, initialization, exporter configuration, resource usage, and context propagation. Start by reproducing the issue in a controlled environment, enable detailed logging, and iterate through configuration, connectivity, and code-level checks. Properly configured, the package provides rich telemetry with minimal overhead; when problems arise, the steps above will help you isolate and resolve them efficiently.
Leave a Reply