-
Notifications
You must be signed in to change notification settings - Fork 3
Diagnostics
Kieron Lanning edited this page Feb 8, 2026
·
7 revisions
This page lists all diagnostic codes emitted by the Purview Telemetry Source Generator with their severity levels, categories, and descriptions.
- Error - Prevents code generation or compilation
- Warning - Indicates potential issues or non-recommended patterns
- Info - Suggestions for improvement or informational messages
| ID | Level | Category | Description |
|---|---|---|---|
TSG1000 |
Error |
Usage |
Fatal execution error occurred during generation. |
TSG1001 |
Error |
Usage |
Inferring generation targets is not supported when using multi-target generation. Each method must have an explicit attribute. |
TSG1002 |
Error |
Usage |
Multiple attributes from the same target family are not supported. Only one Activity, Logging, or Metrics attribute per method. |
TSG1003 |
Error |
Usage |
Duplicate method names are not supported. Method names must be unique as they're used to generate other members. |
TSG1004 |
Error |
Usage |
Generic interfaces are not supported. Remove generic type parameters from the interface. |
TSG1005 |
Error |
Usage |
Generic methods are not supported. Remove generic type parameters from methods. |
TSG1006 |
Warning |
Usage |
[ExcludeTargets] references a target not present on this method. |
TSG1007 |
Warning |
Usage |
[ExcludeTargets] results in an empty or invalid parameter set for a target. |
TSG1008 |
Warning |
Usage |
Activity parameter present but no Activity attribute on method. Parameter will be ignored. |
TSG1009 |
Info |
Usage |
Tag/baggage key appears to be a compound word without separators. Consider using snake_case or dot.notation. |
| ID | Level | Category | Description | Applies To |
|---|---|---|---|---|
TSG2000 |
Error |
Usage |
Too many exception parameters. Only a single Exception parameter is permitted. | v1, v2 |
TSG2001 |
Error |
Usage |
More than 6 parameters (excluding Exception). Maximum is 6 non-exception parameters. | v1, v2 |
TSG2002 |
Info |
Usage |
Inferring Error log level because an Exception parameter was defined without explicit level. | v1, v2 |
TSG2003 |
Warning |
Usage |
Microsoft.Extensions.Logging.ILogger type not found. Add reference to Microsoft.Extensions.Logging package. |
v1, v2 |
TSG2004 |
Error |
Usage |
Cannot mix ordinal and named property placeholders in message template. | v1, v2 |
TSG2005 |
Error |
Usage |
Ordinal values in message template exceed the number of provided parameters. | v1, v2 |
TSG2006 |
Error |
Usage |
Using [LogProperties] and [ExpandEnumerable] on the same parameter is not supported. |
v2 only |
TSG2007 |
Warning |
Usage |
Scoped log methods should not have a LogLevel set. It will be ignored. | v1, v2 |
TSG2008 |
Warning |
Performance |
Unbounded enumeration limit is higher than recommended default (500). May cause performance issues. | v2 only |
TSG2020 |
Error |
Usage |
Scoped logging methods must return IDisposable? to properly manage log scope lifetime. |
v1, v2 |
TSG2021 |
Error |
Usage |
Log methods must return void (non-scoped) or IDisposable? (scoped). Other return types are not supported. |
v1, v2 |
TSG2022 |
Error |
Usage |
Async return types (Task, ValueTask) are not supported for logging methods. |
v1, v2 |
TSG2023 |
Info |
Usage |
Using Default prefix type results in log names with no context prefix. Consider using TrimmedClassName or Custom. | v1, v2 |
TSG2024 |
Warning |
Usage |
Log method name is very short or generic. Use a more descriptive name. | v1, v2 |
| ID | Level | Category | Description |
|---|---|---|---|
TSG3000 |
Warning |
Usage |
Baggage parameter types only accept strings. ToString() will be called on non-string types. |
TSG3001 |
Warning |
Usage |
No activity source name specified. Defaulting to 'purview'. |
TSG3002 |
Error |
Usage |
Invalid return type. Activity or Event methods must return void, Activity, or Activity?. |
TSG3003 |
Error |
Usage |
Duplicate reserved parameters defined. Only one of each reserved parameter type is allowed. |
TSG3004 |
Error |
Usage |
Activity parameter is not valid on Activity methods, only on Event and Context methods. |
TSG3005 |
Error |
Usage |
Timestamp parameter is not valid on Activity methods, only on Event methods. |
TSG3006 |
Error |
Usage |
Start time parameter is only valid when starting an activity, not on Create or Event methods. |
TSG3007 |
Error |
Usage |
Parent context or Parent Id parameter is only valid on Activity start/create methods, not Events. |
TSG3008 |
Error |
Usage |
Activity links parameters are only valid on Activity start/create methods, not Events or Context. |
TSG3009 |
Error |
Usage |
Activity tags parameter is only valid on Activity start/create and Event methods, not Context. |
TSG3010 |
Error |
Usage |
Escaped parameters must be of type boolean. |
TSG3011 |
Error |
Usage |
Escaped parameters are only valid on Event methods, not Activity or Context methods. |
TSG3012 |
Info |
Usage |
No Activity methods defined. Event/Context methods will use Activity.Current which may not be intended. |
TSG3013 |
Warning |
Usage |
Activity method should return Activity? so it can be disposed and used for Events/Context. |
TSG3014 |
Warning |
Usage |
Event/Context method should accept an Activity? parameter to ensure it applies to the intended Activity. |
TSG3015 |
Info |
Usage |
For readability, the Activity parameter should be the first parameter. |
TSG3016 |
Error |
Usage |
Status description parameter must be of type string. |
TSG3017 |
Error |
Usage |
Status description parameters are only valid on Event methods, not Activity or Context. |
TSG3018 |
Info |
Usage |
Span name is generic or reserved (e.g., "process", "execute", "run"). Use a more descriptive name. |
TSG3019 |
Info |
Usage |
ActivitySource name is defaulting to assembly name. Consider specifying explicitly with [ActivitySource(Name = "...")]. |
TSG3020 |
Warning |
Usage |
ActivitySource name cannot be empty or whitespace. Provide a valid name. |
TSG3021 |
Info |
Usage |
Event records an exception but doesn't use OpenTelemetry standard name "exception". Consider [Event(Name = "exception")]. |
| ID | Level | Category | Description |
|---|---|---|---|
TSG4000 |
Error |
Usage |
No instrument defined. Add a meter attribute or exclude the method. |
TSG4001 |
Error |
Usage |
Instrument methods must return void or bool (for observables to indicate initialization). |
TSG4002 |
Error |
Usage |
Auto increment counter and measurement parameter both defined. Use one or the other. |
TSG4003 |
Error |
Usage |
Multiple measurement parameters defined. Only one [InstrumentMeasurement] is allowed. |
TSG4004 |
Error |
Usage |
No measurement value defined. Add [InstrumentMeasurement] parameter or a supported numeric type. |
TSG4005 |
Error |
Usage |
Observable instruments require a Func<T> parameter where T is a supported measurement result type. |
TSG4006 |
Error |
Usage |
Invalid measurement type. Valid types: byte, short, int, long, float, double, decimal, Measurement<T>, IEnumerable<Measurement<T>>. |
TSG4007 |
Error |
Usage |
Observable metrics can only return void or Activity? (when combined with [Activity]). Boolean returns not supported. |
TSG4008 |
Error |
Usage |
AutoCounter methods must return void. Boolean or other return types are not supported. |
TSG4009 |
Warning |
Usage |
Instrument name matches the instrument type name (e.g., "counter", "histogram"). Name what you're measuring, not the type. |
TSG4010 |
Warning |
Usage |
Instrument name contains compound words without separators. Consider using dot.notation or snake_case. |
TSG4011 |
Info |
Usage |
Meter name is defaulting to interface name. Consider using assembly name or explicit name with [Meter(Name = "...")]. |
TSG4012 |
Info |
Usage |
Instrument name starts with instrument type verb (e.g., "RecordDuration"). Name after the concept instead (e.g., "request.duration"). |
Problem: Using multiple generation targets without explicit method attributes.
Solution:
// Bad - inference not supported with multi-target
[ActivitySource("MyApp")]
[Logger]
[Meter]
interface IMyTelemetry
{
void DoSomething(int id); // ERROR: No explicit attribute
}
// Good - explicit attributes
[ActivitySource("MyApp")]
[Logger]
[Meter]
interface IMyTelemetry
{
[Activity]
[Info]
[AutoCounter]
Activity? DoSomething(int id);
}Problem: Multiple methods with the same name.
Solution:
// Bad
interface IMyTelemetry
{
[Info]
void ProcessItem(int id);
[Info]
void ProcessItem(string name); // ERROR: Duplicate name
}
// Good - unique names
interface IMyTelemetry
{
[Info]
void ProcessItemById(int id);
[Info]
void ProcessItemByName(string name);
}Problem: Scoped log doesn't return IDisposable?.
Solution:
// Bad
[Logger]
interface IMyTelemetry
{
[Log]
void ProcessingScope(int id); // ERROR: Should return IDisposable?
}
// Good
[Logger]
interface IMyTelemetry
{
[Log]
IDisposable? ProcessingScope(int id); // Scoped log
}Problem: Activity not returned or Event doesn't accept Activity parameter.
Solution:
// Bad
[ActivitySource("MyApp")]
interface IMyTelemetry
{
[Activity]
void ProcessItem(int id); // Warning: Should return Activity?
[Event]
void ItemProcessed(int id); // Warning: Should accept Activity?
}
// Good
[ActivitySource("MyApp")]
interface IMyTelemetry
{
[Activity]
Activity? ProcessItem(int id);
[Event]
void ItemProcessed(Activity? activity, int id);
}Problem: AutoCounter with measurement parameter.
Solution:
// Bad
[Meter]
interface IMyMetrics
{
[AutoCounter]
void Count([InstrumentMeasurement]int value); // ERROR: AutoCounter doesn't need measurement
}
// Good - Option 1: Use AutoCounter (always increments by 1)
[Meter]
interface IMyMetrics
{
[AutoCounter]
void Count([Tag]string type);
}
// Good - Option 2: Use Counter with measurement
[Meter]
interface IMyMetrics
{
[Counter]
void Count([InstrumentMeasurement]int value, [Tag]string type);
}- Getting Started - Quick start examples
- Activities - Activity generation details
- Logging - Logging generation details
- Metrics - Metrics generation details
Important
Consider helping children around the world affected by conflict. You can donate any amount to War Child here - any amount can help save a life.
Purview Telemetry Source Generator v4.0.0-prerelease.1 | Home | Getting Started | FAQ | Breaking Changes | GitHub