Skip to content

[Infra] Add factory for ActivitySource and Meter#4079

Merged
martincostello merged 2 commits intoopen-telemetry:mainfrom
martincostello:gh-4064-add-telemetry-factories
Apr 9, 2026
Merged

[Infra] Add factory for ActivitySource and Meter#4079
martincostello merged 2 commits intoopen-telemetry:mainfrom
martincostello:gh-4064-add-telemetry-factories

Conversation

@martincostello
Copy link
Copy Markdown
Member

Contributes to #4064.

Changes

Add shared code to minimise duplication when creating instances of ActivitySource and Meter to help ensure that telemetry schema URLs are set.

While working on #4078 I realised that there was a lot of duplication starting to happen, so this centralises that code and adopts it for use for AspNet and SqlClient instrumentation which are the only two that currently set TelemetrySchemaUrl.

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)

Add shared code to minimise duplication when creating instances of `ActivitySource` and `Meter` to help ensure that telemetry schema URLs are set.

Contributes to open-telemetry#4064.
@github-actions github-actions bot added comp:instrumentation.aspnet Things related to OpenTelemetry.Instrumentation.AspNet comp:instrumentation.sqlclient Things related to OpenTelemetry.Instrumentation.SqlClient labels Apr 8, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.69%. Comparing base (4f1d56b) to head (be295fb).
⚠️ Report is 3 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4079      +/-   ##
==========================================
- Coverage   72.71%   72.69%   -0.02%     
==========================================
  Files         458      460       +2     
  Lines       17876    17875       -1     
==========================================
- Hits        12998    12995       -3     
- Misses       4878     4880       +2     
Flag Coverage Δ
unittests-Contrib.Shared.Tests 89.74% <100.00%> (-0.02%) ⬇️
unittests-Exporter.Geneva 54.82% <ø> (-0.02%) ⬇️
unittests-Exporter.InfluxDB 95.81% <ø> (ø)
unittests-Exporter.Instana 74.86% <ø> (ø)
unittests-Exporter.OneCollector 94.61% <ø> (ø)
unittests-Extensions 90.65% <ø> (ø)
unittests-Extensions.Enrichment 100.00% <ø> (ø)
unittests-Extensions.Enrichment.AspNetCore 86.27% <ø> (ø)
unittests-Extensions.Enrichment.Http 94.33% <ø> (ø)
unittests-Instrumentation.AWS 83.54% <ø> (ø)
unittests-Instrumentation.AspNet 76.61% <100.00%> (-0.76%) ⬇️
unittests-Instrumentation.AspNetCore 70.44% <ø> (ø)
unittests-Instrumentation.Cassandra 23.52% <ø> (ø)
unittests-Instrumentation.ConfluentKafka 39.83% <ø> (ø)
unittests-Instrumentation.ElasticsearchClient 80.60% <ø> (ø)
unittests-Instrumentation.EntityFrameworkCore 80.80% <ø> (ø)
unittests-Instrumentation.EventCounters 77.27% <ø> (ø)
unittests-Instrumentation.GrpcCore 91.42% <ø> (ø)
unittests-Instrumentation.GrpcNetClient 73.78% <ø> (ø)
unittests-Instrumentation.Hangfire 86.05% <ø> (ø)
unittests-Instrumentation.Http 74.62% <ø> (ø)
unittests-Instrumentation.Owin 88.62% <ø> (ø)
unittests-Instrumentation.Process 100.00% <ø> (ø)
unittests-Instrumentation.Quartz 78.76% <ø> (ø)
unittests-Instrumentation.Runtime 100.00% <ø> (ø)
unittests-Instrumentation.ServiceFabricRemoting 34.68% <ø> (ø)
unittests-Instrumentation.SqlClient 85.21% <100.00%> (-0.54%) ⬇️
unittests-Instrumentation.StackExchangeRedis 71.98% <ø> (ø)
unittests-Instrumentation.Wcf 79.68% <ø> (ø)
unittests-OpAmp.Client 78.99% <ø> (-0.13%) ⬇️
unittests-PersistentStorage 68.19% <ø> (ø)
unittests-Resources.AWS 74.34% <ø> (ø)
unittests-Resources.Azure 85.31% <ø> (ø)
unittests-Resources.Container 67.34% <ø> (ø)
unittests-Resources.Gcp 71.42% <ø> (ø)
unittests-Resources.Host 72.26% <ø> (ø)
unittests-Resources.OperatingSystem 76.98% <ø> (ø)
unittests-Resources.Process 100.00% <ø> (ø)
unittests-Resources.ProcessRuntime 79.59% <ø> (ø)
unittests-Sampler.AWS 94.28% <ø> (ø)

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

