Installation
Installation
Section titled “Installation”This page covers supported frameworks, installation methods, per-feature dependencies, and build configuration for the Purview.Telemetry.SourceGenerator package.
Supported frameworks
Section titled “Supported frameworks”Consumer runtime targets:
- .NET Framework 4.8
- .NET 8 or higher, including .NET 11
Build toolchain requirement:
- Visual Studio 2026 (18.x) or the .NET 10 SDK or later (Roslyn 5.9.0+)
The generator itself is a Roslyn component targeting netstandard2.0, so it works in any supported compiler host. See Platform Support and .NET 11 for the hosting models (Native AOT, Blazor WebAssembly, Blazor Server, Aspire) and the trim/AOT guarantees.
Install the package
Section titled “Install the package”.NET CLI
Section titled “.NET CLI”dotnet add package Purview.Telemetry.SourceGeneratorPackage Manager Console
Section titled “Package Manager Console”Install-Package Purview.Telemetry.SourceGeneratorProject file (.csproj or Directory.Build.props)
Section titled “Project file (.csproj or Directory.Build.props)”<PackageReference Include="Purview.Telemetry.SourceGenerator"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>analyzers</IncludeAssets></PackageReference>PrivateAssets="all" keeps the generator out of consumers’ dependencies and IncludeAssets="analyzers" treats it purely as an analyzer.
Runtime dependencies
Section titled “Runtime dependencies”| Telemetry type | Required reference | Notes |
|---|---|---|
| Activities | System.Diagnostics.DiagnosticSource | Included in the SDK for .NET 5+ |
| Logging | Microsoft.Extensions.Logging.Abstractions | Required for [Logger] interfaces; TSG2003 is raised if ILogger cannot be resolved. Part of the shared framework on .NET 11, so no reference is needed there (an explicit one reports NU1510) |
| Logging (v2) | Microsoft.Extensions.Telemetry.Abstractions | Required for state-based v2 generation (LoggerMessageHelper, [LogProperties]) |
| Metrics | System.Diagnostics.Metrics | Included in the SDK for .NET 8+ |
Activities from ActivitySourceFactory (opt-in) | Microsoft.Extensions.Diagnostics 11 (services.AddTracing()) | Only with UseActivitySourceFactory; see Activities |
Verifying the install
Section titled “Verifying the install”Create an interface with a telemetry attribute and build:
using Purview.Telemetry;
[Logger]interface IMyTelemetry{ [Info] void Hello();}If generation succeeds you will see a MyTelemetryCore implementation and an AddMyTelemetry extension method. To inspect the generated code, enable:
<PropertyGroup> <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles></PropertyGroup>Generated files land in obj/Debug|Release/<tfm>/generated/Purview.Telemetry.SourceGenerator/Purview.Telemetry.SourceGenerator.TelemetrySourceGenerator/.
Build configuration
Section titled “Build configuration”PURVIEW_TELEMETRY_ATTRIBUTES
Section titled “PURVIEW_TELEMETRY_ATTRIBUTES”Marker attributes are generated as [Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] and are internal to your assembly. Define this constant if you want to retain them in your build (for example, so the analyzer sees attribute usage in projects that share attribute source):
<PropertyGroup> <DefineConstants>$(DefineConstants);PURVIEW_TELEMETRY_ATTRIBUTES</DefineConstants></PropertyGroup>EXCLUDE_PURVIEW_TELEMETRY_LOGGING
Section titled “EXCLUDE_PURVIEW_TELEMETRY_LOGGING”Define this constant to disable logging generation entirely. This is useful when the Microsoft.Extensions.Logging types are not available in the compilation:
<PropertyGroup> <DefineConstants>$(DefineConstants);EXCLUDE_PURVIEW_TELEMETRY_LOGGING</DefineConstants></PropertyGroup>Unsupported target frameworks
Section titled “Unsupported target frameworks”A compilation that targets neither net8.0+ nor net48+ (for example netstandard2.0) reports
TSG1011 and generates nothing. No define suppresses it. A library that
keeps such a target references the package only from its supported targets, and puts its telemetry
interfaces under the same condition:
<PackageReference Include="Purview.Telemetry.SourceGenerator" Condition="'$(TargetFramework)' != 'netstandard2.0'"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>analyzers</IncludeAssets></PackageReference>Project-type snippets
Section titled “Project-type snippets”ASP.NET Core
Section titled “ASP.NET Core”builder.Services.AddWeatherServiceTelemetry();Console / library
Section titled “Console / library”services.AddOrderServiceTelemetry();.NET Aspire
Section titled “.NET Aspire”Opt the host project into the TelemetryNames class — it aggregates the names of every assembly it references — then pass the arrays into ServiceDefaults:
[assembly: TelemetryGeneration(GenerateTelemetryNamesClass = true)]builder.AddServiceDefaults(TelemetryNames.MeterNames, TelemetryNames.ActivitySourceNames);See the sample application for a complete Aspire setup on .NET 10.
Troubleshooting
Section titled “Troubleshooting”“Type or namespace ‘ActivitySourceAttribute’ could not be found”
- Ensure
using Purview.Telemetry;is present (all attributes live in the singlePurview.Telemetrynamespace). - Check the package reference includes
IncludeAssets="analyzers".
“No implementation found for interface”
- Verify the interface has at least one of
[ActivitySource],[Logger], or[Meter]. - Check that methods have the appropriate method-level attributes.
- Rebuild to trigger source generation.
“ActivitySource not producing traces”
- Ensure the generated
Add{InterfaceName}()DI registration method has been called. - Configure OpenTelemetry to listen to your ActivitySource name.
“Logs not appearing”
- Verify
ILoggeris configured in your application. - Check that log-level filters are not excluding your messages.
- Ensure DI registration was called.
“Metrics not collected”
- Configure a metrics exporter in your application.
- Verify the meter name matches what your collector expects.
- Confirm instruments are recorded with valid measurement values.
Next steps
Section titled “Next steps”- Getting Started — write your first telemetry interface
- Generation Options — control class names, DI, and naming
- Diagnostics — analyzer warnings and errors