Add otel.sdk.processor.log.processed metric#7486
Open
cijothomas wants to merge 7 commits into
Open
Conversation
Implement the otel.sdk.processor.log.processed counter metric for
BatchLogRecordExportProcessor and SimpleLogRecordExportProcessor.
The metric is emitted on meter 'otel.sdk.experimental' which requires
explicit opt-in via .AddMeter("otel.sdk.experimental") — zero overhead
without a listener.
Attributes:
- otel.component.type: batching_log_processor | simple_log_processor
- otel.component.name: unique instance identifier (e.g. batching_log_processor/0)
- error.type (conditional): queue_full | already_shutdown
Design:
- SdkSelfObservability internal helper owns the Meter and Counter
- Pre-allocated KeyValuePair[] tag arrays (no per-call allocation)
- Batch processor uses TryExport return value to classify success vs queue_full
- Both processors detect post-shutdown state via OnShutdown override
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7486 +/- ##
==========================================
+ Coverage 90.21% 90.23% +0.01%
==========================================
Files 287 289 +2
Lines 15560 15620 +60
==========================================
+ Hits 14038 14094 +56
- Misses 1522 1526 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
|
The test was flaky on Windows ARM / net462 because with maxQueueSize=1 and maxExportBatchSize=1, the worker thread could drain the queue faster than items were being emitted, resulting in no drops. Use a blocking DelegatingExporter to hold the worker in Export() while filling the queue.
| break; | ||
| } | ||
|
|
||
| // TODO: Consider switching to an ObservableCounter that piggybacks on |
Member
Author
There was a problem hiding this comment.
Will file a tracking issue for this.
Member
There was a problem hiding this comment.
Cool - just add a link to the TODO once created.
c6a9a18 to
8c89abe
Compare
- Copy MeterFactory from contrib for auto-versioning - Make Meter internal (removes SA1202 suppression) - Share base tags between success/error arrays - Single Counter.Add() call with local tag assignment - Shorten README overhead note
8c89abe to
6c5df34
Compare
martincostello
approved these changes
Jul 4, 2026
| /// </summary> | ||
| public class BatchLogRecordExportProcessor : BatchExportProcessor<LogRecord> | ||
| { | ||
| private static int instanceCounter = -1; |
Member
There was a problem hiding this comment.
While unlikely there'd ever be that many created in the lifetime of a process, maybe use long to give more headroom against overflow?
| break; | ||
| } | ||
|
|
||
| // TODO: Consider switching to an ObservableCounter that piggybacks on |
Member
There was a problem hiding this comment.
Cool - just add a link to the TODO once created.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Towards #3880
Adds the
otel.sdk.processor.log.processedcounter metric toBatchLogRecordExportProcessorandSimpleLogRecordExportProcessor, 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
otel.sdk.experimental- requires explicit opt-in via.AddMeter("otel.sdk.experimental"). Without this,Counter.Add()is a no-op with zero overhead.Counter<long>namedotel.sdk.processor.log.processedotel.component.type-batching_log_processororsimple_log_processorotel.component.name- unique per instance (e.g.batching_log_processor/0)error.type(conditional) -queue_fullwhen buffer rejects,already_shutdownwhen processor has been shut downOpt-in example
Why .AddMeter() instead of env variable or compile-time flag?
Metrics in .NET are inherently opt-in: without a
MeterProvidersubscribing 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.