Repository navigation
OpenTelemetry tracing and metrics for Send, CreateStream, Publish and handlers - #19
Merged
Merged
Conversation
AnyMediator emits OpenTelemetry-compatible spans and a duration histogram
through .NET's ActivitySource and Meter, with no new dependency.
- AnyMediatorDiagnostics exposes ActivitySourceName and MeterName.
- Spans: "send {Request}", "create_stream {Request}" (open until the
stream is read, fails or is abandoned), "publish {Notification}" and one
"handle {Notification}" child per handler, with operation, message type
and handler type attributes. Failures set Error status, error.type and
an exception event.
- Histogram anymediator.operation.duration (seconds) by operation,
message type and error.type.
- With no listener the dispatch path checks two flags; traced paths live in
separate methods so no closure is allocated. Send stays at 93 ns / 96 B.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
New "Tracing and metrics" guide page with the OpenTelemetry setup, span and metric reference, cost, and trace propagation through a notification sink. README section and llms.txt entry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Span names and attributes are built once per message type (OperationSpan) instead of on every call; traced operations take their inputs as a state tuple and a static lambda, so no closure is allocated; the non-generic Run no longer wraps the generic one; tags are passed at span creation and the duration is recorded with the same prebuilt array. TracingBenchmarks measures Send and Publish with and without listeners. With a listener recording everything: Send 652 ns / 880 B -> 564 ns / 704 B; Publish with 3 handlers 2950 ns / 3936 B -> 2310 ns / 2872 B. Unchanged with no listener. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
|
Added two commits after measuring the cost with a listener active (new
Span names and attributes are now built once per message type, traced operations use a state tuple with static lambdas (no closures), and the extra async layer is gone. The tracing guide's "Cost" section shows these numbers. Still 128 tests passing. |
Tracing and metrics release: OpenTelemetry spans and a duration histogram through AnyMediatorDiagnostics, with no behavior change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
AnyMediator now emits OpenTelemetry-compatible spans and a duration histogram through .NET's own
ActivitySourceandMeter: no new dependency, nothing recorded until something subscribes.AnyMediatorDiagnosticswithActivitySourceNameandMeterName(minor version bump at release: 2.2.0).send {Request},create_stream {Request}(open until the stream is read, fails or is abandoned),publish {Notification}with onehandle {Notification}child per handler. Attributes:anymediator.operation,anymediator.message.type,anymediator.handler.type. Failures setErrorstatus,error.typeand anexceptionevent per the OpenTelemetry conventions.anymediator.operation.durationhistogram (seconds) by operation, message type anderror.type.Sendunchanged at 93 ns / 96 B;Publish196 → 207 ns, same allocations.llms.txtentry.Tests
TelemetryTests, usingActivityListener/MeterListener: send span and duration, failure recording, publish span with per-handler children, stream span lifetime). Ran the suite 4 times to check stability, since listeners are process-wide.🤖 Generated with Claude Code