Diagnostics
Diagnostics
Section titled “Diagnostics”The package ships a single Roslyn analyzer, TelemetryDiagnosticAnalyzer, which validates telemetry interfaces and raises diagnostics with the TSG prefix. All diagnostics are grouped by category.
- General —
TSG1xxx - Logging —
TSG2xxx - Activities —
TSG3xxx - Metrics —
TSG4xxx
General diagnostics (TSG1xxx)
Section titled “General diagnostics (TSG1xxx)”| ID | Severity | Description |
|---|---|---|
TSG1000 | Error | Fatal execution error occurred (Failed to execute the generation stage: {0}). Raised by the generator itself when an unexpected exception escapes the pipeline. |
TSG1001 | Error | Inferring generation targets is not supported when using multi-target generation. A method on a multi-target interface has no explicit generation attribute. |
TSG1002 | Error | Multiple attributes from the same target family are not supported. Only one Activity, Logging, or Metrics attribute is allowed per method. |
TSG1003 | Error | Duplicate method names are not supported. Two or more methods on the interface share the same name. |
TSG1004 | Error | Generic interfaces are not supported. |
TSG1005 | Error | Generic methods are not supported. |
TSG1006 | Warning | ExcludeTargets references a target not present on this method. |
TSG1007 | Warning | ExcludeTargets results in an empty or invalid parameter set for a target. |
TSG1008 | Warning | Activity parameter has no Activity target. A parameter of type Activity is present on a method with no [Activity]/[Event]/[Context] attribute. |
TSG1010 | Error | Method target not registered on interface. A method carries an attribute for a target family that is not registered on the interface. |
TSG1011 | Error | Unsupported target framework. The compilation targets neither .NET 8+ nor .NET Framework 4.8+ (for example netstandard2.0), so no telemetry is generated for it. There is no opt-out. Target net8.0 or later, or net48 or later; a multi-targeted library references the package only from its supported targets (a Condition on the PackageReference), with the telemetry interfaces under the same condition. See Platform Support. |
Logging diagnostics (TSG2xxx)
Section titled “Logging diagnostics (TSG2xxx)”Activities diagnostics (TSG3xxx)
Section titled “Activities diagnostics (TSG3xxx)”Metrics diagnostics (TSG4xxx)
Section titled “Metrics diagnostics (TSG4xxx)”Common resolutions
Section titled “Common resolutions”TSG1001 — inference disabled on multi-target interfaces
Section titled “TSG1001 — inference disabled on multi-target interfaces”A method on a multi-target interface ([ActivitySource] + [Logger] + [Meter]) has no explicit attribute. Add the attributes for each target the method should emit, or mark it [Exclude].
[ActivitySource("MyApp")][Logger][Meter]interface IMyTelemetry{ [Info] // ✅ explicit target void ProcessItem(int id);}TSG1003 — duplicate method names
Section titled “TSG1003 — duplicate method names”Two or more methods share the same name, which is used to generate members on the implementation class. Rename the methods.
TSG2008 — unbounded enumeration
Section titled “TSG2008 — unbounded enumeration”[ExpandEnumerable] is configured with a MaximumValueCount greater than 5. Reduce it to the recommended default (5) unless you have tested the performance impact.
TSG3013 / TSG3014 — missing Activity
Section titled “TSG3013 / TSG3014 — missing Activity”An Activity method does not return the created Activity, or an Event/Context method has no Activity parameter. Return the Activity/Activity? and pass it to Event/Context methods. These best-practice diagnostics are controlled by ActivitySourceGeneration.GenerateDiagnosticsForMissingActivity.
TSG3021 — exception event name
Section titled “TSG3021 — exception event name”Rename the event with [Event(Name = "exception")] so the OpenTelemetry exception tags (exception.type, exception.message, exception.stacktrace, exception.escaped) are attached to that event instead of a separate event named exception.
[Event(Name = "exception")] // ✅ the event carries the exception tagsvoid FailedToRetrieve(Activity? activity, Exception exception);A Name set on a logging attribute does not name the event — it renames the log entry:
[Event] // ❌ event name is the method name[Error(Name = "exception")] // the log entry is named 'exception'void FailedToRetrieve(Activity? activity, Exception exception);The diagnostic is not raised when the exception is not recorded using the OpenTelemetry exception rules: [Event(UseRecordExceptionRules = false)], a [Baggage] exception parameter, or an exception parameter excluded from the Activities target ([ExcludeTargets(Targets.Activities)]).
TSG3022 — non-nullable Activity return
Section titled “TSG3022 — non-nullable Activity return”Return Activity? so callers can handle the null case when no listeners are active.
TSG3023 — ActivitySourceFactory is not available
Section titled “TSG3023 — ActivitySourceFactory is not available”[assembly: ActivitySourceGeneration(..., UseActivitySourceFactory = true)] asks for sources created by
System.Diagnostics.ActivitySourceFactory, but the compilation cannot resolve that type, so a static ActivitySource
is generated instead. Target net11.0, or reference System.Diagnostics.DiagnosticSource 11 or later; or remove the
option. See Creating sources with ActivitySourceFactory.
TSG4002 — auto-increment counter with a measurement
Section titled “TSG4002 — auto-increment counter with a measurement”[AutoCounter] (or [Counter(AutoIncrement = true)]) must not declare a measurement parameter — the measurement is fixed to 1.