Skip to main content
Source: Al0087PreferConstantAttributeAnalyzer.cs

Description

Attribute names used in SetTag() calls should reference constant fields instead of string literals to prevent typos and enable refactoring.

Bad Code

activity?.SetTag("http.request.method", method);
activity?.SetTag("http.response.status_code", statusCode);

Good Code

activity?.SetTag(SemanticConventions.HttpRequestMethod, method);
activity?.SetTag(SemanticConventions.HttpResponseStatusCode, statusCode);

Properties

  • Category: OpenTelemetry
  • Severity: Info
  • Enabled by default: True
  • Code fix available: False

Configuration

dotnet_diagnostic.AL0087.severity = suggestion