diff --git a/_posts/2026-05-15-service-composer-telemetry.md b/_posts/2026-05-15-service-composer-telemetry.md new file mode 100644 index 00000000..ffce33ea --- /dev/null +++ b/_posts/2026-05-15-service-composer-telemetry.md @@ -0,0 +1,35 @@ +--- +layout: post +title: "ServiceComposer 5.2 OpenTelemetry support" +author: Mauro Servienti +synopsis: "OpenTelemetry tracing is one of those things you don't want until you need it. With version 5.2, ServiceComposer integrates with ASP.NET tracing adding relevant information to the ASP.NET spans" +header_image: /img/posts/service-composer-telemetry/header.jpg +tags: +- soa +- viewmodel-composition +--- + +This is going to be a quick one—ServiceComposer [5.2.0](https://github.com/ServiceComposer/ServiceComposer.AspNetCore/releases/tag/5.2.0) introduced support for OpenTelemetry. + +More details on the [OpenTelemetry documentation page](https://github.com/ServiceComposer/ServiceComposer.AspNetCore/blob/master/docs/open-telemetry.md). + +Tracing can be enabled for composition or scatter/gather: + +```csharp +builder.Services.AddOpenTelemetry() + .WithTracing(b => b + .AddSource("ServiceComposer.AspNetCore.ViewModelComposition") + .AddSource("ServiceComposer.AspNetCore.ScatterGather")); +``` + +Each `ICompositionRequestsHandler` execution produces a child span of the ASP.NET Core HTTP server span. When a handler raises an event via `context.RaiseEvent()`, the event handling produces a child span of the raising handler's span. When a handler or event handler throws, the span sets `ActivityStatusCode.Error`, adds tags, and an exception span event following the [OTel exception conventions](https://opentelemetry.io/docs/reference/specification/trace/semantic_conventions/exceptions/). + +On a smaller scale, when using [scatter/gather](https://milestone.topics.it/2026/03/12/scatter-gather.html), each `IGatherer` execution produces a child span of the ASP.NET Core HTTP server span. When a gatherer throws, the span sets `ActivityStatusCode.Error` with the same `otel.status_code`, `otel.status_description` tags, and exception span event as the composition process does. + +## Conclusion + +I've wanted OpenTelemetry support for a very long time, and finally it landed. + +--- + +Photo by Arturo Añez on Unsplash diff --git a/img/posts/service-composer-telemetry/header.jpg b/img/posts/service-composer-telemetry/header.jpg new file mode 100644 index 00000000..8da1c9cd Binary files /dev/null and b/img/posts/service-composer-telemetry/header.jpg differ