Skip to content

Tags, Baggage, and Parameter Attributes

Stable Telemetry SourceGenerator Reviewed 2026-09-27 purview-dev/telemetry-sourcegenerator 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

Parameters on telemetry methods can be decorated to control how they are emitted. This page covers the parameter-level attributes.

Used within Activity and Metrics generation to add a parameter as a tag. Tag names follow the configured NamingConvention:

  • OpenTelemetry (default): snake_case for compound words (e.g. "entity_id")
  • Legacy: lowercased, smashed (e.g. "entityid")
PropertyTypeDefaultDescription
Namestring?nullExplicitly sets the tag name. When null, the parameter name is used (transformed according to the naming convention).
SkipOnNullOrEmptyboolfalseWhen true, the tag is not added if the parameter value is null or default.
using Purview.Telemetry;
[ActivitySource("OrderService")]
interface IOrderTelemetry
{
[Activity]
Activity? ProcessingOrder(
// Auto-named tag (becomes "order_id" in OpenTelemetry mode)
[Tag]int orderId,
// Explicitly named tag (explicit names are not transformed)
[Tag(Name = "customer.name")]string customerName,
// Skip if null
[Tag(SkipOnNullOrEmpty = true)]string? notes
);
}

OpenTelemetry convention (default):

[Tag]int orderId // Generated: "order_id"
[Tag]string userName // Generated: "user_name"
[Tag(Name = "my.custom.tag")]int value // Generated: "my.custom.tag" (not transformed)

Legacy convention:

[Tag]int orderId // Generated: "orderid"
[Tag]string userName // Generated: "username"

To change the convention, see Naming conventions.

  1. Use explicit names for cross-service tags to prevent breakage if parameter names change:

    [Tag(Name = "trace.id")]string traceId
  2. Use SkipOnNullOrEmpty for optional tags to avoid cluttering telemetry with null values:

    [Tag(SkipOnNullOrEmpty = true)]string? optionalContext
  3. Follow OpenTelemetry semantic conventions for standard names such as http.method, http.status_code, service.name.

Marks a parameter as baggage on an Activity or ActivityEvent. Baggage propagates across service boundaries, unlike tags.

PropertyTypeDefaultDescription
Namestring?nullExplicitly sets the baggage name. When null, the parameter name is used.
SkipOnNullOrEmptyboolfalseWhen true, the parameter is skipped when null or default.

Excludes a parameter from specific telemetry targets. See Multi-Targeting for the Targets enum values (None, Activities, Logging, Metrics, All).

PropertyTypeDescription
ExcludedTargetsTargetsThe targets to exclude the parameter from. Available on construction.
[ExcludeTargets(Targets.Metrics)]
string verboseMessage; // excluded from metrics only

The parameter stays part of the generated method signature, but it is not applied to the excluded target: for the Activities target that means it is not set as a tag, not added as baggage, and not used as a reserved parameter such as tags, parentContext, startTime, or [Escape]. Excluding it from Activities also stops the Activities-specific diagnostics (TSG3000, TSG3003–TSG3011, TSG3016, TSG3017, TSG3021) for that parameter.

Applied to an array or IEnumerable parameter on a log method, it logs the individual elements. See Logging Generation v2.

PropertyTypeDefaultDescription
MaximumValueCountint5The maximum number of elements to output from the enumeration/array.

Marks the parameter used as the instrument measurement value on a metrics method. See Metrics.

Marks a bool parameter as the escape value for an exception event on an Event method. See Activities.

Marks a string parameter as the status description for an Event that sets an error status code. See Activities.