From 2cca49542db3f46ce524d34376714977aaf9b601 Mon Sep 17 00:00:00 2001 From: Kieron Date: Mon, 20 May 2024 14:02:04 +0100 Subject: [PATCH] feat: added new diagnostic (info) for when no Activity method is defined, but an Event and/ or Context is --- Makefile | 2 +- ...eGeneratorActivityTests.BasicContextGen.cs | 33 +++++- ...rceGeneratorActivityTests.BasicEventGen.cs | 12 +- ...rySourceGeneratorActivityTests.BasicGen.cs | 26 +++++ ....TestActivitiesCore.Activity.g.verified.cs | 6 + ....TestActivitiesCore.Activity.g.verified.cs | 6 + ....TestActivitiesCore.Activity.g.verified.cs | 6 + ....TestActivitiesCore.Activity.g.verified.cs | 6 + ....TestActivitiesCore.Activity.g.verified.cs | 6 + ....TestActivitiesCore.Activity.g.verified.cs | 6 + ....TestActivitiesCore.Activity.g.verified.cs | 6 + ....TestActivitiesCore.Activity.g.verified.cs | 6 + ....DotNet8_0#ActivityAttribute.g.verified.cs | 84 ++++++++++++++ ...t8_0#ActivitySourceAttribute.g.verified.cs | 76 +++++++++++++ ...itySourceGenerationAttribute.g.verified.cs | 78 +++++++++++++ ...tNet8_0#AutoCounterAttribute.g.verified.cs | 67 +++++++++++ ...c.DotNet8_0#BaggageAttribute.g.verified.cs | 66 +++++++++++ ...c.DotNet8_0#ContextAttribute.g.verified.cs | 28 +++++ ...c.DotNet8_0#CounterAttribute.g.verified.cs | 83 ++++++++++++++ ...ic.DotNet8_0#EscapeAttribute.g.verified.cs | 28 +++++ ...tic.DotNet8_0#EventAttribute.g.verified.cs | 63 +++++++++++ ...c.DotNet8_0#ExcludeAttribute.g.verified.cs | 25 +++++ ...DotNet8_0#HistogramAttribute.g.verified.cs | 62 +++++++++++ ...strumentMeasurementAttribute.g.verified.cs | 25 +++++ ...ostic.DotNet8_0#LogAttribute.g.verified.cs | 104 ++++++++++++++++++ ...stic.DotNet8_0#LogPrefixType.g.verified.cs | 49 +++++++++ ...ic.DotNet8_0#LoggerAttribute.g.verified.cs | 68 ++++++++++++ ..._0#LoggerGenerationAttribute.g.verified.cs | 48 ++++++++ ...tic.DotNet8_0#MeterAttribute.g.verified.cs | 72 ++++++++++++ ...8_0#MeterGenerationAttribute.g.verified.cs | 63 +++++++++++ ...0#ObservableCounterAttribute.g.verified.cs | 71 ++++++++++++ ...8_0#ObservableGaugeAttribute.g.verified.cs | 71 ++++++++++++ ...rvableUpDownCounterAttribute.g.verified.cs | 71 ++++++++++++ ...ostic.DotNet8_0#TagAttribute.g.verified.cs | 67 +++++++++++ ...TelemetryGenerationAttribute.g.verified.cs | 78 +++++++++++++ ....TestActivitiesCore.Activity.g.verified.cs | 70 ++++++++++++ ...et8_0#UpDownCounterAttribute.g.verified.cs | 63 +++++++++++ ...GeneratesDiagnostic.DotNet8_0.verified.txt | 14 +++ ....DotNet8_0#ActivityAttribute.g.verified.cs | 84 ++++++++++++++ ...t8_0#ActivitySourceAttribute.g.verified.cs | 76 +++++++++++++ ...itySourceGenerationAttribute.g.verified.cs | 78 +++++++++++++ ...tNet8_0#AutoCounterAttribute.g.verified.cs | 67 +++++++++++ ...c.DotNet8_0#BaggageAttribute.g.verified.cs | 66 +++++++++++ ...c.DotNet8_0#ContextAttribute.g.verified.cs | 28 +++++ ...c.DotNet8_0#CounterAttribute.g.verified.cs | 83 ++++++++++++++ ...ic.DotNet8_0#EscapeAttribute.g.verified.cs | 28 +++++ ...tic.DotNet8_0#EventAttribute.g.verified.cs | 63 +++++++++++ ...c.DotNet8_0#ExcludeAttribute.g.verified.cs | 25 +++++ ...DotNet8_0#HistogramAttribute.g.verified.cs | 62 +++++++++++ ...strumentMeasurementAttribute.g.verified.cs | 25 +++++ ...ostic.DotNet8_0#LogAttribute.g.verified.cs | 104 ++++++++++++++++++ ...stic.DotNet8_0#LogPrefixType.g.verified.cs | 49 +++++++++ ...ic.DotNet8_0#LoggerAttribute.g.verified.cs | 68 ++++++++++++ ..._0#LoggerGenerationAttribute.g.verified.cs | 48 ++++++++ ...tic.DotNet8_0#MeterAttribute.g.verified.cs | 72 ++++++++++++ ...8_0#MeterGenerationAttribute.g.verified.cs | 63 +++++++++++ ...0#ObservableCounterAttribute.g.verified.cs | 71 ++++++++++++ ...8_0#ObservableGaugeAttribute.g.verified.cs | 71 ++++++++++++ ...rvableUpDownCounterAttribute.g.verified.cs | 71 ++++++++++++ ...ostic.DotNet8_0#TagAttribute.g.verified.cs | 67 +++++++++++ ...TelemetryGenerationAttribute.g.verified.cs | 78 +++++++++++++ ....TestActivitiesCore.Activity.g.verified.cs | 70 ++++++++++++ ...et8_0#UpDownCounterAttribute.g.verified.cs | 63 +++++++++++ ...GeneratesDiagnostic.DotNet8_0.verified.txt | 14 +++ ...g.TestTelemetryCore.Activity.g.verified.cs | 6 + ...g.TestTelemetryCore.Activity.g.verified.cs | 6 + ...g.TestTelemetryCore.Activity.g.verified.cs | 6 + ...g.TestTelemetryCore.Activity.g.verified.cs | 6 + ...g.TestTelemetryCore.Activity.g.verified.cs | 6 + ...etrySourceGeneratorTests.TelemetryBasic.cs | 15 +++ ...ctivitySourceTargetClassEmitter.Methods.cs | 10 ++ .../Helpers/PipelineHelpers.Activities.cs | 3 +- .../Records/ActivityRecords.cs | 4 +- .../TelemetryDiagnostics.Activities.cs | 8 ++ version.json | 2 +- 75 files changed, 3369 insertions(+), 12 deletions(-) create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ActivityAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ActivitySourceAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ActivitySourceGenerationAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#AutoCounterAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#BaggageAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ContextAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#CounterAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#EscapeAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#EventAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ExcludeAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#HistogramAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#InstrumentMeasurementAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#LogAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#LogPrefixType.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#LoggerAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#LoggerGenerationAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#MeterAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#MeterGenerationAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ObservableCounterAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ObservableGaugeAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ObservableUpDownCounterAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#TagAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#TelemetryGenerationAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#UpDownCounterAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0.verified.txt create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ActivityAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ActivitySourceAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ActivitySourceGenerationAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#AutoCounterAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#BaggageAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ContextAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#CounterAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#EscapeAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#EventAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ExcludeAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#HistogramAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#InstrumentMeasurementAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#LogAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#LogPrefixType.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#LoggerAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#LoggerGenerationAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#MeterAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#MeterGenerationAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ObservableCounterAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ObservableGaugeAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ObservableUpDownCounterAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#TagAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#TelemetryGenerationAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#UpDownCounterAttribute.g.verified.cs create mode 100644 src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0.verified.txt diff --git a/Makefile b/Makefile index 8342f270..ebad3f86 100644 --- a/Makefile +++ b/Makefile @@ -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.5 +PACK_VERSION = 1.0.6 ARTIFACT_FOLDER = p:/sync-projects/.local-nuget/ # Targets diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Activities/TelemetrySourceGeneratorActivityTests.BasicContextGen.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Activities/TelemetrySourceGeneratorActivityTests.BasicContextGen.cs index 618ec4e1..d735a4b5 100644 --- a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Activities/TelemetrySourceGeneratorActivityTests.BasicContextGen.cs +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Activities/TelemetrySourceGeneratorActivityTests.BasicContextGen.cs @@ -12,7 +12,11 @@ public async Task Generate_GivenBasicContextGen_GeneratesActivity() namespace Testing; [ActivitySource(""testing-activity-source"")] -public interface ITestActivities { +public interface ITestActivities +{ + [Activity] + void Activity(); + [Context] void Context([Baggage]string stringParam, [Tag]int intParam, bool boolParam); } @@ -36,7 +40,11 @@ public async Task Generate_GivenBasicContextGenWithReturningActivity_GeneratesAc namespace Testing; [ActivitySource(""testing-activity-source"")] -public interface ITestActivities { +public interface ITestActivities +{ + [Activity] + void Activity(); + [Context] Activity Context([Baggage]string stringParam, [Tag]int intParam, bool boolParam); } @@ -61,6 +69,9 @@ namespace Testing; [ActivitySource(""testing-activity-source"")] public interface ITestActivities { + [Activity] + void Activity(); + [Context] Activity Context([Baggage]string stringParam, [Tag]int intParam, bool boolParam); @@ -87,7 +98,11 @@ public async Task Generate_GivenBasicContextGenWithNullableParams_GeneratesActiv namespace Testing; [ActivitySource(""testing-activity-source"")] -public interface ITestActivities { +public interface ITestActivities +{ + [Activity] + void Activity(); + [Context] Activity Context([Baggage]string? stringParam, [Tag]int? intParam, bool? boolParam); @@ -114,7 +129,11 @@ public async Task Generate_GivenBasicContextGenWithActivity_GeneratesActivity() namespace Testing; [ActivitySource(""testing-activity-source"")] -public interface ITestActivities { +public interface ITestActivities +{ + [Activity] + void Activity(); + [Context] Activity Context(Activity activityParameter, [Baggage]string? stringParam, [Tag]int? intParam, bool? boolParam); @@ -141,7 +160,11 @@ public async Task Generate_GivenBasicContextGenWithActivityAndNoReturn_Generates namespace Testing; [ActivitySource(""testing-activity-source"")] -public interface ITestActivities { +public interface ITestActivities +{ + [Activity] + void Activity(); + [Context] void Context(Activity activityParameter, [Baggage]string? stringParam, [Tag]int? intParam, bool? boolParam); diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Activities/TelemetrySourceGeneratorActivityTests.BasicEventGen.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Activities/TelemetrySourceGeneratorActivityTests.BasicEventGen.cs index c327e59f..0bdb3cbf 100644 --- a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Activities/TelemetrySourceGeneratorActivityTests.BasicEventGen.cs +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Activities/TelemetrySourceGeneratorActivityTests.BasicEventGen.cs @@ -13,7 +13,11 @@ public async Task Generate_GivenBasicEventWithActivityParameter_GeneratesActivit namespace Testing; [ActivitySource(""testing-activity-source"")] -public interface ITestActivities { +public interface ITestActivities +{ + [Activity] + void Activity(); + [Event] void Event(Activity activity, [Baggage]string stringParam, [Tag]int intParam, bool boolParam); } @@ -37,7 +41,11 @@ public async Task Generate_GivenBasicEventWithNullableActivityParameter_Generate namespace Testing; [ActivitySource(""testing-activity-source"")] -public interface ITestActivities { +public interface ITestActivities +{ + [Activity] + void Activity(); + [Event] void Event(Activity? activity, [Baggage]string stringParam, [Tag]int intParam, bool boolParam); } diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Activities/TelemetrySourceGeneratorActivityTests.BasicGen.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Activities/TelemetrySourceGeneratorActivityTests.BasicGen.cs index 3a733ad0..ea0ab94d 100644 --- a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Activities/TelemetrySourceGeneratorActivityTests.BasicGen.cs +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Activities/TelemetrySourceGeneratorActivityTests.BasicGen.cs @@ -28,6 +28,32 @@ public interface ITestActivities { await TestHelpers.Verify(generationResult); } + [Fact] + public async Task Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic() + { + // Arrange + const string basicActivity = @" +using Purview.Telemetry.Activities; + +namespace Testing; + +[ActivitySource(""testing-activity-source"")] +public interface ITestActivities { + [Context] + void Activity([Baggage]string stringParam, [Tag]int intParam, bool boolParam); + + [Event] + void Event([Baggage]string stringParam, [Tag]int intParam, bool boolParam); +} +"; + + // Act + var generationResult = await GenerateAsync(basicActivity); + + // Assert + await TestHelpers.Verify(generationResult, config: s => s.ScrubInlineGuids(), validateNonEmptyDiagnostics: true); + } + [Fact] public async Task Generate_GivenBasicGenAndNoActivityName_GeneratesActivity() { diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs index 9216d9cd..1f222a3d 100644 --- a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivityAndNoReturn_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -38,6 +38,12 @@ static void RecordExceptionInternal(System.Diagnostics.Activity? activity, Syste activity.AddEvent(recordExceptionEvent); } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Activity() + { + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] public void Context(System.Diagnostics.Activity activityParameter, string? stringParam, int? intParam, bool? boolParam) { diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs index c16bba3d..1128e187 100644 --- a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithActivity_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -38,6 +38,12 @@ static void RecordExceptionInternal(System.Diagnostics.Activity? activity, Syste activity.AddEvent(recordExceptionEvent); } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Activity() + { + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] public System.Diagnostics.Activity Context(System.Diagnostics.Activity activityParameter, string? stringParam, int? intParam, bool? boolParam) { diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs index 11ebaf38..c1009a1a 100644 --- a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithNullableParams_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -38,6 +38,12 @@ static void RecordExceptionInternal(System.Diagnostics.Activity? activity, Syste activity.AddEvent(recordExceptionEvent); } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Activity() + { + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] public System.Diagnostics.Activity Context(string? stringParam, int? intParam, bool? boolParam) { diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs index 727b7804..6cb441c9 100644 --- a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningActivity_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -38,6 +38,12 @@ static void RecordExceptionInternal(System.Diagnostics.Activity? activity, Syste activity.AddEvent(recordExceptionEvent); } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Activity() + { + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] public System.Diagnostics.Activity Context(string stringParam, int intParam, bool boolParam) { diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs index 3befd724..050c8711 100644 --- a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGenWithReturningNullableActivity_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -38,6 +38,12 @@ static void RecordExceptionInternal(System.Diagnostics.Activity? activity, Syste activity.AddEvent(recordExceptionEvent); } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Activity() + { + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] public System.Diagnostics.Activity Context(string stringParam, int intParam, bool boolParam) { diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs index 2dbbca5d..bcb52cf1 100644 --- a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicContextGen_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -38,6 +38,12 @@ static void RecordExceptionInternal(System.Diagnostics.Activity? activity, Syste activity.AddEvent(recordExceptionEvent); } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Activity() + { + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] public void Context(string stringParam, int intParam, bool boolParam) { diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs index 7131bd56..cb4decef 100644 --- a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithActivityParameter_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -38,6 +38,12 @@ static void RecordExceptionInternal(System.Diagnostics.Activity? activity, Syste activity.AddEvent(recordExceptionEvent); } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Activity() + { + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] public void Event(System.Diagnostics.Activity activity, string stringParam, int intParam, bool boolParam) { diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs index 88a8f54b..0cc9e7be 100644 --- a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicEventWithNullableActivityParameter_GeneratesActivity.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -38,6 +38,12 @@ static void RecordExceptionInternal(System.Diagnostics.Activity? activity, Syste activity.AddEvent(recordExceptionEvent); } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Activity() + { + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] public void Event(System.Diagnostics.Activity? activity, string stringParam, int intParam, bool boolParam) { diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..1236d492 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..37b12691 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true) + { + if (string.IsNullOrWhiteSpace(name)) + { + throw new System.ArgumentNullException(nameof(name)); + } + + Name = name; + DefaultToTags = defaultToTags; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..928be3cf --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,70 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("testing-activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Activity(string stringParam, int intParam, bool boolParam) + { + if (System.Diagnostics.Activity.Current != null) + { + System.Diagnostics.Activity.Current.SetTag("intparam", intParam); + System.Diagnostics.Activity.Current.SetTag("boolparam", boolParam); + System.Diagnostics.Activity.Current.SetBaggage("stringparam", stringParam); + } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(string stringParam, int intParam, bool boolParam) + { + if (System.Diagnostics.Activity.Current != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEvent = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionEvent.Add("intparam", intParam); + tagsCollectionEvent.Add("boolparam", boolParam); + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: tagsCollectionEvent); + + System.Diagnostics.Activity.Current.AddEvent(activityEventEvent); + + System.Diagnostics.Activity.Current.SetBaggage("stringparam", stringParam); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0.verified.txt b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0.verified.txt new file mode 100644 index 00000000..87b60420 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenBasicInterfaceWithNoActivity_GeneratesDiagnostic.DotNet8_0.verified.txt @@ -0,0 +1,14 @@ +{ + Diagnostics: [ + { + Id: TSG3012, + Title: There are no Activity methods defined, assumed use of Activity.Current., + Severity: Info, + WarningLevel: 1, + Location: Guid_1: (9,0)-(16,1), + MessageFormat: As Event and/ or Context methods are defined, it's best practise to create a specific Activity otherwise the Activity will belong to another operation., + Message: As Event and/ or Context methods are defined, it's best practise to create a specific Activity otherwise the Activity will belong to another operation., + Category: Activity.Usage + } + ] +} \ No newline at end of file diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ActivityAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ActivityAttribute.g.verified.cs new file mode 100644 index 00000000..1236d492 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ActivityAttribute.g.verified.cs @@ -0,0 +1,84 @@ +//HintName: ActivityAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of activities. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivityAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivityAttribute() + { + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(string name) + { + Name = name; + } + + /// + /// Constructs a new and specifies the . + /// + /// Specifies the . + public ActivityAttribute(System.Diagnostics.ActivityKind kind) + { + Kind = kind; + } + + /// + /// Constructs a new and specifies the and + /// optionally the and/ or . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies . + public ActivityAttribute(string name, System.Diagnostics.ActivityKind kind, bool createOnly = false) + { + Name = name; + Kind = kind; + CreateOnly = createOnly; + } + + /// + /// Optional. Gets/ sets the name of the . + /// If this is not specified, the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Optional. Gets/ sets the kind of the + /// activity. Defaults to . + /// + public System.Diagnostics.ActivityKind Kind { get; set; } = System.Diagnostics.ActivityKind.Internal; + + /// + /// If true, the is created using + /// , meaning it is not started by default. Otherwise + /// is used. The default is false. + /// + public bool CreateOnly { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ActivitySourceAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ActivitySourceAttribute.g.verified.cs new file mode 100644 index 00000000..14ef177c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ActivitySourceAttribute.g.verified.cs @@ -0,0 +1,76 @@ +//HintName: ActivitySourceAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for +/// and generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + public ActivitySourceAttribute() + { + } + + /// + /// Constructs a new specifying the . + /// + /// The . + public ActivitySourceAttribute(string name) + { + Name = name; + } + + /// + /// Sets the name for the generated , + /// overriding the . + /// + public string? Name { get; set; } + + /// + /// Specifies the default when inferring between + /// or + /// , unless + /// explicitly marked. + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines if the (or ) + /// is used as a prefix, before the . + /// + public bool IncludeActivitySourcePrefix { get; set; } = true; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased. + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ActivitySourceGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ActivitySourceGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..37b12691 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ActivitySourceGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: ActivitySourceGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines the default for generated +/// activities and events. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ActivitySourceGenerationAttribute : System.Attribute +{ + /// + /// Constructs a new . + /// + /// The name of the activity source. + /// Determines if the default for method parameters are Tags (default) or Baggage. + /// If the is null, empty or whitespace. + public ActivitySourceGenerationAttribute(string name, bool defaultToTags = true) + { + if (string.IsNullOrWhiteSpace(name)) + { + throw new System.ArgumentNullException(nameof(name)); + } + + Name = name; + DefaultToTags = defaultToTags; + } + + /// + /// Specifies the default to use. + /// + public string Name { get; } + + /// + /// Specifies the default used when inferring between + /// + /// or , unless + /// explicitly marked. Overridden when specifying . + /// + public bool DefaultToTags { get; set; } = true; + + /// + /// Prefix used to when generating the tag or baggage name. Prepended + /// before the or + /// , unless + /// explicitly marked. Overridden when specifying . + /// + public string? BaggageAndTagPrefix { get; set; } + + /// + /// Determines the separator used between the and + /// the various prefix options. The default is a period. + /// + public string BaggageAndTagSeparator { get; set; } = "."; + + /// + /// Determines if the or + /// (including + /// any prefixes) are lowercased, unless + /// explicitly marked. Overridden when specifying . + /// + public bool LowercaseBaggageAndTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#AutoCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#AutoCounterAttribute.g.verified.cs new file mode 100644 index 00000000..0a6f422a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#AutoCounterAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: AutoCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a +/// that auto-increments when called. +/// +/// This is equivalent to applying the with the +/// property set to true. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class AutoCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public AutoCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public AutoCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#BaggageAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#BaggageAttribute.g.verified.cs new file mode 100644 index 00000000..0ef5346f --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#BaggageAttribute.g.verified.cs @@ -0,0 +1,66 @@ +//HintName: BaggageAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute required for explicitly setting a +/// parameter as baggage when generating and +/// or an . +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class BaggageAttribute : System.Attribute +{ + /// + /// Create a new . + /// + public BaggageAttribute() + { + } + + /// + /// Create a new and sets the + /// property. + /// + public BaggageAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Create a new and sets the + /// and optionally the property. + /// + /// Sets the . + /// Optionally sets the (defaults to false). + public BaggageAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Specifies the name of the baggage item. If null, empty or whitespace + /// defaults to the name of the parameter. + /// + public string? Name { get; set; } + + /// + /// Determines if the parameter should be skipped when the value is a default value. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ContextAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ContextAttribute.g.verified.cs new file mode 100644 index 00000000..6aa1d127 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ContextAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: ContextAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Determines if the methods parameters should be +/// added to the current , using +/// either the , +/// the or inferred. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ContextAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#CounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#CounterAttribute.g.verified.cs new file mode 100644 index 00000000..eb858169 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#CounterAttribute.g.verified.cs @@ -0,0 +1,83 @@ +//HintName: CounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class CounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public CounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// . + /// + /// Specifies the . + public CounterAttribute(bool autoIncrement) + { + AutoIncrement = autoIncrement; + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the counter is auto incremented. + public CounterAttribute(string name, string? unit = null, string? description = null, bool autoIncrement = false) + { + Name = name; + Unit = unit; + Description = description; + AutoIncrement = autoIncrement; + } + + /// + /// If true, when the method is called the counter is automatically incremented (+1). + /// Otherwise a parameter value must be specified (either inferred or via using + /// the ). + /// + public bool AutoIncrement { get; set; } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#EscapeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#EscapeAttribute.g.verified.cs new file mode 100644 index 00000000..d72ac24a --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#EscapeAttribute.g.verified.cs @@ -0,0 +1,28 @@ +//HintName: EscapeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Used during generation +/// when specifying an . When true, determines if the +/// exception should be marked as escaped, i.e. the exception caused the +/// process/ action to end unexpectedly. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class EscapeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#EventAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#EventAttribute.g.verified.cs new file mode 100644 index 00000000..c92b1b87 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#EventAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: EventAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Activities; + +/// +/// Marker attribute used to control the generation +/// of events. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class EventAttribute : System.Attribute +{ + /// + /// Generates a new . + /// + public EventAttribute() + { + } + + /// + /// Generates a new , specifying the and optionally + /// the property and/ or . + /// + public EventAttribute(string name, bool useRecordExceptionRules = true, bool recordExceptionAsEscaped = true) + { + Name = name; + UseRecordExceptionRules = useRecordExceptionRules; + RecordExceptionAsEscaped = recordExceptionAsEscaped; + } + + /// + /// Optional. Gets/ sets the name of the event. If null, empty or whitespace + /// then the name of the method is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the event should use OpenTelemetry exception recording rules. + /// + public bool UseRecordExceptionRules { get; set; } = true; + + /// + /// Determines if a recorded exception (when is true and an exception parameter exists) + /// if the exception prevented the operation from completing (true) or if the exception was caught and handled (false) + /// and did not affect the operation. Alternatively, use the to override this value by + /// providing a value dynamically. + /// + public bool RecordExceptionAsEscaped { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ExcludeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ExcludeAttribute.g.verified.cs new file mode 100644 index 00000000..70179ce5 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ExcludeAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: ExcludeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Excludes the method from any activity, logging or meter generation. +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class ExcludeAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#HistogramAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#HistogramAttribute.g.verified.cs new file mode 100644 index 00000000..436e42e1 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#HistogramAttribute.g.verified.cs @@ -0,0 +1,62 @@ +//HintName: HistogramAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class HistogramAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public HistogramAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public HistogramAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; internal set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; internal set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; internal set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#InstrumentMeasurementAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#InstrumentMeasurementAttribute.g.verified.cs new file mode 100644 index 00000000..d47a446e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#InstrumentMeasurementAttribute.g.verified.cs @@ -0,0 +1,25 @@ +//HintName: InstrumentMeasurementAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Determines if the parameter is an instrument measurement. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +sealed class InstrumentMeasurementAttribute : System.Attribute +{ +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#LogAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#LogAttribute.g.verified.cs new file mode 100644 index 00000000..b1043483 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#LogAttribute.g.verified.cs @@ -0,0 +1,104 @@ +//HintName: LogAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for log entry generation, based on +/// high-performance . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LogAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LogAttribute() + { + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(string messageTemplate) + { + MessageTemplate = messageTemplate; + } + + /// + /// Creates a new instance of the , specifying the . + /// + /// Specifies the . + public LogAttribute(int eventId) + { + EventId = eventId; + } + + /// + /// Creates a new instance of the , specifying the , + /// optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + Name = name; + } + + /// + /// Creates a new instance of the , specifying the + /// and the , optionally the and . + /// + /// Specifies the . + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public LogAttribute(int eventId, Microsoft.Extensions.Logging.LogLevel level, string? messageTemplate = null, string? name = null) + { + Level = level; + MessageTemplate = messageTemplate; + EventId = eventId; + Name = name; + } + + /// + /// Optional. Gets/ sets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel Level { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The message template used for the log entry, otherwise one is + /// generated based on the parameters. + /// + public string? MessageTemplate { get; set; } + + /// + /// Optional. The event Id for this log entry. If one is not specified, one is automatically generated. + /// + public int? EventId { get; set; } + + /// + /// Optional. Gets/ set the name of the log entry. If one is not specified, the method name is used. + /// + public string? Name { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#LogPrefixType.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#LogPrefixType.g.verified.cs new file mode 100644 index 00000000..1d8739ad --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#LogPrefixType.g.verified.cs @@ -0,0 +1,49 @@ +//HintName: LogPrefixType.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// The types of prefixes that can be used for the log entry name generation. +/// +enum LogPrefixType +{ + /// + /// The name of the interface without the "I" prefix or "Log", "Logger" or "Telemetry" suffixes. + /// + Default, + + /// + /// The name of the interface. + /// + Interface, + + /// + /// The name of the class either specified or generated. + /// + Class, + + /// + /// Uses the custom name specified by . This is used when + /// the is set + /// regardless of . + /// + Custom, + + /// + /// No suffix is added to the name. + /// + NoSuffix +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#LoggerAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#LoggerAttribute.g.verified.cs new file mode 100644 index 00000000..bdf65f19 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#LoggerAttribute.g.verified.cs @@ -0,0 +1,68 @@ +//HintName: LoggerAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Marker attribute required for Log generation. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public LoggerAttribute() + { + + } + + /// + /// Creates a new instance of the , specifying the + /// and optionally the . + /// + /// The default to use + /// when one is not specified. + /// If specified, also sets the to . + public LoggerAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel, string? customPrefix = null) + { + DefaultLevel = defaultLevel; + CustomPrefix = customPrefix; + + if (CustomPrefix != null) + { + PrefixType = LogPrefixType.Custom; + } + } + + /// + /// Optional. Gets the level of the + /// log entry. Defaults to , unless there is + /// an parameter and no-other override is defined. + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; + + /// + /// Optional. The prefix used to when generating the log entry name. + /// + public string? CustomPrefix { get; set; } + + /// + /// Specifies the mode used to generate or override the prefix for the log entry. + /// + public LogPrefixType PrefixType { get; set; } = LogPrefixType.Default; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#LoggerGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#LoggerGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5001fb9c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#LoggerGenerationAttribute.g.verified.cs @@ -0,0 +1,48 @@ +//HintName: LoggerGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Logging; + +/// +/// Sets defaults for the generation of loggers and log entries. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class LoggerGenerationAttribute : System.Attribute +{ + /// + /// Creates a new instance of . + /// + public LoggerGenerationAttribute() + { + } + + /// + /// Creates a new instance of with the specified + /// . + /// + /// + public LoggerGenerationAttribute(Microsoft.Extensions.Logging.LogLevel defaultLevel) + { + DefaultLevel = defaultLevel; + } + + /// + /// Gets/ sets the default level of the + /// logger. Defaults to . + /// + public Microsoft.Extensions.Logging.LogLevel DefaultLevel { get; set; } = Microsoft.Extensions.Logging.LogLevel.Information; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#MeterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#MeterAttribute.g.verified.cs new file mode 100644 index 00000000..2bf8962b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#MeterAttribute.g.verified.cs @@ -0,0 +1,72 @@ +//HintName: MeterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicating a meter, or group of instruments. +/// +[System.AttributeUsage(System.AttributeTargets.Interface, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterAttribute : System.Attribute +{ + /// + /// Creates a new . + /// + public MeterAttribute() + { + } + + /// + /// Creates a new , specifying the . + /// + /// Specifies the . + public MeterAttribute(string name) + { + Name = name; + } + + /// + /// Optional. Gets/ sets the name of the meter, used for creating + /// a named grouped of instruments. + /// + public string? Name { get; set; } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, determines if is + /// included in the generated name. + /// + public bool IncludeAssemblyInstrumentPrefix { get; set; } = true; + + /// + /// Determines if the , , + /// , , + /// or (including + /// any prefixes) are lowercased. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Determines if the (including + /// any prefixes) are lowercased. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#MeterGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#MeterGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..6c5d7f6c --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#MeterGenerationAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: MeterGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Marker attribute, used to indicate a meter (or group of instruments) and how they should be generated. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class MeterGenerationAttribute : System.Attribute +{ + /// + /// Creates a new with optional + /// , + /// and/ or . + /// + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public MeterGenerationAttribute(string? instrumentPrefix = null, bool lowercaseInstrumentName = true, bool lowercaseTagKeys = true) + { + InstrumentPrefix = instrumentPrefix; + LowercaseInstrumentName = lowercaseInstrumentName; + LowercaseTagKeys = lowercaseTagKeys; + } + + /// + /// Optional, gets/ sets the prefix used when generating the instrument name. + /// + public string? InstrumentPrefix { get; set; } + + /// + /// Optional, gets/ sets the separator used when + /// pre-pending any prefixes. Defaults to period. + /// + public string InstrumentSeparator { get; set; } = "."; + + /// + /// Optional, gets/ sets a value indicating if the + /// instrument name is lowercased. Defaults to true. + /// + public bool LowercaseInstrumentName { get; set; } = true; + + /// + /// Optional, get/ sets a value indicating if any tag + /// keys/ names are lowercased. Defaults to true. + /// + public bool LowercaseTagKeys { get; set; } = true; +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ObservableCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ObservableCounterAttribute.g.verified.cs new file mode 100644 index 00000000..9c3eb70d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ObservableCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ObservableGaugeAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ObservableGaugeAttribute.g.verified.cs new file mode 100644 index 00000000..427c5b1d --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ObservableGaugeAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableGaugeAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableGaugeAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableGaugeAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableGaugeAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ObservableUpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ObservableUpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..50d37b8e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#ObservableUpDownCounterAttribute.g.verified.cs @@ -0,0 +1,71 @@ +//HintName: ObservableUpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class ObservableUpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public ObservableUpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the , + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + /// Optionally specifies if the observable counter throws an exception if it is already initialised. . + public ObservableUpDownCounterAttribute(string name, string? unit = null, string? description = null, bool throwOnAlreadyInitialized = false) + { + Name = name; + Unit = unit; + Description = description; + ThrowOnAlreadyInitialized = throwOnAlreadyInitialized; + } + + /// + /// Optionally specifies the name of the instrument. If + /// one is not specified, the method is used. + /// + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } + + /// + /// Optional, determines if the instrument method throws + /// if it's already initialised. Defaults to false. + /// + public bool ThrowOnAlreadyInitialized { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#TagAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#TagAttribute.g.verified.cs new file mode 100644 index 00000000..d6936756 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#TagAttribute.g.verified.cs @@ -0,0 +1,67 @@ +//HintName: TagAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to specify that a parameter should be included as a tag. +/// +[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TagAttribute : System.Attribute +{ + /// + /// Creates a new instance of a . + /// + public TagAttribute() + { + } + + /// + /// Creates a new instance of a and specifies the + /// property. + /// + /// Specifies the . + public TagAttribute(bool skipOnNullOrEmpty) + { + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Creates a new instance of a and specifies the + /// property, and optionally the + /// property. + /// + /// Specifies the key/ name of the tag. + /// Optionally specifies the . + public TagAttribute(string? name, bool skipOnNullOrEmpty = false) + { + Name = name; + SkipOnNullOrEmpty = skipOnNullOrEmpty; + } + + /// + /// Optionally specifies the key/ name of the tag. If one is not specified, + /// the of the parameter is used. + /// + public string? Name { get; set; } + + /// + /// Determines if the tag is skipped if it equals it's default value. + /// Defaults to false. + /// + public bool SkipOnNullOrEmpty { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#TelemetryGenerationAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#TelemetryGenerationAttribute.g.verified.cs new file mode 100644 index 00000000..5043562e --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#TelemetryGenerationAttribute.g.verified.cs @@ -0,0 +1,78 @@ +//HintName: TelemetryGenerationAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry; + +/// +/// Marker attribute to control the generation of telemetry-based classes. +/// +[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Interface, AllowMultiple = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class TelemetryGenerationAttribute : System.Attribute +{ + /// + /// Initializes a new instance of the class. + /// + public TelemetryGenerationAttribute() + { + } + + /// + /// Initializes a new instance of the class, and + /// specifies the property and optionally the + /// and properties. + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(bool generateDependencyExtension, string? className = null, string? dependencyInjectionClassName = null) + { + GenerateDependencyExtension = generateDependencyExtension; + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Initializes a new instance of the class, and + /// specifies the and optionally the property. + /// + /// Specifies the . + /// Optionally specifies the . + public TelemetryGenerationAttribute(string className, string? dependencyInjectionClassName = null) + { + ClassName = className; + DependencyInjectionClassName = dependencyInjectionClassName; + } + + /// + /// Determines if an extension method is created registering + /// the source interface and the generated class with + /// and . + /// + public bool GenerateDependencyExtension { get; set; } = true; + + /// + /// Optionally specifies the name of the telemetry implementation class to use. + /// Defaults to null. When null, uses the source interface name minus any starting 'I', + /// and appends 'Core' to the end. + /// + public string? ClassName { get; set; } + + /// + /// Optionally specifies the name of the dependency injection class to generation. + /// + public string? DependencyInjectionClassName { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs new file mode 100644 index 00000000..928be3cf --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#Testing.TestActivitiesCore.Activity.g.verified.cs @@ -0,0 +1,70 @@ +//HintName: Testing.TestActivitiesCore.Activity.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Testing +{ + sealed partial class TestActivitiesCore : Testing.ITestActivities + { + readonly static System.Diagnostics.ActivitySource _activitySource = new System.Diagnostics.ActivitySource("testing-activity-source"); + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + static void RecordExceptionInternal(System.Diagnostics.Activity? activity, System.Exception? exception, bool escape) + { + if (activity == null || exception == null) + { + return; + } + + System.Diagnostics.ActivityTagsCollection tagsCollection = new System.Diagnostics.ActivityTagsCollection(); + tagsCollection.Add("exception.escaped", escape); + tagsCollection.Add("exception.message", exception.Message); + tagsCollection.Add("exception.type", exception.GetType().FullName); + tagsCollection.Add("exception.stacktrace", exception.StackTrace); + + System.Diagnostics.ActivityEvent recordExceptionEvent = new System.Diagnostics.ActivityEvent(name: "exception", timestamp: default, tags: tagsCollection); + + activity.AddEvent(recordExceptionEvent); + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Activity(string stringParam, int intParam, bool boolParam) + { + if (System.Diagnostics.Activity.Current != null) + { + System.Diagnostics.Activity.Current.SetTag("intparam", intParam); + System.Diagnostics.Activity.Current.SetTag("boolparam", boolParam); + System.Diagnostics.Activity.Current.SetBaggage("stringparam", stringParam); + } + } + + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Event(string stringParam, int intParam, bool boolParam) + { + if (System.Diagnostics.Activity.Current != null) + { + System.Diagnostics.ActivityTagsCollection tagsCollectionEvent = new System.Diagnostics.ActivityTagsCollection(); + tagsCollectionEvent.Add("intparam", intParam); + tagsCollectionEvent.Add("boolparam", boolParam); + + System.Diagnostics.ActivityEvent activityEventEvent = new System.Diagnostics.ActivityEvent(name: "Event", timestamp: default, tags: tagsCollectionEvent); + + System.Diagnostics.Activity.Current.AddEvent(activityEventEvent); + + System.Diagnostics.Activity.Current.SetBaggage("stringparam", stringParam); + } + } + + } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#UpDownCounterAttribute.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#UpDownCounterAttribute.g.verified.cs new file mode 100644 index 00000000..1794bd8b --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0#UpDownCounterAttribute.g.verified.cs @@ -0,0 +1,63 @@ +//HintName: UpDownCounterAttribute.g.cs +//------------------------------------------------------------------------------ +// +// This code was generated by the Purview.Telemetry.SourceGenerator +// on {Scrubbed}. +// +// Changes to this file may cause incorrect behaviour and will be lost +// when the code is regenerated. +// +//------------------------------------------------------------------------------ + +#pragma warning disable 1591 // publicly visible type or member must be documented + +#nullable enable + +namespace Purview.Telemetry.Metrics; + +/// +/// Specifies the meter type generated corresponds to a . +/// +[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)] +[System.Diagnostics.Conditional("PURVIEW_TELEMETRY_ATTRIBUTES")] +[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1019:Define accessors for attribute arguments")] +sealed class UpDownCounterAttribute : System.Attribute +{ + /// + /// Creates a new instance of the class. + /// + public UpDownCounterAttribute() + { + } + + /// + /// Creates a new instance of the class, and specifies the + /// , and optionally the and . + /// + /// Specifies the . + /// Optionally specifies the . + /// Optionally specifies the . + public UpDownCounterAttribute(string name, string? unit = null, string? description = null) + { + Name = name; + Unit = unit; + Description = description; + } + + /// + /// Optionally specifies the name of the meter. If one is not specified, the name + /// of the method is used. + /// + + public string? Name { get; set; } + + /// + /// Optionally specifies the unit of the meter. + /// + public string? Unit { get; set; } + + /// + /// Optionally specifies the description of the meter. + /// + public string? Description { get; set; } +} diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0.verified.txt b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0.verified.txt new file mode 100644 index 00000000..87b60420 --- /dev/null +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorActivityTests.Generate_GivenInterfaceWithNoActivityButOtherActivityBasedMethods_GeneratesDiagnostic.DotNet8_0.verified.txt @@ -0,0 +1,14 @@ +{ + Diagnostics: [ + { + Id: TSG3012, + Title: There are no Activity methods defined, assumed use of Activity.Current., + Severity: Info, + WarningLevel: 1, + Location: Guid_1: (9,0)-(16,1), + MessageFormat: As Event and/ or Context methods are defined, it's best practise to create a specific Activity otherwise the Activity will belong to another operation., + Message: As Event and/ or Context methods are defined, it's best practise to create a specific Activity otherwise the Activity will belong to another operation., + Category: Activity.Usage + } + ] +} \ No newline at end of file diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet8_0#Testing.TestTelemetryCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet8_0#Testing.TestTelemetryCore.Activity.g.verified.cs index 27b884af..f31b91d7 100644 --- a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet8_0#Testing.TestTelemetryCore.Activity.g.verified.cs +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndDisabledOTelExceptionRulesAndEscape_GeneratesTelemetry.DotNet8_0#Testing.TestTelemetryCore.Activity.g.verified.cs @@ -38,6 +38,12 @@ static void RecordExceptionInternal(System.Diagnostics.Activity? activity, Syste activity.AddEvent(recordExceptionEvent); } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Activity() + { + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] public void EventMethod(string stringParam, int intParam, bool boolParam, System.Exception anException, bool escape) { diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet8_0#Testing.TestTelemetryCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet8_0#Testing.TestTelemetryCore.Activity.g.verified.cs index 7db5ef4e..8255ab90 100644 --- a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet8_0#Testing.TestTelemetryCore.Activity.g.verified.cs +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExceptionAndEscape_GeneratesTelemetry.DotNet8_0#Testing.TestTelemetryCore.Activity.g.verified.cs @@ -38,6 +38,12 @@ static void RecordExceptionInternal(System.Diagnostics.Activity? activity, Syste activity.AddEvent(recordExceptionEvent); } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Activity() + { + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] public void Event(string stringParam, int intParam, bool boolParam, System.Exception anException, bool escape) { diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet8_0#Testing.TestTelemetryCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet8_0#Testing.TestTelemetryCore.Activity.g.verified.cs index 8f675f07..55116563 100644 --- a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet8_0#Testing.TestTelemetryCore.Activity.g.verified.cs +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithException_GeneratesTelemetry.DotNet8_0#Testing.TestTelemetryCore.Activity.g.verified.cs @@ -38,6 +38,12 @@ static void RecordExceptionInternal(System.Diagnostics.Activity? activity, Syste activity.AddEvent(recordExceptionEvent); } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Activity() + { + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] public void Event(string stringParam, int intParam, bool boolParam, System.Exception anException) { diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet8_0#Testing.TestTelemetryCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet8_0#Testing.TestTelemetryCore.Activity.g.verified.cs index db02052b..03e0aefe 100644 --- a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet8_0#Testing.TestTelemetryCore.Activity.g.verified.cs +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndEventIsNamedExceptionAndRulesAreTrue_GeneratesTelemetry.DotNet8_0#Testing.TestTelemetryCore.Activity.g.verified.cs @@ -38,6 +38,12 @@ static void RecordExceptionInternal(System.Diagnostics.Activity? activity, Syste activity.AddEvent(recordExceptionEvent); } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Activity() + { + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] public void EventMethod(string stringParam, int intParam, bool boolParam, System.Exception anException, bool escape) { diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet8_0#Testing.TestTelemetryCore.Activity.g.verified.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet8_0#Testing.TestTelemetryCore.Activity.g.verified.cs index db02052b..03e0aefe 100644 --- a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet8_0#Testing.TestTelemetryCore.Activity.g.verified.cs +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/Snapshots/TelemetrySourceGeneratorTests.Generate_GivenBasicEventWithExplicitExceptionAndNamedExceptionAndRulesAreFalse_GeneratesTelemetry.DotNet8_0#Testing.TestTelemetryCore.Activity.g.verified.cs @@ -38,6 +38,12 @@ static void RecordExceptionInternal(System.Diagnostics.Activity? activity, Syste activity.AddEvent(recordExceptionEvent); } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Activity() + { + System.Diagnostics.Activity? activityActivity = _activitySource.StartActivity(name: "Activity", kind: System.Diagnostics.ActivityKind.Internal, parentId: default, tags: default, links: default, startTime: default); + } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] public void EventMethod(string stringParam, int intParam, bool boolParam, System.Exception anException, bool escape) { diff --git a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/TelemetrySourceGeneratorTests.TelemetryBasic.cs b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/TelemetrySourceGeneratorTests.TelemetryBasic.cs index e73d20ff..9d3c81a8 100644 --- a/src/Purview.Telemetry.SourceGenerator.IntegrationTests/TelemetrySourceGeneratorTests.TelemetryBasic.cs +++ b/src/Purview.Telemetry.SourceGenerator.IntegrationTests/TelemetrySourceGeneratorTests.TelemetryBasic.cs @@ -98,6 +98,9 @@ namespace Testing; [ActivitySource(""activity-source"")] public interface ITestTelemetry { + [Activity] + void Activity(); + [Event] void Event([Baggage]string stringParam, [Tag]int intParam, bool boolParam, Exception anException); } @@ -122,6 +125,9 @@ namespace Testing; [ActivitySource(""activity-source"")] public interface ITestTelemetry { + [Activity] + void Activity(); + [Event] void Event([Baggage]string stringParam, [Tag]int intParam, bool boolParam, Exception anException, [Escape]bool escape); } @@ -146,6 +152,9 @@ namespace Testing; [ActivitySource(""activity-source"")] public interface ITestTelemetry { + [Activity] + void Activity(); + [Event(UseRecordExceptionRules = false)] void EventMethod([Baggage]string stringParam, [Tag]int intParam, bool boolParam, Exception anException, [Escape]bool escape); } @@ -170,6 +179,9 @@ namespace Testing; [ActivitySource(""activity-source"")] public interface ITestTelemetry { + [Activity] + void Activity(); + [Event(name: ""exception"", UseRecordExceptionRules = false)] void EventMethod([Baggage]string stringParam, [Tag]int intParam, bool boolParam, Exception anException, [Escape]bool escape); } @@ -194,6 +206,9 @@ namespace Testing; [ActivitySource(""activity-source"")] public interface ITestTelemetry { + [Activity] + void Activity(); + [Event(name: ""exception"", UseRecordExceptionRules = true)] void EventMethod([Baggage]string stringParam, [Tag]int intParam, bool boolParam, Exception anException, [Escape]bool escape); } diff --git a/src/Purview.Telemetry.SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.Methods.cs b/src/Purview.Telemetry.SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.Methods.cs index 70960ef3..19497608 100644 --- a/src/Purview.Telemetry.SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.Methods.cs +++ b/src/Purview.Telemetry.SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.Methods.cs @@ -13,6 +13,16 @@ static int EmitMethods(ActivitySourceTarget target, StringBuilder builder, int i EmitRecordExceptionEvent(builder, indent, context, logger); + if (!target.ActivityMethods.Any(m => m.MethodType == ActivityMethodType.Activity)) + { + if (target.ActivityMethods.Any(m => m.MethodType != ActivityMethodType.Activity)) + { + logger?.Diagnostic("There are no Activity methods defined, however there are Events/ Context methods."); + + TelemetryDiagnostics.Report(context.ReportDiagnostic, TelemetryDiagnostics.Activities.NoActivityMethodsDefined, target.InterfaceLocation); + } + } + foreach (var methodTarget in target.ActivityMethods) { context.CancellationToken.ThrowIfCancellationRequested(); diff --git a/src/Purview.Telemetry.SourceGenerator/Helpers/PipelineHelpers.Activities.cs b/src/Purview.Telemetry.SourceGenerator/Helpers/PipelineHelpers.Activities.cs index 5004ed24..9699eb7d 100644 --- a/src/Purview.Telemetry.SourceGenerator/Helpers/PipelineHelpers.Activities.cs +++ b/src/Purview.Telemetry.SourceGenerator/Helpers/PipelineHelpers.Activities.cs @@ -85,7 +85,8 @@ partial class PipelineHelpers ActivityTargetAttributeRecord: activitySourceAttribute, - ActivityMethods: activityMethods + ActivityMethods: activityMethods, + InterfaceLocation: interfaceDeclaration.GetLocation() ); } diff --git a/src/Purview.Telemetry.SourceGenerator/Records/ActivityRecords.cs b/src/Purview.Telemetry.SourceGenerator/Records/ActivityRecords.cs index 189b4637..fcb10f03 100644 --- a/src/Purview.Telemetry.SourceGenerator/Records/ActivityRecords.cs +++ b/src/Purview.Telemetry.SourceGenerator/Records/ActivityRecords.cs @@ -1,5 +1,4 @@ using System.Collections.Immutable; - using Microsoft.CodeAnalysis; namespace Purview.Telemetry.SourceGenerator.Records; @@ -23,7 +22,8 @@ record ActivitySourceTarget( ImmutableArray ActivityMethods , - ActivitySourceAttributeRecord ActivityTargetAttributeRecord + ActivitySourceAttributeRecord ActivityTargetAttributeRecord, + Location? InterfaceLocation ); record ActivityBasedGenerationTarget( diff --git a/src/Purview.Telemetry.SourceGenerator/TelemetryDiagnostics.Activities.cs b/src/Purview.Telemetry.SourceGenerator/TelemetryDiagnostics.Activities.cs index eb2a9636..d3d23799 100644 --- a/src/Purview.Telemetry.SourceGenerator/TelemetryDiagnostics.Activities.cs +++ b/src/Purview.Telemetry.SourceGenerator/TelemetryDiagnostics.Activities.cs @@ -103,5 +103,13 @@ public static class Activities Category: Constants.Diagnostics.Activity.Usage, Severity: DiagnosticSeverity.Error ); + + public static readonly TelemetryDiagnosticDescriptor NoActivityMethodsDefined = new( + Id: "TSG3012", + Title: "There are no Activity methods defined, assumed use of Activity.Current.", + Description: "As Event and/ or Context methods are defined, it's best practise to create a specific Activity otherwise the Activity will belong to another operation.", + Category: Constants.Diagnostics.Activity.Usage, + Severity: DiagnosticSeverity.Info + ); } } diff --git a/version.json b/version.json index f1d8edb3..237a567f 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.0.5", + "version": "1.0.6", "cloudBuild": { "buildNumber": { "enabled": true,