-
Notifications
You must be signed in to change notification settings - Fork 2
Installation
This guide covers installing and configuring the Purview Telemetry Source Generator in your project.
- .NET 8.0 or higher (Recommended)
- .NET Framework 4.8 or higher
- Visual Studio 2022 (17.0 or higher)
- Visual Studio Code with C# extension
- JetBrains Rider 2022.3 or higher
- Any IDE with Roslyn analyzer support
dotnet add package Purview.Telemetry.SourceGenerator --version 4.1.0Install-Package Purview.Telemetry.SourceGenerator -Version 4.1.0Add directly to your .csproj file:
<ItemGroup>
<PackageReference Include="Purview.Telemetry.SourceGenerator" Version="4.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>Important
The <PrivateAssets>all</PrivateAssets> and <IncludeAssets>analyzers</IncludeAssets> tags ensure the source generator is used during compilation but not included in your published output.
For solutions with multiple projects that all need telemetry, create or edit Directory.Build.props at the solution root:
<Project>
<ItemGroup>
<PackageReference Include="Purview.Telemetry.SourceGenerator" Version="4.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>This automatically adds the package to all projects in the solution.
Create a file ITelemetryTest.cs:
using Purview.Telemetry;
[Logger]
public interface ITelemetryTest
{
[Info]
void TestMessage(string message);
}dotnet buildIf EmitCompilerGeneratedFiles is enabled (see below), check:
obj/Debug/net8.0/generated/Purview.Telemetry.SourceGenerator/
You should see generated files with names like:
{Namespace}.TelemetryTestCore.Logging.g.cs{Namespace}.TelemetryTestCoreDIExtension.DependencyInjection.g.cs
In your Program.cs:
services.AddTelemetryTest(); // This should have IntelliSense supportIf IntelliSense recognizes AddTelemetryTest(), installation was successful! ✅
To inspect generated code during development, add to your .csproj:
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)/generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>Generated files appear in obj/Debug/net8.0/generated/.
To include source generator attributes in your assembly (usually not needed):
<PropertyGroup>
<DefineConstants>PURVIEW_TELEMETRY_ATTRIBUTES</DefineConstants>
</PropertyGroup>By default, attributes are marked [Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] and are removed at runtime.
If Microsoft.Extensions.Logging is not available in your project:
<PropertyGroup>
<DefineConstants>EXCLUDE_PURVIEW_TELEMETRY_LOGGING</DefineConstants>
</PropertyGroup>This excludes logging-related attributes and code generation.
The source generator itself has no runtime dependencies. However, to use the generated code, you need:
# .NET 5.0+ (included in SDK)
# No additional packages neededdotnet add package Microsoft.Extensions.Logging
dotnet add package Microsoft.Extensions.Telemetry.Abstractionsdotnet add package Microsoft.Extensions.Logging# .NET 8.0+ (included in SDK)
# No additional packages needed for IMeterFactoryTo export telemetry to observability platforms:
# Core packages
dotnet add package OpenTelemetry.Extensions.Hosting
dotnet add package OpenTelemetry.Exporter.Console
# Optional: Specific exporters
dotnet add package OpenTelemetry.Exporter.Jaeger
dotnet add package OpenTelemetry.Exporter.Prometheus.AspNetCore
dotnet add package Azure.Monitor.OpenTelemetry.Exporter<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Purview.Telemetry.SourceGenerator" Version="4.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project><Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Purview.Telemetry.SourceGenerator" Version="4.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project><Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Purview.Telemetry.SourceGenerator" Version="4.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project><Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Aspire.Hosting" Version="8.0.0" />
<PackageReference Include="Purview.Telemetry.SourceGenerator" Version="4.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>See the Sample Application for a complete .NET Aspire example.
If your project targets multiple frameworks:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net48</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Purview.Telemetry.SourceGenerator" Version="4.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
<!-- Conditional dependencies for older frameworks -->
<ItemGroup Condition="'$(TargetFramework)' == 'net48'">
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="8.0.0" />
</ItemGroup>
</Project>- Install latest Visual Studio 2022 (17.8 or higher recommended)
- Ensure "Source Generators" support is enabled (on by default)
- After adding the package, rebuild to trigger generation
- Generated files appear in Solution Explorer under Dependencies > Analyzers > Purview.Telemetry.SourceGenerator
- Install the C# extension (ms-dotnettools.csharp)
- Ensure the latest .NET SDK is installed
- Open the project folder
- Run
dotnet buildfrom the terminal - IntelliSense should recognize generated types after build
- Install Rider 2022.3 or higher
- Rider automatically detects source generators
- After adding the package, rebuild the solution
- Generated types appear in IntelliSense immediately
Cause: Package not installed or build not run.
Solution:
dotnet restore
dotnet buildCause: Source generator didn't run or interface not properly annotated.
Solution:
- Ensure the interface has
[ActivitySource],[Logger], or[Meter]attribute - Rebuild:
dotnet build --no-incremental - Check for build errors in the output
Cause: EmitCompilerGeneratedFiles not enabled.
Solution: Add to .csproj:
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>Cause: Incompatible package version or corrupted NuGet cache.
Solution:
# Clear NuGet cache
dotnet nuget locals all --clear
# Restore packages
dotnet restore
# Clean and rebuild
dotnet clean
dotnet buildCause: IDE hasn't detected the generator yet.
Solution:
- Rebuild the project:
dotnet build - Restart the IDE
- Check the package is correctly referenced in
.csproj
Cause: Package referenced multiple times or in multiple Directory.Build.props files.
Solution: Remove duplicate references and ensure the package is only included once per project.
If you're upgrading from v3.x to v4.x:
<!-- Before -->
<PackageReference Include="Purview.Telemetry.SourceGenerator" Version="4.1.0" />
<!-- After -->
<PackageReference Include="Purview.Telemetry.SourceGenerator" Version="4.1.0" />// Before (v3)
using Purview.Telemetry.Activities;
using Purview.Telemetry.Logging;
using Purview.Telemetry.Metrics;
// After (v4)
using Purview.Telemetry; // Single namespace!See the Breaking Changes guide for:
- Namespace consolidation details
- OpenTelemetry naming conventions (default in v4)
- Migration paths and compatibility options
Run this checklist to confirm everything is working:
- Package installed (
dotnet list packageshows it) - Project builds without errors (
dotnet build) - IntelliSense recognizes
using Purview.Telemetry; - Test interface compiles successfully
- Generated DI extension method appears in IntelliSense
- Application runs and telemetry is emitted
- Quick Start - Build your first telemetry interface in 5 minutes
- Getting Started - Comprehensive walkthrough with examples
- Sample Application - Explore the full .NET Aspire sample
- Breaking Changes - Migrating from v3 (if applicable)
| Version | Release Date | Notes |
|---|---|---|
| 4.0.0-prerelease.2 | 2026-02-14 | Added TelemetryNames generated classes |
| 4.0.0-prerelease.1 | 2026-02-08 | OTel-aligned naming across MELT |
| 4.0.0-prerelease.0 | 2026-02-08 | Namespace consolidation, OTel naming conventions |
| 3.2.4 | 2025-07-27 | Last stable v3 release |
See the CHANGELOG for complete version history.
Important
Consider helping children around the world affected by conflict. You can donate any amount to War Child here - any amount can help save a life.
Purview Telemetry Source Generator v4.0.0-prerelease.1 | Home | Getting Started | FAQ | Breaking Changes | GitHub