Skip to content

Conversation

evgenyfedorov2
Copy link
Contributor

@evgenyfedorov2 evgenyfedorov2 commented Sep 8, 2025

Design discussion issue #4097.

Changes

Introducing the HTTP client trace enrichment component - OpenTelemetry.Extensions.Enrichment.Http

This is a framework for trace enrichment of outbound HTTP requests. Similar to OpenTelemetry.Extensions.Enrichment, it has an abstract class HttpClientTraceEnricher for .NET:

public abstract class HttpClientTraceEnricher
{
    public virtual void EnrichWithRequest(in TraceEnrichmentBag bag, HttpRequestMessage request) {}
    public virtual void EnrichWithResponse(in TraceEnrichmentBag bag, HttpResponseMessage response) {}
    public virtual void EnrichWithException(in TraceEnrichmentBag bag, Exception exception) {}
}

and for .NET Framework:

public abstract class HttpClientTraceEnricher
{
    public virtual void EnrichWithRequest(in TraceEnrichmentBag bag, HttpWebRequest request) {}
    public virtual void EnrichWithResponse(in TraceEnrichmentBag bag, HttpWebResponse response) {}
    public virtual void EnrichWithException(in TraceEnrichmentBag bag, Exception exception) {}
}

Internally, enrichment is done via the HttpClientTraceEnrichmentProcessor class, which hold references to all registered enrichers and calls Enrich*() methods on each of them.

Developers can add enrichers by calling extension methods either on TracerProviderBuilder or on IServiceCollection:

public static TracerProviderBuilder TryAddHttpClientTraceEnricher<T>(this TracerProviderBuilder builder) where T : HttpClientTraceEnricher;
public static TracerProviderBuilder TryAddHttpClientTraceEnricher(this TracerProviderBuilder builder, HttpClientTraceEnricher enricher);
public static TracerProviderBuilder TryAddHttpClientTraceEnricher<T>(this TracerProviderBuilder builder, Func<IServiceProvider, T> enricherImplementationFactory) where T : HttpClientTraceEnricher;
public static IServiceCollection TryAddHttpClientTraceEnricher<T>(this IServiceCollection services) where T : HttpClientTraceEnricher;
public static IServiceCollection TryAddHttpClientTraceEnricher(this IServiceCollection services, HttpClientTraceEnricher enricher);
public static IServiceCollection TryAddHttpClientTraceEnricher<T>(this IServiceCollection services, Func<IServiceProvider, T> enricherImplementationFactory) where T : HttpClientTraceEnricher;

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

@evgenyfedorov2 evgenyfedorov2 requested a review from a team as a code owner September 8, 2025 10:51
@github-actions github-actions bot added infra Infra work - CI/CD, code coverage, linters comp:extensions.enrichment.http Things related to OpenTelemetry.Extensions.Enrichment.Http labels Sep 8, 2025
Copy link

codecov bot commented Sep 8, 2025

Codecov Report

❌ Patch coverage is 94.33962% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.76%. Comparing base (de8dd86) to head (d7f82d8).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...s.Enrichment.Http/Trace/HttpClientTraceEnricher.cs 40.00% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3082      +/-   ##
==========================================
- Coverage   69.88%   69.76%   -0.12%     
==========================================
  Files         431      436       +5     
  Lines       16671    16724      +53     