Files with missing lines Coverage Δ
...ry.Instrumentation.AspNet/AspNetInstrumentation.cs 93.75% <100.00%> (-3.03%) ⬇️
...ion.SqlClient/Implementation/SqlTelemetryHelper.cs 94.23% <100.00%> (-1.30%) ⬇️
src/Shared/ActivitySourceFactory.cs 100.00% <100.00%> (ø)
src/Shared/MeterFactory.cs 100.00% <100.00%> (ø)

... and 3 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.

Update namespace for shared tests.
@martincostello martincostello marked this pull request as ready for review April 8, 2026 16:55
@martincostello martincostello requested a review from a team as a code owner April 8, 2026 16:55
Copilot AI review requested due to automatic review settings April 8, 2026 16:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds shared factory helpers for creating ActivitySource and Meter instances with a consistent telemetry schema URL, and adopts the new helpers in the ASP.NET and SqlClient instrumentations to reduce duplication and standardize schema URL application (contributing to #4064).

Changes:

  • Added ActivitySourceFactory and MeterFactory shared helpers to centralize name/version/schema URL construction.
  • Updated ASP.NET and SqlClient instrumentations to use the new factories instead of inline construction.
  • Added unit tests validating that factories set name/version and TelemetrySchemaUrl as expected.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/OpenTelemetry.Contrib.Shared.Tests/OpenTelemetry.Contrib.Shared.Tests.csproj Links new shared helper sources into the shared test project.
test/OpenTelemetry.Contrib.Shared.Tests/MeterFactoryTests.cs Adds coverage for MeterFactory name/version/schema URL behavior.
test/OpenTelemetry.Contrib.Shared.Tests/ActivitySourceFactoryTests.cs Adds coverage for ActivitySourceFactory name/version/schema URL behavior.
src/Shared/MeterFactory.cs Introduces centralized Meter creation with schema URL + package version.
src/Shared/ActivitySourceFactory.cs Introduces centralized ActivitySource creation with schema URL + package version.
src/OpenTelemetry.Instrumentation.SqlClient/OpenTelemetry.Instrumentation.SqlClient.csproj Includes the new shared factory sources in SqlClient instrumentation build.
src/OpenTelemetry.Instrumentation.SqlClient/Implementation/SqlTelemetryHelper.cs Switches telemetry construction to factories and centralizes schema version as a Version.
src/OpenTelemetry.Instrumentation.AspNet/OpenTelemetry.Instrumentation.AspNet.csproj Includes the new shared factory sources in ASP.NET instrumentation build.
src/OpenTelemetry.Instrumentation.AspNet/AspNetInstrumentation.cs Switches telemetry construction to factories and centralizes schema version as a Version.
opentelemetry-dotnet-contrib.slnx Adds the new shared files to the solution listing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@martincostello martincostello added this pull request to the merge queue Apr 9, 2026
Merged via the queue into open-telemetry:main with commit 0ecb0b2 Apr 9, 2026
332 of 333 checks passed
@martincostello martincostello deleted the gh-4064-add-telemetry-factories branch April 9, 2026 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:instrumentation.aspnet Things related to OpenTelemetry.Instrumentation.AspNet comp:instrumentation.sqlclient Things related to OpenTelemetry.Instrumentation.SqlClient

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants