sains1.OtelSemConvAnalyzer 0.0.1

dotnet add package sains1.OtelSemConvAnalyzer --version 0.0.1
                    
NuGet\Install-Package sains1.OtelSemConvAnalyzer -Version 0.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="sains1.OtelSemConvAnalyzer" Version="0.0.1">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="sains1.OtelSemConvAnalyzer" Version="0.0.1" />
                    
Directory.Packages.props
<PackageReference Include="sains1.OtelSemConvAnalyzer">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add sains1.OtelSemConvAnalyzer --version 0.0.1
                    
#r "nuget: sains1.OtelSemConvAnalyzer, 0.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package sains1.OtelSemConvAnalyzer@0.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=sains1.OtelSemConvAnalyzer&version=0.0.1
                    
Install as a Cake Addin
#tool nuget:?package=sains1.OtelSemConvAnalyzer&version=0.0.1
                    
Install as a Cake Tool

OpenTelemetry Semantic Conventions Roslyn Analyzer for .NET

A Roslyn analyzer that enforces OpenTelemetry semantic conventions at compile-time for .NET projects. This analyzer validates attribute names and types when using Activity.SetTag(), Activity.AddTag(), and Span.SetAttribute() methods.

Diagnostic Rules

Rule ID Description Default Severity
OTEL0001 Invalid attribute name Error
OTEL0002 Type mismatch Error
OTEL0003 Experimental attribute Info
OTEL0004 Deprecated attribute Warning

Getting Started

1. Install Nuget package

Install the analyzer via NuGet:

dotnet add package sains1.OtelSemConvAnalyzer

Or add to your .csproj:

<ItemGroup>
  <PackageReference Include="sains1.OtelSemConvAnalyzer" Version="1.0.0">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
  </PackageReference>
</ItemGroup>

2. Generate semantic conventions output

We use weaver for code generation to output our semantic convention files.

In ./otel-semconv-generator/ is our example weaver setup.

  • 2.1 Clone the contents of ./otel-semconv-generator/ to your project

  • 2.2 Within ./otel-semconv-generator/ clone the semantic conventions repo

cd ./otel-semconv-generator/
git clone https://github.com/open-telemetry/semantic-conventions
  • 2.3 Run the code generation
make generate

This generates:

  • OtelAttributes.cs - Constants for use in your code
  • otel-attributes-metadata.json - Metadata for the analyzer

OtellAttributes should be copied into your project and used as follows:

using var activity = Otel.ActivitySource.StartActivity();
activity?.SetTag(OtelAttributes.MYAPP_ACTIVITY_LOG_ENTRY_COUNT, 123);

otel-attributes-metadata.json should be copied into your project and is used by the analyzer

3. Configure the analyzer metadata file

Copy the metadata file into your project and add the following:


  <ItemGroup>
    
    <AdditionalFiles Include="otel-attributes-metadata.json" />
  </ItemGroup>

4. Optionally configure the analyzer severity within your .editorconfig

# OpenTelemetry Semantic Convention Analyzer Rules

# OTEL0001: Invalid attribute name
# Severity: error (default), warning, suggestion, silent, none
dotnet_diagnostic.OTEL0001.severity = error

# OTEL0002: Type mismatch
# Severity: error (default), warning, suggestion, silent, none
dotnet_diagnostic.OTEL0002.severity = error

# OTEL0003: Experimental attribute usage
# Severity: suggestion (default), error, warning, silent, none
dotnet_diagnostic.OTEL0003.severity = suggestion

# OTEL0004: Deprecated attribute usage
# Severity: warning (default), error, suggestion, silent, none
dotnet_diagnostic.OTEL0004.severity = warning

After a build you should see any warnings/errors directly in your IDE and in the build output:

error example

Resources

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.1 238 11/15/2025