==========================================
+ Hits        11651    11668      +17     
- Misses       5020     5056      +36     
Flag Coverage Δ
unittests-Contrib.Shared.Tests 83.73% <ø> (ø)
unittests-Exporter.Geneva 53.33% <ø> (-0.28%) ⬇️
unittests-Exporter.InfluxDB 95.14% <ø> (ø)
unittests-Exporter.Instana 74.86% <ø> (ø)
unittests-Exporter.OneCollector 94.61% <ø> (ø)
unittests-Extensions 90.65% <ø> (ø)
unittests-Extensions.Enrichment 100.00% <ø> (ø)
unittests-Extensions.Enrichment.AspNetCore 94.11% <ø> (ø)
unittests-Extensions.Enrichment.Http 94.33% <94.33%> (?)
unittests-Instrumentation.AWS 83.80% <ø> (ø)
unittests-Instrumentation.AspNet 74.93% <ø> (ø)
unittests-Instrumentation.AspNetCore 70.76% <ø> (ø)
unittests-Instrumentation.Cassandra 23.52% <ø> (ø)
unittests-Instrumentation.ConfluentKafka 14.10% <ø> (ø)
unittests-Instrumentation.ElasticsearchClient 80.12% <ø> (ø)
unittests-Instrumentation.EntityFrameworkCore 80.80% <ø> (ø)
unittests-Instrumentation.EventCounters 76.36% <ø> (ø)
unittests-Instrumentation.GrpcCore 91.42% <ø> (ø)
unittests-Instrumentation.GrpcNetClient 79.61% <ø> (ø)
unittests-Instrumentation.Hangfire 84.61% <ø> (ø)
unittests-Instrumentation.Http 74.18% <ø> (ø)
unittests-Instrumentation.Owin 88.62% <ø> (ø)
unittests-Instrumentation.Process 100.00% <ø> (ø)
unittests-Instrumentation.Quartz 78.76% <ø> (ø)
unittests-Instrumentation.Runtime 100.00% <ø> (ø)
unittests-Instrumentation.ServiceFabricRemoting 34.54% <ø> (ø)
unittests-Instrumentation.SqlClient 87.29% <ø> (ø)
unittests-Instrumentation.StackExchangeRedis 70.31% <ø> (ø)
unittests-Instrumentation.Wcf 78.95% <ø> (ø)
unittests-OpAmp.Client 68.10% <ø> (+0.93%) ⬆️
unittests-PersistentStorage 65.88% <ø> (-8.03%) ⬇️
unittests-Resources.AWS 74.42% <ø> (ø)
unittests-Resources.Azure 85.31% <ø> (ø)
unittests-Resources.Container 67.34% <ø> (ø)
unittests-Resources.Gcp 71.42% <ø> (ø)
unittests-Resources.Host 73.91% <ø> (ø)
unittests-Resources.OperatingSystem 76.98% <ø> (ø)
unittests-Resources.Process 100.00% <ø> (ø)
unittests-Resources.ProcessRuntime 79.59% <ø> (ø)
unittests-Sampler.AWS 88.25% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...HttpClientEnrichmentServiceCollectionExtensions.cs 100.00% <100.00%> (ø)
...ClientEnrichmentTracerProviderBuilderExtensions.cs 100.00% <100.00%> (ø)
.../ConfigureHttpClientTraceInstrumentationOptions.cs 100.00% <100.00%> (ø)
...ttp/Internal/HttpClientTraceEnrichmentProcessor.cs 100.00% <100.00%> (ø)
...s.Enrichment.Http/Trace/HttpClientTraceEnricher.cs 40.00% <40.00%> (ø)

... and 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@evgenyfedorov2 evgenyfedorov2 force-pushed the users/evgenyfedorov/add_http_trace_enrichment branch from 451ba96 to 4cb105a Compare September 8, 2025 13:01
@evgenyfedorov2
Copy link
Contributor Author

@Kielek @rajkumar-rangaraj could you please review this?

@evgenyfedorov2 evgenyfedorov2 changed the title Introduce HTTP client trace enrichment [Extensions.Enrichment.Http]Introduce HTTP client trace enrichment Sep 9, 2025
@evgenyfedorov2 evgenyfedorov2 changed the title [Extensions.Enrichment.Http]Introduce HTTP client trace enrichment [Extensions.Enrichment.Http] Introduce HTTP client trace enrichment Sep 9, 2025
Co-authored-by: Rajkumar Rangaraj <[email protected]>
@Kielek Kielek merged commit af0d4b8 into open-telemetry:main Sep 16, 2025
233 of 234 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:extensions.enrichment.http Things related to OpenTelemetry.Extensions.Enrichment.Http infra Infra work - CI/CD, code coverage, linters

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants