Last active
November 13, 2025 15:18
-
-
Save kyletaylored/44a4a0d86cc0ec1b9634b06f7af7dbc6 to your computer and use it in GitHub Desktop.
Umbraco Datadog Header Propagation for APM Tracing
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
| <PackageReference Include="Microsoft.AspNetCore.HeaderPropagation" Version="9.0.10" /> |
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
| WebApplicationBuilder builder = WebApplication.CreateBuilder(args); | |
| builder.CreateUmbracoBuilder() | |
| .AddBackOffice() | |
| .AddWebsite() | |
| .AddComposers() | |
| .Build(); | |
| WebApplication app = builder.Build(); | |
| await app.BootUmbracoAsync(); | |
| // Enable header propagation middleware to capture incoming trace headers | |
| app.UseHeaderPropagation(); | |
| app.UseUmbraco() | |
| .WithMiddleware(u => | |
| { | |
| u.UseBackOffice(); | |
| u.UseWebsite(); | |
| }) | |
| .WithEndpoints(u => | |
| { | |
| u.UseBackOfficeEndpoints(); | |
| u.UseWebsiteEndpoints(); | |
| }); | |
| await app.RunAsync(); |
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
| using Umbraco.Cms.Core.Composing; | |
| using Umbraco.Cms.Core.DependencyInjection; | |
| namespace DatadogUmbraco.Composers | |
| { | |
| public class TracingComposer : IComposer | |
| { | |
| public void Compose(IUmbracoBuilder builder) | |
| { | |
| // Configure header propagation for Datadog trace context | |
| builder.Services.AddHeaderPropagation(options => | |
| { | |
| // Datadog trace headers | |
| options.Headers.Add("x-datadog-trace-id"); | |
| options.Headers.Add("x-datadog-parent-id"); | |
| options.Headers.Add("x-datadog-sampling-priority"); | |
| options.Headers.Add("x-datadog-origin"); | |
| options.Headers.Add("x-datadog-tags"); | |
| // W3C trace context headers | |
| options.Headers.Add("traceparent"); | |
| options.Headers.Add("tracestate"); | |
| }); | |
| // Configure all HttpClient instances to use header propagation | |
| builder.Services.ConfigureHttpClientDefaults(http => | |
| { | |
| http.AddHeaderPropagation(); | |
| }); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment