Documentation section: Reference
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 interface cannot be generated. A generic interface is generated as a generic class with the same type parameters and constraints; the shapes that cannot be are a nested generic interface (the enclosing type’s type arguments cannot be repeated on the generated class) and a type parameter carrying the allows ref struct anti-constraint (the generated class cannot repeat it). |
TSG1005 |
Error | Generic method cannot be generated. Generic methods and their constraints are mirrored; what cannot be is a type parameter carrying the allows ref struct anti-constraint, or a metric method whose measurement is one of its own type parameters (the instrument is a field, and a field cannot name a method’s type parameter — declare that type parameter on the interface instead). The method is emitted as a throwing stub so the interface stays implemented. |
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 10+ nor .NET Framework 4.8+ (for example netstandard2.0, net8.0 or net9.0), so no telemetry is generated for it. There is no opt-out. Target net10.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.
TSG1004 — generic interface cannot be generated
Section titled “TSG1004 — generic interface cannot be generated”A generic interface is generated as a generic class with the same type parameters and constraints:
[Logger]public interface IMyTelemetry<T> where T : class{ void Log(T value); // ✅ generated as IMyTelemetryCore<T>}Two shapes still cannot be generated, because the generated class has no way to express them:
- a nested generic interface — the enclosing type’s type arguments cannot be repeated on the generated class;
- a type parameter carrying the
allows ref structanti-constraint — it cannot be repeated on the generated class.
TSG1005 — generic method cannot be generated
Section titled “TSG1005 — generic method cannot be generated”Generic methods are generated with the interface method’s type parameters and constraints mirrored onto the
implementation, and constraints are mirrored for struct, class, class?, notnull, unmanaged, new() and
type-parameter or type constraints:
[Logger]public interface IMyTelemetry{ void Log<T>(T value) where T : notnull; // ✅ generated as void Log<T>(T value) where T : notnull}The method is emitted as a throwing stub, so the interface stays implemented, when:
- a type parameter carries the
allows ref structanti-constraint; or - a metric method uses one of its own type parameters as the instrument measurement. An instrument is a field, and a field cannot name a method’s type parameter — declare that type parameter on the interface instead, which makes the generated class generic and lets the instrument field use it.
TSG2024 / TSG2025 / TSG2026 — [TagProvider] cannot be used
Section titled “TSG2024 / TSG2025 / TSG2026 — [TagProvider] cannot be used”[TagProvider(typeof(T), "Method")] names a static method that contributes extra tags; see
Logging. TSG2024 reports a provider type that cannot be resolved,
TSG2025 a method that does not exist on it, and TSG2026 a method whose signature the generated foreach cannot
read. In every case the parameter is still logged — only the extra tags are missing.
TSG2027 — [TagProvider] on a method that never logs
Section titled “TSG2027 — [TagProvider] on a method that never logs”The attribute is on a parameter of a method that generates no log entry (for example an [Activity]-only method on a
multi-target interface). Move it to the logging method, or remove it.
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.
TSG3024 — ActivitySourceOptions require UseActivitySourceFactory
Section titled “TSG3024 — ActivitySourceOptions require UseActivitySourceFactory”Version or TelemetrySchemaUrl on [assembly: ActivitySourceGeneration(...)] is only consumed by
System.Diagnostics.ActivitySourceOptions, which a factory-created source passes to
ActivitySourceFactory.Create. A static ActivitySource has nowhere to put them, so they are ignored. Set
UseActivitySourceFactory = true, 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.