Skip to content

Commit

Permalink
Merge pull request #27 from purview-dev/fixed-diagnostics
Browse files Browse the repository at this point in the history
Fixed diagnostics ID duplication
  • Loading branch information
kieronlanning authored May 6, 2024
2 parents 7c6265a + e2a4bc3 commit 1c637a6
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SOLUTION_FILE = $(ROOT_FOLDER)Purview.Telemetry.SourceGenerator.sln
TEST_PROJECT = $(ROOT_FOLDER)Purview.Telemetry.SourceGenerator.sln
CONFIGURATION = Release

PACK_VERSION = 1.0.4
PACK_VERSION = 1.0.5
ARTIFACT_FOLDER = p:/sync-projects/.local-nuget/

# Targets
Expand Down
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,37 @@ The latest version is available on [NuGet](https://www.nuget.org/packages/Purvie
[ActivitySource]
[Logger]
[Meter]
interface IServiceTelemetry
interface IEntityStoreTelemetry
{
/// <summary>
/// Creates and starts an Activity and adds the parameters as Tags and Baggage.
/// </summary>
[Activity]
Activity? StartsAnActivity(string tagStringParam, [Baggage]int entityId);
void GettingEntityFromStore(int entityId, [Baggage]string serviceUrl);

/// <summary>
/// Adds an ActivityEvent to the Activity with the parameters as Tags.
/// </summary>
[Event]
void AnInterestingEvent(Activity? activity, float aTagValue);
void GetDuration(int durationInMS);

/// <summary>
/// Adds the parameters as Baggage to the Activity.
/// </summary>
[Context]
void InterestingInfo(Activity? activity, float anotherTagValue, int intTagValue);
void RetrievedEntity(float totalValue, int lastUpdatedByUserId);

/// <summary>
/// Generates a structured log message using an ILogger.
/// </summary>
[Log]
void ProcessingEntity(int entityId, string property);
void ProcessingEntity(int entityId, string updateState);

/// <summary>
/// Adds 1 to a Counter<T> with the entityId as a Tag.
/// </summary>
[AutoCounter]
void AnAutoIncrementCounter([Tag]int entityId);
void RetrievingEntity(int entityId);
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,95 +10,95 @@ public static class Activities
{
public static readonly TelemetryDiagnosticDescriptor BaggageParameterShouldBeString = new(
Id: "TSG3000",
Title: "Baggage parameter types only accept strings.",
Title: "Baggage parameter types only accept strings",
Description: "Baggage parameter types only accept strings, be aware this parameter will have ToString() called.",
Category: Constants.Diagnostics.Activity.Usage,
Severity: DiagnosticSeverity.Warning
);

public static readonly TelemetryDiagnosticDescriptor NoActivitySourceSpecified = new(
Id: "TSG3001",
Title: "No activity source specified.",
Title: "No activity source specified",
Description: $"An activity source helps to identify your application and it's telemetry. Defaulting to '{Constants.Activities.DefaultActivitySourceName}'.",
Category: Constants.Diagnostics.Activity.Usage,
Severity: DiagnosticSeverity.Warning
);

public static readonly TelemetryDiagnosticDescriptor InvalidReturnType = new(
Id: "TSG3002",
Title: "Invalid return type.",
Title: "Invalid return type",
Description: $"An activity or event must return either void or an {Constants.Activities.SystemDiagnostics.Activity}.",
Category: Constants.Diagnostics.Activity.Usage,
Severity: DiagnosticSeverity.Error
);

public static readonly TelemetryDiagnosticDescriptor DuplicateParameterTypes = new(
Id: "TSG3003",
Title: "Duplicate special parameters defined.",
Title: "Duplicate reserved parameters defined",
Description: "{0} are all the same type of parameter ({1}), a maximum or one is allowed. Explicitly define them as either a Tag or Baggage.",
Category: Constants.Diagnostics.Activity.Usage,
Severity: DiagnosticSeverity.Error
);

public static readonly TelemetryDiagnosticDescriptor ActivityParameterNotAllowed = new(
Id: "TSG3004",
Title: "Activity parameter is not valid.",
Title: "Activity parameter is not valid",
Description: "The {0} parameter is not allowed when defining an activity, only an event.",
Category: Constants.Diagnostics.Activity.Usage,
Severity: DiagnosticSeverity.Error
);

public static readonly TelemetryDiagnosticDescriptor TimestampParameterNotAllowed = new(
Id: "TSG3005",
Title: "Timestamp parameter is not valid.",
Title: "Timestamp parameter is not valid",
Description: "The {0} parameter is not allowed when defining an activity, only an event. You can specify this as a Tag or as Baggage to stop the inference.",
Category: Constants.Diagnostics.Activity.Usage,
Severity: DiagnosticSeverity.Error
);

public static readonly TelemetryDiagnosticDescriptor StartTimeParameterNotAllowed = new(
Id: "TSG3006",
Title: "Start time parameter is not valid on Create activity or Event method.",
Title: "Start time parameter is not valid on Create activity or Event method",
Description: "The {0} parameter is not allowed when defining an activity create or activity event method, only when starting an activity.",
Category: Constants.Diagnostics.Activity.Usage,
Severity: DiagnosticSeverity.Error
);

public static readonly TelemetryDiagnosticDescriptor ParentContextOrIdParameterNotAllowed = new(
Id: "TSG3007",
Title: "Parent context or Parent Id parameter is not valid on event.",
Title: "Parent context or Parent Id parameter is not valid on event",
Description: "The {0} parameter is not allowed when defining an activity event, only on the activity start/ create method.",
Category: Constants.Diagnostics.Activity.Usage,
Severity: DiagnosticSeverity.Error
);

public static readonly TelemetryDiagnosticDescriptor LinksParameterNotAllowed = new(
Id: "TSG3008",
Title: "Activity links parameters are not valid on events or context methods.",
Title: "Activity links parameters are not valid on events or context methods",
Description: "The {0} parameter is not allowed when defining an activity event or context, only on the activity start/ create method.",
Category: Constants.Diagnostics.Activity.Usage,
Severity: DiagnosticSeverity.Error
);

public static readonly TelemetryDiagnosticDescriptor TagsParameterNotAllowed = new(
Id: "TSG3009",
Title: "Activity tags parameter are not valid on context methods.",
Title: "Activity tags parameter are not valid on context methods",
Description: "The {0} parameter is not allowed when defining an activity context, only on the activity start/ create methods or events.",
Category: Constants.Diagnostics.Activity.Usage,
Severity: DiagnosticSeverity.Error
);

public static readonly TelemetryDiagnosticDescriptor EscapedParameterInvalidType = new(
Id: "TSG3010",
Title: "Escaped parameters must be a boolean.",
Title: "Escaped parameters must be a boolean",
Description: "Only boolean parameter types are valid for the escape parameter.",
Category: Constants.Diagnostics.Activity.Usage,
Severity: DiagnosticSeverity.Error
);

public static readonly TelemetryDiagnosticDescriptor EscapedParameterIsOnlyValidOnEvent = new(
Id: "TSG3010",
Title: "Escaped parameters are only valid on Events, not Activity or Context methods.",
Id: "TSG3011",
Title: "Escaped parameters are only valid on Events, not Activity or Context methods",
Description: "The parameters {0} is not valid on Activity or Context methods, only on Events.",
Category: Constants.Diagnostics.Activity.Usage,
Severity: DiagnosticSeverity.Error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static class General

public static readonly TelemetryDiagnosticDescriptor InferenceNotSupportedWithMultiTargeting = new(
Id: "TSG1001",
Title: "Inferring generation targets is not supported when using multi-target generation.",
Title: "Inferring generation targets is not supported when using multi-target generation",
Description: $"When using multiple generation targets - Activities, Logs or Metrics, each method must be either excluded or have an explicit generation target: " +
$"{Constants.Activities.ActivityAttribute.Name}, {Constants.Activities.EventAttribute.Name}, {Constants.Activities.ContextAttribute.Name}, {Constants.Logging.LogAttribute.Name}, " +
$"{Constants.Metrics.CounterAttribute.Name}, {Constants.Metrics.HistogramAttribute.Name}, {Constants.Metrics.UpDownCounterAttribute.Name}, " +
Expand All @@ -28,8 +28,8 @@ public static class General

public static readonly TelemetryDiagnosticDescriptor MultiGenerationTargetsNotSupported = new(
Id: "TSG1002",
Title: "Only single generation types are supported.",
Description: $"Only a single generation target types (Activities, Logs or Metrics) is supported on methods. Use one of the following: " +
Title: "Multiple generation types are not supported",
Description: $"Only a single generation target types (Activities, Logs or Metrics) are supported. Use one of the following: " +
$"{Constants.Activities.ActivityAttribute.Name}, {Constants.Activities.EventAttribute.Name}, {Constants.Activities.ContextAttribute.Name}, {Constants.Logging.LogAttribute.Name}, " +
$"{Constants.Metrics.CounterAttribute.Name}, {Constants.Metrics.HistogramAttribute.Name}, {Constants.Metrics.UpDownCounterAttribute.Name}, " +
$"{Constants.Metrics.ObservableCounterAttribute.Name}, {Constants.Metrics.ObservableGaugeAttribute.Name} or {Constants.Metrics.ObservableUpDownCounterAttribute.Name}.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,55 +10,55 @@ public static class Metrics
{
public static readonly TelemetryDiagnosticDescriptor NoInstrumentDefined = new(
Id: "TSG4000",
Title: "No instrument defined.",
Title: "No instrument defined",
Description: "Either exclude this method, or define an instrument.",
Category: Constants.Diagnostics.Metrics.Usage,
Severity: DiagnosticSeverity.Error
);

public static readonly TelemetryDiagnosticDescriptor DoesNotReturnVoid = new(
Id: "TSG4001",
Title: "Must return void or bool.",
Title: "Must return void or bool",
Description: "Instrument methods can only return void or bool.",
Category: Constants.Diagnostics.Metrics.Usage,
Severity: DiagnosticSeverity.Error
);

public static readonly TelemetryDiagnosticDescriptor AutoIncrementCountAndMeasurementParam = new(
Id: "TSG4002",
Title: "Auto increment counter and measurement defined.",
Title: "Auto increment counter and measurement defined",
Description: "Auto increment counter and a measurement parameter are defined, either remove the parameter or disable auto increment.",
Category: Constants.Diagnostics.Metrics.Usage,
Severity: DiagnosticSeverity.Error
);

public static readonly TelemetryDiagnosticDescriptor MoreThanOneMeasurementValueDefined = new(
Id: "TSG4003",
Title: "Multiple measurement values defined.",
Title: "Multiple measurement values defined",
Description: "More than one measurement parameters are defined.",
Category: Constants.Diagnostics.Metrics.Usage,
Severity: DiagnosticSeverity.Error
);

public static readonly TelemetryDiagnosticDescriptor NoMeasurementValueDefined = new(
Id: "TSG4004",
Title: "No measurement value defined.",
Title: "No measurement value defined",
Description: "Either define a measurement parameter, or provide a supported type parameter that is not a tag to enable inferring.",
Category: Constants.Diagnostics.Metrics.Usage,
Severity: DiagnosticSeverity.Error
);

public static readonly TelemetryDiagnosticDescriptor ObservableRequiredFunc = new(
Id: "TSG4005",
Title: "Observable instrument requires func.",
Title: "Observable instrument requires Func<T>",
Description: "Observable instruments require a Func<T> where T is a supported instrument result type.",
Category: Constants.Diagnostics.Metrics.Usage,
Severity: DiagnosticSeverity.Error
);

public static readonly TelemetryDiagnosticDescriptor InvalidMeasurementType = new(
Id: "TSG4006",
Title: "Invalid measurement type.",
Title: "Invalid measurement type",
Description: $"Invalid measurement type used, valid types are {string.Join(", ", Constants.Metrics.ValidMeasurementKeywordTypes)}, Measurement<T> or IEnumerable<MeasurementT>>.",
Category: Constants.Diagnostics.Metrics.Usage,
Severity: DiagnosticSeverity.Error
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json",
"version": "1.0.4",
"version": "1.0.5",
"cloudBuild": {
"buildNumber": {
"enabled": true,
Expand Down

0 comments on commit 1c637a6

Please sign in to comment.