Add otel.sdk.processor.log.processed metric

Merged
CI
3mo ago
+636-27

Towards #3880

Adds the otel.sdk.processor.log.processed counter metric to BatchLogRecordExportProcessor and SimpleLogRecordExportProcessor, following the OTel SDK self-observability semantic conventions.

This is the first SDK self-observability metric in the .NET SDK. More metrics (queue size, exporter counters, etc.) will follow in subsequent PRs.

Design

  • Meter: otel.sdk.experimental - requires explicit opt-in via .AddMeter("otel.sdk.experimental"). Without this, Counter.Add() is a no-op with zero overhead.
  • Instrument: Counter<long> named otel.sdk.processor.log.processed
  • Attributes:
    • otel.component.type - batching_log_processor or simple_log_processor
    • otel.component.name - unique per instance (e.g. batching_log_processor/0)
    • error.type (conditional) - queue_full when buffer rejects, already_shutdown when processor has been shut down

Shutdown behavior (note for reviewers)

To count already_shutdown accurately, the batch processor needs a well-defined shutdown boundary: a record whose OnEnd is in flight when Shutdown() is called must be classified deterministically. It uses a small barrier (activeOnEndCount plus a bounded wait in OnShutdown) so an in-flight OnEnd either finishes enqueueing before the worker snapshots its drain target — so the record is drained and counted as processed — or observes shutdown and is counted already_shutdown. As a side benefit this also tightens a pre-existing enqueue-vs-drain-snapshot race at shutdown, so it is a slight behavior change beyond adding the metric (records at the boundary are handled deterministically rather than silently lost). That underlying race is generic to BatchExportProcessor<T>; lifting this coordination into the shared batch infrastructure (to also cover span batching) can be a follow-up. SimpleLogRecordExportProcessor deliberately does not add this coordination — it accepts a benign shutdown race and is not intended for production use.

Opt-in example

var meterProvider = Sdk.CreateMeterProviderBuilder()
    .AddMeter("otel.sdk.experimental")
    .AddOtlpExporter()
    .Build();

Why .AddMeter() instead of env variable or compile-time flag?

Metrics in .NET are inherently opt-in: without a MeterProvider subscribing to the meter, Counter.Add() is a no-op at near-zero cost. The .AddMeter("otel.sdk.experimental") call provides natural gating without requiring additional mechanisms like env variables or feature flags.