[Infra] Add factory for ActivitySource and Meter#4079
[Infra] Add factory for ActivitySource and Meter#4079martincostello merged 2 commits intoopen-telemetry:mainfrom
Conversation
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.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ 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 Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Update namespace for shared tests.
There was a problem hiding this comment.
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
ActivitySourceFactoryandMeterFactoryshared 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
TelemetrySchemaUrlas 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.
0ecb0b2
Contributes to #4064.
Changes
Add shared code to minimise duplication when creating instances of
ActivitySourceandMeterto 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
AppropriateCHANGELOG.mdfiles updated for non-trivial changesChanges in public API reviewed (if applicable)