sains1.OtelSemConvAnalyzer
0.0.1
dotnet add package sains1.OtelSemConvAnalyzer --version 0.0.1
NuGet\Install-Package sains1.OtelSemConvAnalyzer -Version 0.0.1
<PackageReference Include="sains1.OtelSemConvAnalyzer" Version="0.0.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="sains1.OtelSemConvAnalyzer" Version="0.0.1" />
<PackageReference Include="sains1.OtelSemConvAnalyzer"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add sains1.OtelSemConvAnalyzer --version 0.0.1
#r "nuget: sains1.OtelSemConvAnalyzer, 0.0.1"
#:package sains1.OtelSemConvAnalyzer@0.0.1
#addin nuget:?package=sains1.OtelSemConvAnalyzer&version=0.0.1
#tool nuget:?package=sains1.OtelSemConvAnalyzer&version=0.0.1
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 project2.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 codeotel-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:
Resources
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 |