Skip to content
Purview Dev logo

Installation

Stable Telemetry SourceGenerator Reviewed 2026-10-28 purview-dev/telemetry-sourcegenerator Star on GitHub 36 activity c-sharp distributed-tracing dotnet events high-performance-logging instrumentation logging melt metrics nuget observability open-telemetry open-telemetry-csharp otel roslyn source-generator spans telemetry tracing

This page covers supported frameworks, installation methods, per-feature dependencies, and build configuration for the Purview.Telemetry.SourceGenerator package.

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.

Terminal window
dotnet add package Purview.Telemetry.SourceGenerator
Terminal window
Install-Package Purview.Telemetry.SourceGenerator

Project 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.

Telemetry typeRequired referenceNotes
ActivitiesSystem.Diagnostics.DiagnosticSourceIncluded in the SDK for .NET 5+
LoggingMicrosoft.Extensions.Logging.AbstractionsRequired 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.AbstractionsRequired for state-based v2 generation (LoggerMessageHelper, [LogProperties])
MetricsSystem.Diagnostics.MetricsIncluded in the SDK for .NET 8+
Activities from ActivitySourceFactory (opt-in)Microsoft.Extensions.Diagnostics 11 (services.AddTracing())Only with UseActivitySourceFactory; see Activities

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/.

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>

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>

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>
builder.Services.AddWeatherServiceTelemetry();
services.AddOrderServiceTelemetry();

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.

“Type or namespace ‘ActivitySourceAttribute’ could not be found”

  • Ensure using Purview.Telemetry; is present (all attributes live in the single Purview.Telemetry namespace).
  • 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 ILogger is 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.