From 268e01298803ad94fdb503d62987644145f34d30 Mon Sep 17 00:00:00 2001 From: Kieron Lanning Date: Mon, 7 Sep 2026 01:13:19 +0100 Subject: [PATCH 1/2] chore: updating to latest source gen --- Directory.Packages.props | 11 +- Justfile | 19 +- package.json | 2 +- .../Analyzers/TelemetryDiagnosticAnalyzer.cs | 14 +- ...ourceTargetClassEmitter.ActivityMethods.cs | 8 +- ...SourceTargetClassEmitter.ContextMethods.cs | 5 +- ...tySourceTargetClassEmitter.EventMethods.cs | 12 +- ...ActivitySourceTargetClassEmitter.Fields.cs | 6 +- ...ctivitySourceTargetClassEmitter.Methods.cs | 36 +- .../Emitters/ConstructorEmitter.cs | 6 +- .../DependencyInjectionClassEmitter.cs | 7 +- .../Emitters/GeneratedTypesEmitter.cs | 1447 +++++++++-------- .../LoggerGenTargetClassEmitter.Methods.cs | 40 +- .../Emitters/LoggerGenTargetClassEmitter.cs | 2 +- .../LoggerTargetClassEmitter.Fields.cs | 4 +- .../LoggerTargetClassEmitter.Methods.cs | 6 +- .../MeterTargetClassEmitter.Fields.cs | 7 +- ...TargetClassEmitter.InitializationMethod.cs | 10 +- .../MeterTargetClassEmitter.Methods.cs | 10 +- .../Emitters/MeterTargetClassEmitter.cs | 6 +- .../Emitters/TelemetryNamesEmitter.cs | 2 +- .../TypeLibraryExtensions.cs | 58 + .../TelemetrySourceGenerator.Activities.cs | 8 + .../TelemetrySourceGenerator.Logging.cs | 10 +- .../TelemetrySourceGenerator.Metrics.cs | 8 + ...TelemetrySourceGenerator.TelemetryNames.cs | 8 + .../Generators/TelemetrySourceGenerator.cs | 6 +- .../Helpers/DiagnosticLibrary.Activities.cs | 2 +- .../Helpers/DiagnosticLibrary.General.cs | 11 +- .../Helpers/InstrumentMethodModelBuilder.cs | 22 +- .../Helpers/LogMethodModelBuilder.cs | 14 +- .../Helpers/PipelineHelpers.Activities.cs | 39 +- .../Helpers/PipelineHelpers.Logger.cs | 2 +- .../Helpers/PropertyLibrary.cs | 54 +- .../Helpers/SharedHelpers.Activities.cs | 19 +- .../Helpers/SharedHelpers.Logging.cs | 29 +- .../Helpers/SharedHelpers.Metrics.cs | 11 +- .../SourceGenerator/Helpers/SharedHelpers.cs | 8 +- .../SourceGenerator/Helpers/TypeLibrary.cs | 341 ---- .../TypeLibraryGenerator.Activities.cs | 47 + .../Helpers/TypeLibraryGenerator.Logging.cs | 25 + .../Helpers/TypeLibraryGenerator.Metrics.cs | 34 + .../Helpers/TypeLibraryGenerator.cs | 126 ++ src/src/SourceGenerator/Helpers/Utilities.cs | 52 +- .../Records/AttributeDataModels.cs | 12 +- .../Records/TelemetryRules.Activities.cs | 5 +- .../Records/TelemetryRules.Logging.cs | 6 +- .../SourceGenerator/Records/TelemetryRules.cs | 18 +- .../SourceGenerator/SourceGenerator.csproj | 1 + ...eGeneratorActivityTests.BasicContextGen.cs | 15 +- ...rceGeneratorActivityTests.BasicEventGen.cs | 23 +- ...rySourceGeneratorActivityTests.BasicGen.cs | 7 - ...rySourceGeneratorActivityTests.CSharp73.cs | 2 - ...elemetrySourceGeneratorActivityTests.DI.cs | 14 +- ...ourceGeneratorActivityTests.ParentTests.cs | 7 +- .../TelemetrySourceGeneratorActivityTests.cs | 6 +- ...ourceGeneratorLoggingGen2Tests.CSharp73.cs | 1 - ...eneratorLoggingGen2Tests.ExceptionTests.cs | 7 +- ...eratorLoggingGen2Tests.ExpandEnumerable.cs | 2 +- ...GeneratorLoggingGen2Tests.LogProperties.cs | 29 +- ...ceGeneratorLoggingGen2Tests.PerMethodV1.cs | 8 +- ...urceGeneratorLoggingGen2Tests.ScopedGen.cs | 13 +- ...elemetrySourceGeneratorLoggingGen2Tests.cs | 4 +- ...trySourceGeneratorLoggingTests.BasicGen.cs | 14 +- ...trySourceGeneratorLoggingTests.CSharp73.cs | 1 - ...TelemetrySourceGeneratorLoggingTests.DI.cs | 10 +- ...ourceGeneratorLoggingTests.LogAttribute.cs | 2 - ...metrySourceGeneratorLoggingTests.Nested.cs | 12 +- ...ourceGeneratorLoggingTests.NoILoggerRef.cs | 1 - ...eratorLoggingTests.SpecificLogAttribute.cs | 7 - .../TelemetrySourceGeneratorLoggingTests.cs | 2 +- ...trySourceGeneratorMetricsTests.CSharp73.cs | 17 +- ...trySourceGeneratorMetricsTests.Counters.cs | 16 +- ...TelemetrySourceGeneratorMetricsTests.DI.cs | 10 +- ...emetrySourceGeneratorMetricsTests.Gauge.cs | 6 +- ...rySourceGeneratorMetricsTests.Histogram.cs | 2 - ...SourceGeneratorMetricsTests.MeterNaming.cs | 22 +- ...eratorMetricsTests.NameUnitsDescription.cs | 2 +- ...eneratorMetricsTests.ObservableSpecific.cs | 12 +- ...ourceGeneratorMetricsTests.TagListCount.cs | 2 +- ...metrySourceGeneratorMetricsTests.UpDown.cs | 8 +- .../TelemetrySourceGeneratorMetricsTests.cs | 16 +- ...SourceGeneratorTests.InvalidReturnTypes.cs | 2 +- .../TelemetrySourceGeneratorTests.cs | 25 + .../TelemetrySourceGeneratorTestOptions.cs | 9 +- 85 files changed, 1464 insertions(+), 1508 deletions(-) create mode 100644 src/src/SourceGenerator/Extensions/Purview/SourceGeneratorFramework/TypeLibraryExtensions.cs delete mode 100644 src/src/SourceGenerator/Helpers/TypeLibrary.cs create mode 100644 src/src/SourceGenerator/Helpers/TypeLibraryGenerator.Activities.cs create mode 100644 src/src/SourceGenerator/Helpers/TypeLibraryGenerator.Logging.cs create mode 100644 src/src/SourceGenerator/Helpers/TypeLibraryGenerator.Metrics.cs create mode 100644 src/src/SourceGenerator/Helpers/TypeLibraryGenerator.cs diff --git a/Directory.Packages.props b/Directory.Packages.props index 156a0864..3b5ae4df 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,16 +1,9 @@ true - - 4.14.0 + 5.9.0 1.65.51 - 1.0.0-prerelease.36 + 1.0.0-prerelease.37 diff --git a/Justfile b/Justfile index c063079b..31a16f76 100644 --- a/Justfile +++ b/Justfile @@ -74,6 +74,11 @@ build *args: echo "Building {{ BLUE }}{{ solution_file }}{{ NORMAL }} with {{ YELLOW }}{{ build_configuration }}{{ NORMAL }}..." dotnet build "{{ solution_file }}" --configuration "{{ build_configuration }}" {{ args }} +# Restore NuGet packages for the solution +[group('Build and Test')] +restore *args: + dotnet restore {{ solution_file }} {{ args }} + # Runs tests for the solution with the specified configuration (default: Release) [group('Build and Test')] test filter="/*/*/*/*/" *args: @@ -163,25 +168,33 @@ update-version: # Opens the solution in the default associated application -[group('System/ Shell')] +[group('Utilities')] vs: echo "Opening {{ BLUE }}{{ solution_file }}{{ NORMAL }}..." open "{{ solution_file }}" # Opens the root folder in Visual Studio Code -[group('System/ Shell')] +[group('Utilities')] code: echo "Opening {{ BLUE }}Visual Studio Code{{ NORMAL }}..." code "{{ root_folder }}" # Opens the sample solution in the default associated application -[group('System/ Shell')] +[group('Utilities')] vs-s: echo "Opening {{ BLUE }}{{ sample_solution_file }}{{ NORMAL }}..." open "{{ sample_solution_file }}" +# Clean up the repository by removing build artifacts, bin/obj folders etc, and shutting down the build server +[group('Utilities')] +scrub: + find . -type d \( -name bin -o -name obj \) -exec rm -rf {} + + just clean + just restore --force-evaluate + dotnet build-server shutdown + # ----------------------------------------------------------------------------- # Benchmarking # ----------------------------------------------------------------------------- diff --git a/package.json b/package.json index f2613fd4..dc8aac1a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "purview-telemetry-sourcegenerator", - "version": "5.0.0-prerelease.5", + "version": "5.0.0-prerelease.6", "description": "Generates [`ActivitySource`](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.activitysource), [`ILogger`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.logging.ilogger), and [`Metrics`](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.metrics) based on interface methods.", "readme": "README.md", "repository": { diff --git a/src/src/SourceGenerator/Analyzers/TelemetryDiagnosticAnalyzer.cs b/src/src/SourceGenerator/Analyzers/TelemetryDiagnosticAnalyzer.cs index ef6ee575..cb01bece 100644 --- a/src/src/SourceGenerator/Analyzers/TelemetryDiagnosticAnalyzer.cs +++ b/src/src/SourceGenerator/Analyzers/TelemetryDiagnosticAnalyzer.cs @@ -38,11 +38,19 @@ static void AnalyzeNamedType(SymbolAnalysisContext context) var hasActivitySource = Utilities.ContainsAttribute( interfaceSymbol, - TypeLibrary.Activities.ActivitySourceAttribute, + TypeLibrary.Purview.Telemetry.ActivitySourceAttribute, + token + ); + var hasLogger = Utilities.ContainsAttribute( + interfaceSymbol, + TypeLibrary.Purview.Telemetry.LoggerAttribute, + token + ); + var hasMeter = Utilities.ContainsAttribute( + interfaceSymbol, + TypeLibrary.Purview.Telemetry.MeterAttribute, token ); - var hasLogger = Utilities.ContainsAttribute(interfaceSymbol, TypeLibrary.Logging.LoggerAttribute, token); - var hasMeter = Utilities.ContainsAttribute(interfaceSymbol, TypeLibrary.Metrics.MeterAttribute, token); if (!hasActivitySource && !hasLogger && !hasMeter) return; diff --git a/src/src/SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.ActivityMethods.cs b/src/src/SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.ActivityMethods.cs index 6dbb1ca6..203df099 100644 --- a/src/src/SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.ActivityMethods.cs +++ b/src/src/SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.ActivityMethods.cs @@ -50,7 +50,7 @@ out var _ var activityVariableName = "activity" + methodTarget.MethodName; writer.Assignment( - TypeLibrary.Activities.SystemDiagnostics.Activity.MakeNullable(writer), + TypeLibrary.System.Diagnostics.Activity.MakeNullable(writer), activityVariableName, writeValue: assignmentWriter => { @@ -62,9 +62,7 @@ out var _ var createOnly = methodTarget.ActivityAttribute?.CreateOnly == true; var useParentContext = parentContextOrId != null - && parentContextOrId.ParameterType.Identity.Equals( - TypeLibrary.Activities.SystemDiagnostics.ActivityContext - ); + && parentContextOrId.ParameterType.Identity.Equals(TypeLibrary.System.Diagnostics.ActivityContext); var parentContextParameterName = useParentContext ? "parentContext" : "parentId"; if (createOnly && startTimeParam != null) @@ -120,7 +118,7 @@ out var _ context.CancellationToken.ThrowIfCancellationRequested(); - if (methodTarget.ReturnType.Similar(TypeLibrary.Activities.SystemDiagnostics.Activity)) + if (methodTarget.ReturnType.Similar(TypeLibrary.System.Diagnostics.Activity)) { writer.Return(returnWriter => returnWriter.Write(activityVariableName).Write(methodTarget.ReturnType.IsNullable ? null : "!") diff --git a/src/src/SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.ContextMethods.cs b/src/src/SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.ContextMethods.cs index 0be9f6d8..bbbbe684 100644 --- a/src/src/SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.ContextMethods.cs +++ b/src/src/SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.ContextMethods.cs @@ -1,5 +1,4 @@ using Microsoft.CodeAnalysis; -using Purview.Telemetry.SourceGenerator.Helpers; using Purview.Telemetry.SourceGenerator.Records; namespace Purview.Telemetry.SourceGenerator.Emitters; @@ -34,7 +33,7 @@ out var _ } var activityVariableName = - activityParam?.ParameterName ?? TypeLibrary.Activities.SystemDiagnostics.Activity.StaticMember("Current"); + activityParam?.ParameterName ?? TypeLibrary.System.Diagnostics.Activity.StaticMember("Current"); if (tagsParam != null) { @@ -63,7 +62,7 @@ out var _ context.CancellationToken.ThrowIfCancellationRequested(); - if (methodTarget.ReturnType.Identity.Equals(TypeLibrary.Activities.SystemDiagnostics.Activity)) + if (methodTarget.ReturnType.Identity.Equals(TypeLibrary.System.Diagnostics.Activity)) { writer.NewLine().Write("return ").Write(activityVariableName).Write(";").NewLine(); } diff --git a/src/src/SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.EventMethods.cs b/src/src/SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.EventMethods.cs index 6752ecb7..136c2520 100644 --- a/src/src/SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.EventMethods.cs +++ b/src/src/SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.EventMethods.cs @@ -34,7 +34,7 @@ out var statusDescriptionParam } var activityVariableName = - activityParam?.ParameterName ?? (TypeLibrary.Activities.SystemDiagnostics.Activity + ".Current"); + activityParam?.ParameterName ?? (TypeLibrary.System.Diagnostics.Activity + ".Current"); if (parentContextOrId != null) { output.Context.Diagnostic("Parent context/ Id not allowed on event method, only activities."); @@ -77,12 +77,12 @@ out var statusDescriptionParam writer .NewLine() - .Write(TypeLibrary.Activities.SystemDiagnostics.ActivityEvent) + .Write(TypeLibrary.System.Diagnostics.ActivityEvent) .Write(' ') .Write(eventVariableName) .Write(" = new ") // Use explicit type for C# 7.3 compatibility (target-typed new() requires C# 9+) - .Write(TypeLibrary.Activities.SystemDiagnostics.ActivityEvent) + .Write(TypeLibrary.System.Diagnostics.ActivityEvent) .Write("(name: ") .Write(methodTarget.ActivityOrEventName.Wrap()) // timestamp: @@ -108,7 +108,7 @@ out var statusDescriptionParam context.CancellationToken.ThrowIfCancellationRequested(); - if (methodTarget.ReturnType.Identity.Equals(TypeLibrary.Activities.SystemDiagnostics.Activity)) + if (methodTarget.ReturnType.Identity.Equals(TypeLibrary.System.Diagnostics.Activity)) { writer.NewLine().Write("return ").Write(activityVariableName).Write(";").NewLine(); } @@ -128,11 +128,11 @@ static string EmitEventTags( var tagsListVariableName = "tagsCollection" + methodTarget.MethodName; writer - .Write(TypeLibrary.Activities.SystemDiagnostics.ActivityTagsCollection) + .Write(TypeLibrary.System.Diagnostics.ActivityTagsCollection) .Write(' ') .Write(tagsListVariableName) .Write( - " = new(" // : $" = new {TypeLibrary.Activities.SystemDiagnostics.ActivityTagsCollection}(" + " = new(" // : $" = new {TypeLibrary.System.Diagnostics.ActivityTagsCollection}(" ); if (tagsParam != null) diff --git a/src/src/SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.Fields.cs b/src/src/SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.Fields.cs index a33399a7..9cb77b06 100644 --- a/src/src/SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.Fields.cs +++ b/src/src/SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.Fields.cs @@ -19,20 +19,22 @@ static void EmitFields(ActivityOutputContext output, CodeWriter writer, SourcePr activitySourceName = PropertyLibrary.Activities.DefaultActivitySourceName; } +#pragma warning disable IDE0002 // Simplify Member Access writer .Field( new FieldDeclarationOptions( PropertyLibrary.Activities.ActivitySourceFieldName, - TypeLibrary.Activities.SystemDiagnostics.ActivitySource.AsTypeReference() + TypeLibrary.System.Diagnostics.ActivitySource.AsTypeReference() ) { IsStatic = true, IsReadOnly = true, Initializer = - $"new {(string)TypeLibrary.Activities.SystemDiagnostics.ActivitySource}({activitySourceName!.Wrap()})", + $"new {(string)TypeLibrary.System.Diagnostics.ActivitySource}({activitySourceName!.Wrap()})", IncludeGeneratedAttributes = false, } ) .NewLine(); +#pragma warning restore IDE0002 // Simplify Member Access } } diff --git a/src/src/SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.Methods.cs b/src/src/SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.Methods.cs index 2e83ee00..f55d7aa7 100644 --- a/src/src/SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.Methods.cs +++ b/src/src/SourceGenerator/Emitters/ActivitySourceTargetClassEmitter.Methods.cs @@ -49,7 +49,7 @@ SourceProductionContext context writer.MethodScope( new MethodDeclarationOptions( PropertyLibrary.Activities.RecordExceptionMethodName, - PurviewTypeLibrary.System.Void.AsTypeReference() + TypeLibrary.System.Void.AsTypeReference() ) { IsStatic = true, @@ -57,10 +57,10 @@ SourceProductionContext context [ new ParameterDeclarationOptions( "activity", - TypeLibrary.Activities.SystemDiagnostics.Activity.MakeNullable(writer) + TypeLibrary.System.Diagnostics.Activity.MakeNullable(writer) ), new ParameterDeclarationOptions("exception", TypeLibrary.System.Exception.MakeNullable(writer)), - new ParameterDeclarationOptions("escape", PurviewTypeLibrary.System.Boolean.AsTypeReference()), + new ParameterDeclarationOptions("escape", TypeLibrary.System.Boolean.AsTypeReference()), ], IncludeGeneratedAttributes = false, } @@ -73,9 +73,9 @@ SourceProductionContext context const string tagsListVariableName = "tagsCollection"; writer.Assignment( - TypeLibrary.Activities.SystemDiagnostics.ActivityTagsCollection, + TypeLibrary.System.Diagnostics.ActivityTagsCollection, tagsListVariableName, - "new " + TypeLibrary.Activities.SystemDiagnostics.ActivityTagsCollection + "()" + "new " + TypeLibrary.System.Diagnostics.ActivityTagsCollection + "()" ); EmitExceptionParam(writer, tagsListVariableName, "escape", "exception"); @@ -84,11 +84,11 @@ SourceProductionContext context writer .NewLine() - .Write(TypeLibrary.Activities.SystemDiagnostics.ActivityEvent) + .Write(TypeLibrary.System.Diagnostics.ActivityEvent) .Write(' ') .Write(eventVariableName) .Write(" = new ") - .Write(TypeLibrary.Activities.SystemDiagnostics.ActivityEvent) + .Write(TypeLibrary.System.Diagnostics.ActivityEvent) // name: .Write("(name: ") .Write(PropertyLibrary.Activities.Tag_ExceptionEventName.Wrap()) @@ -299,9 +299,7 @@ SourceProductionContext context ) ) { - var returnsActivity = methodTarget.ReturnType.Identity.Equals( - TypeLibrary.Activities.SystemDiagnostics.Activity - ); + var returnsActivity = methodTarget.ReturnType.Identity.Equals(TypeLibrary.System.Diagnostics.Activity); var paramList = string.Join(", ", methodTarget.Parameters.Select(p => p.ParameterName)); // Create filtered parameter list for Logging/Metrics (excludes Activity-related types) @@ -309,11 +307,11 @@ SourceProductionContext context ", ", methodTarget .Parameters.Where(p => - !p.ParameterType.Identity.Equals(TypeLibrary.Activities.SystemDiagnostics.Activity) - && !p.ParameterType.Identity.Equals(TypeLibrary.Activities.SystemDiagnostics.ActivityContext) - && !p.ParameterType.Identity.Equals(TypeLibrary.Activities.SystemDiagnostics.ActivityLink) - && !p.ParameterType.Identity.Equals(TypeLibrary.Activities.SystemDiagnostics.ActivityLinkArray) - && !p.ParameterType.Identity.Equals(TypeLibrary.System.TagList) + !p.ParameterType.Identity.Equals(TypeLibrary.System.Diagnostics.Activity) + && !p.ParameterType.Identity.Equals(TypeLibrary.System.Diagnostics.ActivityContext) + && !p.ParameterType.Identity.Equals(TypeLibrary.System.Diagnostics.ActivityLink) + && !p.ParameterType.Identity.Equals(TypeLibrary.System.Diagnostics.ActivityLinkArray) + && !p.ParameterType.Identity.Equals(TypeLibrary.System.Diagnostics.TagList) ) .Select(p => p.ParameterName) ); @@ -423,7 +421,7 @@ static bool GuardMethod(ActivityBasedGenerationTarget methodTarget, ActivityOutp var isValidReturnType = isEvent ? methodTarget.ReturnType.Identity.SpecialType == SpecialType.System_Void : methodTarget.ReturnType.Identity.SpecialType == SpecialType.System_Void - || methodTarget.ReturnType.Identity.Equals(TypeLibrary.Activities.SystemDiagnostics.Activity); + || methodTarget.ReturnType.Identity.Equals(TypeLibrary.System.Diagnostics.Activity); if (!isValidReturnType) { @@ -439,7 +437,7 @@ static bool GuardMethod(ActivityBasedGenerationTarget methodTarget, ActivityOutp // Here we're opting in to generate diagnostics for missing activity return/ params. if (methodTarget.MethodType == ActivityMethodType.Activity) { - if (!methodTarget.ReturnType.Identity.Equals(TypeLibrary.Activities.SystemDiagnostics.Activity)) + if (!methodTarget.ReturnType.Identity.Equals(TypeLibrary.System.Diagnostics.Activity)) { output.Context.Diagnostic($"No Activity returned for {methodTarget.MethodName}."); } @@ -455,9 +453,7 @@ static bool GuardMethod(ActivityBasedGenerationTarget methodTarget, ActivityOutp output.Context.Diagnostic($"No Activity parameter is defined on {methodTarget.MethodName}."); } else if ( - !methodTarget - .Parameters[0] - .ParameterType.Identity.Equals(TypeLibrary.Activities.SystemDiagnostics.Activity) + !methodTarget.Parameters[0].ParameterType.Identity.Equals(TypeLibrary.System.Diagnostics.Activity) ) { output.Context.Diagnostic( diff --git a/src/src/SourceGenerator/Emitters/ConstructorEmitter.cs b/src/src/SourceGenerator/Emitters/ConstructorEmitter.cs index 214f98d8..754d1187 100644 --- a/src/src/SourceGenerator/Emitters/ConstructorEmitter.cs +++ b/src/src/SourceGenerator/Emitters/ConstructorEmitter.cs @@ -50,8 +50,8 @@ GenerationContext generationContext if (generationType.HasFlag(GenerationType.Logging)) { - var loggerType = TypeLibrary.Logging.MicrosoftExtensions.ILogger.MakeGeneric(interfaceType); - builder.Add(new ParameterDeclarationOptions(LoggerParameterName, new TypeReference(loggerType))); + var loggerType = TypeLibrary.Microsoft.Extensions.Logging.ILogger.MakeGeneric(interfaceType); + builder.Add(new(LoggerParameterName, new TypeReference(loggerType))); } if (generationType.HasFlag(GenerationType.Metrics) && generationContext.Capabilities.SupportsIMeterFactory) @@ -59,7 +59,7 @@ GenerationContext generationContext builder.Add( new ParameterDeclarationOptions( PropertyLibrary.Metrics.MeterFactoryParameterName, - TypeLibrary.Metrics.SystemDiagnostics.IMeterFactory + TypeLibrary.System.Diagnostics.Metrics.IMeterFactory ) ); } diff --git a/src/src/SourceGenerator/Emitters/DependencyInjectionClassEmitter.cs b/src/src/SourceGenerator/Emitters/DependencyInjectionClassEmitter.cs index 2946f501..0292308d 100644 --- a/src/src/SourceGenerator/Emitters/DependencyInjectionClassEmitter.cs +++ b/src/src/SourceGenerator/Emitters/DependencyInjectionClassEmitter.cs @@ -121,14 +121,17 @@ CancellationToken token writer.MethodScope( new( "Add" + methodName, - TypeLibrary.DependencyInjection.IServiceCollection, + TypeLibrary.Microsoft.Extensions.DependencyInjection.IServiceCollection, TypeDeclarationAccessibility.Public ) { IsStatic = true, Parameters = [ - new("services", TypeLibrary.DependencyInjection.IServiceCollection) { IsThis = true }, + new("services", TypeLibrary.Microsoft.Extensions.DependencyInjection.IServiceCollection) + { + IsThis = true, + }, ], IncludeGeneratedAttributes = false, } diff --git a/src/src/SourceGenerator/Emitters/GeneratedTypesEmitter.cs b/src/src/SourceGenerator/Emitters/GeneratedTypesEmitter.cs index e27eaae2..caf1e7d6 100644 --- a/src/src/SourceGenerator/Emitters/GeneratedTypesEmitter.cs +++ b/src/src/SourceGenerator/Emitters/GeneratedTypesEmitter.cs @@ -1,6 +1,5 @@ using System.Collections.Immutable; using Microsoft.CodeAnalysis; -using Purview.Telemetry.SourceGenerator.Helpers; namespace Purview.Telemetry.SourceGenerator.Emitters; @@ -15,140 +14,146 @@ static class GeneratedTypesEmitter { // Telemetry Shared yield return ( - TypeLibrary.TelemetryShared.TagAttribute, + TypeLibrary.Purview.Telemetry.TagAttribute, (writer, type) => WriteTagLikeAttribute(writer, type, "Marks a parameter as a tag for an activity, event or instrument.") ); yield return ( - TypeLibrary.TelemetryShared.ExcludeAttribute, + TypeLibrary.Purview.Telemetry.ExcludeAttribute, (writer, type) => WriteSimpleAttribute( writer, type, AttributeTargets.Method, includeSuppressMessage: false, - summary: "Marks a method to be excluded from telemetry generation." + "Marks a method to be excluded from telemetry generation." ) ); - yield return (TypeLibrary.TelemetryShared.TelemetryGenerationAttribute, WriteTelemetryGenerationAttribute); - yield return (TypeLibrary.TelemetryShared.Targets, WriteTargetsEnum); - yield return (TypeLibrary.TelemetryShared.NamingConvention, WriteNamingConventionEnum); - yield return (TypeLibrary.TelemetryShared.ExcludeTargetsAttribute, WriteExcludeTargetsAttribute); + yield return (TypeLibrary.Purview.Telemetry.TelemetryGenerationAttribute, WriteTelemetryGenerationAttribute); + yield return (TypeLibrary.Purview.Telemetry.Targets, WriteTargetsEnum); + yield return (TypeLibrary.Purview.Telemetry.NamingConvention, WriteNamingConventionEnum); + yield return (TypeLibrary.Purview.Telemetry.ExcludeTargetsAttribute, WriteExcludeTargetsAttribute); + // Activities yield return ( - TypeLibrary.Activities.BaggageAttribute, + TypeLibrary.Purview.Telemetry.BaggageAttribute, (writer, type) => WriteTagLikeAttribute(writer, type, "Marks a parameter as baggage to be attached to an activity.") ); - yield return (TypeLibrary.Activities.ActivitySourceGenerationAttribute, WriteActivitySourceGenerationAttribute); - yield return (TypeLibrary.Activities.ActivitySourceAttribute, WriteActivitySourceAttribute); - yield return (TypeLibrary.Activities.ActivityAttribute, WriteActivityAttribute); - yield return (TypeLibrary.Activities.EventAttribute, WriteEventAttribute); yield return ( - TypeLibrary.Activities.ContextAttribute, + TypeLibrary.Purview.Telemetry.ActivitySourceGenerationAttribute, + WriteActivitySourceGenerationAttribute + ); + yield return (TypeLibrary.Purview.Telemetry.ActivitySourceAttribute, WriteActivitySourceAttribute); + yield return (TypeLibrary.Purview.Telemetry.ActivityAttribute, WriteActivityAttribute); + yield return (TypeLibrary.Purview.Telemetry.EventAttribute, WriteEventAttribute); + yield return ( + TypeLibrary.Purview.Telemetry.ContextAttribute, (writer, type) => WriteSimpleAttribute( writer, type, AttributeTargets.Method, includeSuppressMessage: false, - summary: "Marks a parameter as an activity context." + "Marks a parameter as an activity context." ) ); yield return ( - TypeLibrary.Activities.EscapeAttribute, + TypeLibrary.Purview.Telemetry.EscapeAttribute, (writer, type) => WriteSimpleAttribute( writer, type, AttributeTargets.Parameter, includeSuppressMessage: false, - summary: "Marks a parameter as the escape flag for a recorded exception." + "Marks a parameter as the escape flag for a recorded exception." ) ); yield return ( - TypeLibrary.Activities.StatusDescriptionAttribute, + TypeLibrary.Purview.Telemetry.StatusDescriptionAttribute, (writer, type) => WriteSimpleAttribute( writer, type, AttributeTargets.Parameter, includeSuppressMessage: false, - summary: "Marks a parameter as the status description of an activity or event." + "Marks a parameter as the status description of an activity or event." ) ); + // Logging - yield return (TypeLibrary.Logging.LoggerGenerationAttribute, WriteLoggerGenerationAttribute); - yield return (TypeLibrary.Logging.LoggerAttribute, WriteLoggerAttribute); - yield return (TypeLibrary.Logging.LogAttribute, WriteLogAttribute); - yield return (TypeLibrary.Logging.LogPrefixType, WriteLogPrefixTypeEnum); - yield return (TypeLibrary.Logging.LoggerGenerationMode, WriteLoggerGenerationModeEnum); - yield return (TypeLibrary.Logging.ExpandEnumerableAttribute, WriteExpandEnumerableAttribute); + yield return (TypeLibrary.Purview.Telemetry.LoggerGenerationAttribute, WriteLoggerGenerationAttribute); + yield return (TypeLibrary.Purview.Telemetry.LoggerAttribute, WriteLoggerAttribute); + yield return (TypeLibrary.Purview.Telemetry.LogAttribute, WriteLogAttribute); + yield return (TypeLibrary.Purview.Telemetry.LogPrefixType, WriteLogPrefixTypeEnum); + yield return (TypeLibrary.Purview.Telemetry.LoggerGenerationMode, WriteLoggerGenerationModeEnum); + yield return (TypeLibrary.Purview.Telemetry.ExpandEnumerableAttribute, WriteExpandEnumerableAttribute); yield return ( - TypeLibrary.Logging.TraceAttribute, + TypeLibrary.Purview.Telemetry.TraceAttribute, (writer, type) => WriteSpecificLogAttribute(writer, type, "Marks a method as a trace-level log method.") ); yield return ( - TypeLibrary.Logging.DebugAttribute, + TypeLibrary.Purview.Telemetry.DebugAttribute, (writer, type) => WriteSpecificLogAttribute(writer, type, "Marks a method as a debug-level log method.") ); yield return ( - TypeLibrary.Logging.InfoAttribute, + TypeLibrary.Purview.Telemetry.InfoAttribute, (writer, type) => WriteSpecificLogAttribute(writer, type, "Marks a method as an informational log method.") ); yield return ( - TypeLibrary.Logging.WarningAttribute, + TypeLibrary.Purview.Telemetry.WarningAttribute, (writer, type) => WriteSpecificLogAttribute(writer, type, "Marks a method as a warning-level log method.") ); yield return ( - TypeLibrary.Logging.ErrorAttribute, + TypeLibrary.Purview.Telemetry.ErrorAttribute, (writer, type) => WriteSpecificLogAttribute(writer, type, "Marks a method as an error-level log method.") ); yield return ( - TypeLibrary.Logging.CriticalAttribute, + TypeLibrary.Purview.Telemetry.CriticalAttribute, (writer, type) => WriteSpecificLogAttribute(writer, type, "Marks a method as a critical-level log method.") ); + // Metrics - yield return (TypeLibrary.Metrics.MeterGenerationAttribute, WriteMeterGenerationAttribute); - yield return (TypeLibrary.Metrics.MeterAttribute, WriteMeterAttribute); - yield return (TypeLibrary.Metrics.MeterNameGenerationType, WriteMeterNameGenerationTypeEnum); + yield return (TypeLibrary.Purview.Telemetry.MeterGenerationAttribute, WriteMeterGenerationAttribute); + yield return (TypeLibrary.Purview.Telemetry.MeterAttribute, WriteMeterAttribute); + yield return (TypeLibrary.Purview.Telemetry.MeterNameGenerationType, WriteMeterNameGenerationTypeEnum); yield return ( - TypeLibrary.Metrics.InstrumentMeasurementAttribute, + TypeLibrary.Purview.Telemetry.InstrumentMeasurementAttribute, (writer, type) => WriteSimpleAttribute( writer, type, AttributeTargets.Parameter, includeSuppressMessage: false, - summary: "Marks a parameter as the measurement value of an instrument." + "Marks a parameter as the measurement value of an instrument." ) ); yield return ( - TypeLibrary.Metrics.AutoCounterAttribute, + TypeLibrary.Purview.Telemetry.AutoCounterAttribute, (writer, type) => WriteAutoCounterAttribute(writer, type, "Marks a method as an auto-incrementing counter instrument.") ); yield return ( - TypeLibrary.Metrics.CounterAttribute, + TypeLibrary.Purview.Telemetry.CounterAttribute, (writer, type) => WriteCounterLikeAttribute(writer, type, "Marks a method as a counter instrument.") ); yield return ( - TypeLibrary.Metrics.UpDownCounterAttribute, + TypeLibrary.Purview.Telemetry.UpDownCounterAttribute, (writer, type) => WriteCounterLikeAttribute(writer, type, "Marks a method as an up-down counter instrument.") ); yield return ( - TypeLibrary.Metrics.HistogramAttribute, + TypeLibrary.Purview.Telemetry.HistogramAttribute, (writer, type) => WriteCounterLikeAttribute(writer, type, "Marks a method as a histogram instrument.") ); yield return ( - TypeLibrary.Metrics.ObservableCounterAttribute, + TypeLibrary.Purview.Telemetry.ObservableCounterAttribute, (writer, type) => WriteObservableCounterLikeAttribute(writer, type, "Marks a method as an observable counter instrument.") ); yield return ( - TypeLibrary.Metrics.ObservableUpDownCounterAttribute, + TypeLibrary.Purview.Telemetry.ObservableUpDownCounterAttribute, (writer, type) => WriteObservableCounterLikeAttribute( writer, @@ -157,7 +162,7 @@ static class GeneratedTypesEmitter ) ); yield return ( - TypeLibrary.Metrics.ObservableGaugeAttribute, + TypeLibrary.Purview.Telemetry.ObservableGaugeAttribute, (writer, type) => WriteObservableCounterLikeAttribute(writer, type, "Marks a method as an observable gauge instrument.") ); @@ -209,11 +214,16 @@ static void EmitAttribute( TypeIdentity type, AttributeTargets targets, Action body, + string summary, bool wrapInExcludeLoggingGuard = false, - bool includeSuppressMessage = true, - string? summary = null + bool includeSuppressMessage = true ) { +#if DEBUG + if (string.IsNullOrWhiteSpace(summary)) + throw new ArgumentException("Summary must be provided for public properties.", nameof(summary)); +#endif + using var scope = wrapInExcludeLoggingGuard ? writer.HashDefinesScope("!EXCLUDE_PURVIEW_TELEMETRY_LOGGING") : writer.EmptyScope(); @@ -223,14 +233,15 @@ static void EmitAttribute( if (includeSuppressMessage) attributes = attributes.Add(SuppressMessageAttribute()); - writer.FileScopedNamespace(TypeLibrary.PurviewTelemetryNamespace); - if (summary != null) - writer.XmlSummary(summary); - writer.AttributeClass( - new(type.Name, TypeDeclarationAccessibility.Internal) { Attributes = attributes }, - targets, - body - ); + writer.FileScopedNamespace(TypeLibrary.Purview.Telemetry.Namespace); + + writer + .XmlSummary(summary) + .AttributeClass( + new(type.Name, TypeDeclarationAccessibility.Internal) { Attributes = attributes }, + targets, + body + ); } static void WriteSimpleAttribute( @@ -238,9 +249,14 @@ static void WriteSimpleAttribute( TypeIdentity type, AttributeTargets targets, bool includeSuppressMessage, - string? summary = null + string summary ) { +#if DEBUG + if (string.IsNullOrWhiteSpace(summary)) + throw new ArgumentException("Summary must be provided for public properties.", nameof(summary)); +#endif + EmitAttribute( writer, type, @@ -267,59 +283,76 @@ static AttributeDeclarationOptions SuppressMessageAttribute() => // Members // ------------------------------------------------------------------------------------------- - static void WriteEmptyConstructor(CodeWriter writer, TypeIdentity type, string? summary = null) + static void WriteEmptyConstructor(CodeWriter writer, TypeIdentity type, string summary) { - if (summary != null) - writer.XmlSummary(summary); - writer.Constructor(new(type.Name, TypeDeclarationAccessibility.Public), static _ => { }); +#if DEBUG + if (string.IsNullOrWhiteSpace(summary)) + throw new ArgumentException("Summary must be provided for public properties.", nameof(summary)); +#endif + + writer.XmlSummary(summary).Constructor(new(type.Name, TypeDeclarationAccessibility.Public), static _ => { }); } - static void WriteNameConstructor(CodeWriter writer, TypeIdentity type, string? summary = null) + static void WriteNameConstructor( + CodeWriter writer, + TypeIdentity type, + string summary, + Action? xmlBody = null + ) { - if (summary != null) - { - writer.XmlSummary(summary); - writer.XmlParam("name", "The name of the telemetry entry."); - } - writer.Constructor( - new(type.Name, TypeDeclarationAccessibility.Public) - { - Parameters = [new("name", PurviewTypeLibrary.System.String.AsTypeReference())], - }, - ctor => ctor.Assignment("Name", "name") - ); +#if DEBUG + if (string.IsNullOrWhiteSpace(summary)) + throw new ArgumentException("Summary must be provided for public properties.", nameof(summary)); +#endif + + writer + .XmlSummary(summary) + .XmlParam("name", "The name of the telemetry entry.") + .Constructor( + new(type.Name, TypeDeclarationAccessibility.Public) + { + Parameters = [new("name", TypeLibrary.System.String)], + }, + ctor => ctor.Assignment("Name", "name") + ); } - static void WriteMessageTemplateConstructor(CodeWriter writer, TypeIdentity type, string? summary = null) + static void WriteMessageTemplateConstructor(CodeWriter writer, TypeIdentity type, string summary) { - if (summary != null) - { - writer.XmlSummary(summary); - writer.XmlParam("messageTemplate", "The message template used to generate the log message."); - } - writer.Constructor( - new(type.Name, TypeDeclarationAccessibility.Public) - { - Parameters = [new("messageTemplate", PurviewTypeLibrary.System.String.AsTypeReference())], - }, - ctor => ctor.Assignment("MessageTemplate", "messageTemplate") - ); +#if DEBUG + if (string.IsNullOrWhiteSpace(summary)) + throw new ArgumentException("Summary must be provided for public properties.", nameof(summary)); +#endif + + writer + .XmlSummary(summary) + .XmlParam("messageTemplate", "The message template used to generate the log message.") + .Constructor( + new(type.Name, TypeDeclarationAccessibility.Public) + { + Parameters = [new("messageTemplate", TypeLibrary.System.String)], + }, + ctor => ctor.Assignment("MessageTemplate", "messageTemplate") + ); } - static void WriteEventIdConstructor(CodeWriter writer, TypeIdentity type, string? summary = null) + static void WriteEventIdConstructor(CodeWriter writer, TypeIdentity type, string summary) { - if (summary != null) - { - writer.XmlSummary(summary); - writer.XmlParam("eventId", "The event identifier of the log entry."); - } - writer.Constructor( - new(type.Name, TypeDeclarationAccessibility.Public) - { - Parameters = [new("eventId", PurviewTypeLibrary.System.Int32.AsTypeReference())], - }, - ctor => ctor.Assignment("EventId", "eventId") - ); +#if DEBUG + if (string.IsNullOrWhiteSpace(summary)) + throw new ArgumentException("Summary must be provided for public properties.", nameof(summary)); +#endif + + writer + .XmlSummary(summary) + .XmlParam("eventId", "The event identifier of the log entry.") + .Constructor( + new(type.Name, TypeDeclarationAccessibility.Public) + { + Parameters = [new("eventId", TypeLibrary.System.Int32)], + }, + ctor => ctor.Assignment("EventId", "eventId") + ); } /// Writes a public property with generated attributes and an optional initializer. @@ -327,36 +360,40 @@ static void WritePublicProperty( CodeWriter writer, string name, TypeReference type, - string? initializer = null, - string? summary = null + string summary, + string? initializer = null ) { - if (summary != null) - writer.XmlSummary(summary); - writer.Property( - new(name, type, TypeDeclarationAccessibility.Public) { HasSetter = true, Initializer = initializer } - ); +#if DEBUG + if (string.IsNullOrWhiteSpace(summary)) + throw new ArgumentException("Summary must be provided for public properties.", nameof(summary)); +#endif + + writer + .XmlSummary(summary) + .Property( + new(name, type, TypeDeclarationAccessibility.Public) { HasSetter = true, Initializer = initializer } + ); } /// /// Writes a public nullable-capable string property inside the NET48_OR_GREATER/ /// PURVIEW_TELEMETRY_NON_NULLABLE preprocessor guard used by the marker attributes. /// - static void WriteNullableStringProperty(CodeWriter writer, string name, string? summary = null) + static void WriteNullableStringProperty(CodeWriter writer, string name, string summary) { +#if DEBUG + if (string.IsNullOrWhiteSpace(summary)) + throw new ArgumentException("Summary must be provided for public properties.", nameof(summary)); +#endif + writer.HashDefines( "NET48_OR_GREATER || PURVIEW_TELEMETRY_NON_NULLABLE", hashWriter => - { - if (summary != null) - hashWriter.XmlSummary(summary); hashWriter + .XmlSummary(summary) .Property( - new( - name, - PurviewTypeLibrary.System.String.AsTypeReference(), - TypeDeclarationAccessibility.Public - ) + new(name, TypeLibrary.System.String, TypeDeclarationAccessibility.Public) { HasSetter = true, IncludeGeneratedAttributes = false, @@ -364,46 +401,46 @@ static void WriteNullableStringProperty(CodeWriter writer, string name, string? ) .HashElse() .Property( - new( - name, - PurviewTypeLibrary.System.String.MakeNullable(writer), - TypeDeclarationAccessibility.Public - ) + new(name, TypeLibrary.System.String.MakeNullable(writer), TypeDeclarationAccessibility.Public) { HasSetter = true, IncludeGeneratedAttributes = false, } - ); - } + ) ); } /// Writes a public non-nullable string property (used for defaults that always have a value). - static void WritePlainStringProperty( - CodeWriter writer, - string name, - string? initializer = null, - string? summary = null - ) + static void WritePlainStringProperty(CodeWriter writer, string name, string summary, string? initializer = null) { - if (summary != null) - writer.XmlSummary(summary); - writer.Property( - new(name, PurviewTypeLibrary.System.String.AsTypeReference(), TypeDeclarationAccessibility.Public) - { - HasSetter = true, - IncludeGeneratedAttributes = false, - Initializer = initializer, - } - ); +#if DEBUG + if (string.IsNullOrWhiteSpace(summary)) + throw new ArgumentException("Summary must be provided for public properties.", nameof(summary)); +#endif + + writer + .XmlSummary(summary) + .Property( + new(name, TypeLibrary.System.String, TypeDeclarationAccessibility.Public) + { + HasSetter = true, + IncludeGeneratedAttributes = false, + Initializer = initializer, + } + ); } // ------------------------------------------------------------------------------------------- // Shared templates // ------------------------------------------------------------------------------------------- - static void WriteTagLikeAttribute(CodeWriter writer, TypeIdentity type, string? summary = null) + static void WriteTagLikeAttribute(CodeWriter writer, TypeIdentity type, string summary) { +#if DEBUG + if (string.IsNullOrWhiteSpace(summary)) + throw new ArgumentException("Summary must be provided for public properties.", nameof(summary)); +#endif + EmitAttribute( writer, type, @@ -414,7 +451,7 @@ static void WriteTagLikeAttribute(CodeWriter writer, TypeIdentity type, string? body.Constructor( new(type.Name, TypeDeclarationAccessibility.Public) { - Parameters = [new("skipOnNullOrEmpty", PurviewTypeLibrary.System.Boolean.AsTypeReference())], + Parameters = [new("skipOnNullOrEmpty", TypeLibrary.System.Boolean)], }, ctor => ctor.Assignment("SkipOnNullOrEmpty", "skipOnNullOrEmpty") ); @@ -428,11 +465,8 @@ static void WriteTagLikeAttribute(CodeWriter writer, TypeIdentity type, string? { Parameters = [ - new("name", PurviewTypeLibrary.System.String.AsTypeReference()), - new("skipOnNullOrEmpty", PurviewTypeLibrary.System.Boolean.AsTypeReference()) - { - DefaultValue = "false", - }, + new("name", TypeLibrary.System.String), + new("skipOnNullOrEmpty", TypeLibrary.System.Boolean) { DefaultValue = "false" }, ], }, ctor => @@ -446,17 +480,17 @@ static void WriteTagLikeAttribute(CodeWriter writer, TypeIdentity type, string? WritePublicProperty( body, "SkipOnNullOrEmpty", - PurviewTypeLibrary.System.Boolean.AsTypeReference(), - summary: "Determines whether the value is skipped when it is null or empty." + TypeLibrary.System.Boolean, + "Determines whether the value is skipped when it is null or empty." ); }, - summary: summary + summary ); } static void WriteTelemetryGenerationAttribute(CodeWriter writer, TypeIdentity type) { - var namingConvention = TypeLibrary.TelemetryShared.NamingConvention; + var namingConvention = TypeLibrary.Purview.Telemetry.NamingConvention; EmitAttribute( writer, @@ -466,64 +500,61 @@ static void WriteTelemetryGenerationAttribute(CodeWriter writer, TypeIdentity ty { WriteEmptyConstructor(body, type, $"Constructs a new instance of the {XmlSee(type.Name)}."); body.XmlSummary( - "Constructs a new instance specifying whether a dependency-injection extension is generated, the generated class name and the dependency-injection class name." - ); - body.XmlParam("generateDependencyExtension", "Whether to generate a dependency-injection extension."); - body.XmlParam("className", "The name of the generated telemetry class."); - body.XmlParam("dependencyInjectionClassName", "The name of the generated dependency-injection class."); - body.Constructor( - new(type.Name, TypeDeclarationAccessibility.Public) - { - Parameters = - [ - new("generateDependencyExtension", PurviewTypeLibrary.System.Boolean.AsTypeReference()), - new("className", PurviewTypeLibrary.System.String.AsTypeReference()) - { - DefaultValue = "null", - }, - new("dependencyInjectionClassName", PurviewTypeLibrary.System.String.AsTypeReference()) - { - DefaultValue = "null", - }, - ], - }, - ctor => - { - ctor.Assignment("GenerateDependencyExtension", "generateDependencyExtension"); - ctor.Assignment("ClassName", "className"); - ctor.Assignment("DependencyInjectionClassName", "dependencyInjectionClassName"); - } - ); + "Constructs a new instance specifying whether a dependency-injection extension is generated, the generated class name and the dependency-injection class name." + ) + .XmlParam("generateDependencyExtension", "Whether to generate a dependency-injection extension.") + .XmlParam("className", "The name of the generated telemetry class.") + .XmlParam("dependencyInjectionClassName", "The name of the generated dependency-injection class.") + .Constructor( + new(type.Name, TypeDeclarationAccessibility.Public) + { + Parameters = + [ + new("generateDependencyExtension", TypeLibrary.System.Boolean), + new("className", TypeLibrary.System.String) { DefaultValue = "null" }, + new("dependencyInjectionClassName", TypeLibrary.System.String) + { + DefaultValue = "null", + }, + ], + }, + ctor => + { + ctor.Assignment("GenerateDependencyExtension", "generateDependencyExtension"); + ctor.Assignment("ClassName", "className"); + ctor.Assignment("DependencyInjectionClassName", "dependencyInjectionClassName"); + } + ); body.XmlSummary( - "Constructs a new instance specifying the generated class name and the dependency-injection class name." - ); - body.XmlParam("className", "The name of the generated telemetry class."); - body.XmlParam("dependencyInjectionClassName", "The name of the generated dependency-injection class."); - body.Constructor( - new(type.Name, TypeDeclarationAccessibility.Public) - { - Parameters = - [ - new("className", PurviewTypeLibrary.System.String.AsTypeReference()), - new("dependencyInjectionClassName", PurviewTypeLibrary.System.String.AsTypeReference()) - { - DefaultValue = "null", - }, - ], - }, - ctor => - { - ctor.Assignment("ClassName", "className"); - ctor.Assignment("DependencyInjectionClassName", "dependencyInjectionClassName"); - } - ); + "Constructs a new instance specifying the generated class name and the dependency-injection class name." + ) + .XmlParam("className", "The name of the generated telemetry class.") + .XmlParam("dependencyInjectionClassName", "The name of the generated dependency-injection class.") + .Constructor( + new(type.Name, TypeDeclarationAccessibility.Public) + { + Parameters = + [ + new("className", TypeLibrary.System.String), + new("dependencyInjectionClassName", TypeLibrary.System.String) + { + DefaultValue = "null", + }, + ], + }, + ctor => + { + ctor.Assignment("ClassName", "className"); + ctor.Assignment("DependencyInjectionClassName", "dependencyInjectionClassName"); + } + ); WritePublicProperty( body, "GenerateDependencyExtension", - PurviewTypeLibrary.System.Boolean.AsTypeReference(), - "true", - "Determines whether a dependency-injection extension method is generated." + TypeLibrary.System.Boolean, + "Determines whether a dependency-injection extension method is generated.", + "true" ); WriteNullableStringProperty(body, "ClassName", "The name of the generated telemetry class."); WriteNullableStringProperty( @@ -534,22 +565,22 @@ static void WriteTelemetryGenerationAttribute(CodeWriter writer, TypeIdentity ty WritePublicProperty( body, "DependencyInjectionClassIsPublic", - PurviewTypeLibrary.System.Boolean.AsTypeReference(), - summary: "Determines whether the dependency-injection class is generated as public." + TypeLibrary.System.Boolean, + "Determines whether the dependency-injection class is generated as public." ); WritePublicProperty( body, "NamingConvention", - namingConvention.AsTypeReference(), - $"{namingConvention.RenderFullName}.OpenTelemetry", - "Determines the naming convention used for generated telemetry names." + namingConvention, + "Determines the naming convention used for generated telemetry names.", + $"{namingConvention.RenderFullName}.OpenTelemetry" ); WritePublicProperty( body, "GenerateTelemetryNamesClass", - PurviewTypeLibrary.System.Boolean.AsTypeReference(), - "true", - "Determines whether a telemetry names class is generated." + TypeLibrary.System.Boolean, + "Determines whether a telemetry names class is generated.", + "true" ); WriteNullableStringProperty( body, @@ -562,13 +593,13 @@ static void WriteTelemetryGenerationAttribute(CodeWriter writer, TypeIdentity ty "The namespace of the generated telemetry names class." ); }, - summary: "Specifies the telemetry generation behaviour for an interface or assembly." + "Specifies the telemetry generation behaviour for an interface or assembly." ); } static void WriteExcludeTargetsAttribute(CodeWriter writer, TypeIdentity type) { - var targets = TypeLibrary.TelemetryShared.Targets; + var targets = TypeLibrary.Purview.Telemetry.Targets; EmitAttribute( writer, @@ -576,20 +607,21 @@ static void WriteExcludeTargetsAttribute(CodeWriter writer, TypeIdentity type) AttributeTargets.Parameter, body => { - body.XmlSummary("Constructs a new instance with the specified targets to exclude."); - body.XmlParam("targets", $"The {XmlSee("ExcludedTargets")}."); - body.Constructor( - new(type.Name, TypeDeclarationAccessibility.Public) - { - Parameters = [new("targets", targets.AsTypeReference())], - }, - ctor => ctor.Assignment("ExcludedTargets", "targets") - ); + body.XmlSummary("Constructs a new instance with the specified targets to exclude.") + .XmlParam("targets", $"The {XmlSee("ExcludedTargets")}.") + .Constructor( + new(type.Name, TypeDeclarationAccessibility.Public) { Parameters = [new("targets", targets)] }, + ctor => ctor.Assignment("ExcludedTargets", "targets") + ); - body.XmlSummary("Gets or sets the targets to exclude for this parameter."); - WritePublicProperty(body, "ExcludedTargets", targets.AsTypeReference()); + WritePublicProperty( + body, + "ExcludedTargets", + targets, + "Gets or sets the targets to exclude for this parameter." + ); }, - summary: "Marks a parameter as excluded from the specified telemetry targets." + "Marks a parameter as excluded from the specified telemetry targets." ); } @@ -605,54 +637,48 @@ static void WriteActivitySourceGenerationAttribute(CodeWriter writer, TypeIdenti AttributeTargets.Assembly, body => { - body.XmlSummary("Constructs a new instance specifying the activity source name and default behaviour."); - body.XmlParam("name", "The name of the activity source."); - body.XmlParam("defaultToTags", "Whether parameters are inferred as tags by default."); - body.XmlParam( - "generateDiagnosticsForMissingActivity", - "Whether diagnostics are generated for missing activity definitions." - ); - body.Constructor( - new(type.Name, TypeDeclarationAccessibility.Public) - { - Parameters = - [ - new("name", PurviewTypeLibrary.System.String.AsTypeReference()), - new("defaultToTags", PurviewTypeLibrary.System.Boolean.AsTypeReference()) - { - DefaultValue = "true", - }, - new( - "generateDiagnosticsForMissingActivity", - PurviewTypeLibrary.System.Boolean.AsTypeReference() - ) - { - DefaultValue = "true", - }, - ], - }, - ctor => - { - ctor.IfBlock( - "string.IsNullOrWhiteSpace(name)", - static body => body.Throw("new System.ArgumentNullException(nameof(name))") - ); - ctor.Assignment("Name", "name"); - ctor.Assignment("DefaultToTags", "defaultToTags"); - ctor.Assignment( - "GenerateDiagnosticsForMissingActivity", - "generateDiagnosticsForMissingActivity" - ); - } - ); + body.XmlSummary("Constructs a new instance specifying the activity source name and default behaviour.") + .XmlParam("name", "The name of the activity source.") + .XmlParam("defaultToTags", "Whether parameters are inferred as tags by default.") + .XmlParam( + "generateDiagnosticsForMissingActivity", + "Whether diagnostics are generated for missing activity definitions." + ) + .Constructor( + new(type.Name, TypeDeclarationAccessibility.Public) + { + Parameters = + [ + new("name", TypeLibrary.System.String), + new("defaultToTags", TypeLibrary.System.Boolean) { DefaultValue = "true" }, + new("generateDiagnosticsForMissingActivity", TypeLibrary.System.Boolean) + { + DefaultValue = "true", + }, + ], + }, + ctor => + { + ctor.IfBlock( + "string.IsNullOrWhiteSpace(name)", + static body => body.Throw("new System.ArgumentNullException(nameof(name))") + ); + ctor.Assignment("Name", "name"); + ctor.Assignment("DefaultToTags", "defaultToTags"); + ctor.Assignment( + "GenerateDiagnosticsForMissingActivity", + "generateDiagnosticsForMissingActivity" + ); + } + ); WriteNullableStringProperty(body, "Name", "The name of the activity source."); WritePublicProperty( body, "DefaultToTags", - PurviewTypeLibrary.System.Boolean.AsTypeReference(), - "true", - "Determines whether parameters are inferred as tags by default." + TypeLibrary.System.Boolean, + "Determines whether parameters are inferred as tags by default.", + "true" ); WriteNullableStringProperty( body, @@ -662,25 +688,25 @@ static void WriteActivitySourceGenerationAttribute(CodeWriter writer, TypeIdenti WritePlainStringProperty( body, "BaggageAndTagSeparator", - "\".\"", - "The separator used between baggage and tag name parts." + "The separator used between baggage and tag name parts.", + "\".\"" ); WritePublicProperty( body, "LowercaseBaggageAndTagKeys", - PurviewTypeLibrary.System.Boolean.AsTypeReference(), - "true", - "Determines whether baggage and tag keys are lowercased." + TypeLibrary.System.Boolean, + "Determines whether baggage and tag keys are lowercased.", + "true" ); WritePublicProperty( body, "GenerateDiagnosticsForMissingActivity", - PurviewTypeLibrary.System.Boolean.AsTypeReference(), - "true", - "Determines whether diagnostics are generated for missing activity definitions." + TypeLibrary.System.Boolean, + "Determines whether diagnostics are generated for missing activity definitions.", + "true" ); }, - summary: "Specifies the default activity source generation behaviour for an assembly." + "Specifies the default activity source generation behaviour for an assembly." ); } @@ -692,43 +718,57 @@ static void WriteActivitySourceAttribute(CodeWriter writer, TypeIdentity type) AttributeTargets.Interface, body => { - body.XmlSummary($"Constructs a new instance of the {XmlSee("ActivitySourceAttribute")}."); - WriteEmptyConstructor(body, type); + WriteEmptyConstructor( + body, + type, + $"Constructs a new instance of the {XmlSee("ActivitySourceAttribute")}." + ); - body.XmlSummary($"Constructs a new instance specifying the {XmlSee("Name")}."); - body.XmlParam("name", $"The {XmlSee("Name")}."); - WriteNameConstructor(body, type); + WriteNameConstructor( + body, + type, + $"Constructs a new instance specifying the {XmlSee("Name")}.", + w => w.XmlParam("name", $"The {XmlSee("Name")}.") + ); WriteNullableStringProperty(body, "Name", "Optional. Gets the name of the activity source."); - body.XmlSummary("Specifies the default when inferring between tag or baggage."); - WritePublicProperty(body, "DefaultToTags", PurviewTypeLibrary.System.Boolean.AsTypeReference(), "true"); + + WritePublicProperty( + body, + "DefaultToTags", + TypeLibrary.System.Boolean, + "Specifies the default when inferring between tag or baggage.", + "true" + ); WriteNullableStringProperty( body, "BaggageAndTagPrefix", "The prefix applied to generated baggage and tag names." ); - body.XmlSummary("Determines if the name is used as a prefix."); + WritePublicProperty( body, "IncludeActivitySourcePrefix", - PurviewTypeLibrary.System.Boolean.AsTypeReference(), + TypeLibrary.System.Boolean, + "Determines if the name is used as a prefix.", "true" ); - body.XmlSummary("Determines if tag/ baggage names are lowercased."); + WritePublicProperty( body, "LowercaseBaggageAndTagKeys", - PurviewTypeLibrary.System.Boolean.AsTypeReference(), + TypeLibrary.System.Boolean, + "Determines if tag/ baggage names are lowercased.", "true" ); }, - summary: "Marks an interface as an activity source." + "Marks an interface as an activity source." ); } static void WriteActivityAttribute(CodeWriter writer, TypeIdentity type) { - var activityKind = TypeLibrary.Activities.SystemDiagnostics.ActivityKind; + var activityKind = TypeLibrary.System.Diagnostics.ActivityKind; EmitAttribute( writer, @@ -736,77 +776,68 @@ static void WriteActivityAttribute(CodeWriter writer, TypeIdentity type) AttributeTargets.Method, body => { - body.XmlSummary($"Constructs a new instance of the {XmlSee("ActivityAttribute")}."); - WriteEmptyConstructor(body, type); - - body.XmlSummary($"Constructs a new instance specifying the {XmlSee("Name")}."); - body.XmlParam("name", $"The {XmlSee("Name")}."); - WriteNameConstructor(body, type); + WriteEmptyConstructor(body, type, $"Constructs a new instance of the {XmlSee("ActivityAttribute")}."); - body.XmlSummary($"Constructs a new instance specifying the {XmlSee("Kind")}."); - body.XmlParam("kind", $"The {XmlSee("Kind")}."); - body.Constructor( - new(type.Name, TypeDeclarationAccessibility.Public) - { - Parameters = [new("kind", activityKind.AsTypeReference())], - }, - ctor => ctor.Assignment("Kind", "kind") + WriteNameConstructor( + body, + type, + $"Constructs a new instance specifying the {XmlSee("Name")}.", + w => w.XmlParam("name", $"The {XmlSee("Name")}.") ); + body.XmlSummary($"Constructs a new instance specifying the {XmlSee("Kind")}.") + .XmlParam("kind", $"The {XmlSee("Kind")}.") + .Constructor( + new(type.Name, TypeDeclarationAccessibility.Public) + { + Parameters = [new("kind", activityKind)], + }, + ctor => ctor.Assignment("Kind", "kind") + ); + body.XmlSummary( - $"Constructs a new instance specifying the {XmlSee("Name")}, {XmlSee("Kind")} and whether the activity is created without starting it." - ); - body.XmlParam("name", $"The {XmlSee("Name")}."); - body.XmlParam("kind", $"The {XmlSee("Kind")}."); - body.XmlParam( - "createOnly", - $"Whether the activity is created without starting it ({XmlSee("CreateOnly")})." - ); - body.Constructor( - new(type.Name, TypeDeclarationAccessibility.Public) - { - Parameters = - [ - new("name", PurviewTypeLibrary.System.String.AsTypeReference()), - new("kind", activityKind.AsTypeReference()) - { - DefaultValue = $"{activityKind.RenderFullName}.Internal", - }, - new("createOnly", PurviewTypeLibrary.System.Boolean.AsTypeReference()) - { - DefaultValue = "false", - }, - ], - }, - ctor => - { - ctor.Assignment("Name", "name"); - ctor.Assignment("Kind", "kind"); - ctor.Assignment("CreateOnly", "createOnly"); - } - ); + $"Constructs a new instance specifying the {XmlSee("Name")}, {XmlSee("Kind")} and whether the activity is created without starting it." + ) + .XmlParam("name", $"The {XmlSee("Name")}.") + .XmlParam("kind", $"The {XmlSee("Kind")}.") + .XmlParam( + "createOnly", + $"Whether the activity is created without starting it ({XmlSee("CreateOnly")})." + ) + .Constructor( + new(type.Name, TypeDeclarationAccessibility.Public) + { + Parameters = + [ + new("name", TypeLibrary.System.String), + new("kind", activityKind) { DefaultValue = $"{activityKind.RenderFullName}.Internal" }, + new("createOnly", TypeLibrary.System.Boolean) { DefaultValue = "false" }, + ], + }, + ctor => + { + ctor.Assignment("Name", "name"); + ctor.Assignment("Kind", "kind"); + ctor.Assignment("CreateOnly", "createOnly"); + } + ); WriteNullableStringProperty(body, "Name", "Optional. Gets the name of the activity."); - WritePublicProperty( - body, - "Kind", - activityKind.AsTypeReference(), - summary: "Gets the kind of the activity." - ); + WritePublicProperty(body, "Kind", activityKind, "Gets the kind of the activity."); WritePublicProperty( body, "CreateOnly", - PurviewTypeLibrary.System.Boolean.AsTypeReference(), - summary: "Determines whether the activity is created without starting it." + TypeLibrary.System.Boolean, + "Determines whether the activity is created without starting it." ); }, - summary: "Marks a method as an activity." + "Marks a method as an activity." ); } static void WriteEventAttribute(CodeWriter writer, TypeIdentity type) { - var statusCode = TypeLibrary.Activities.SystemDiagnostics.ActivityStatusCode; + var statusCode = TypeLibrary.System.Diagnostics.ActivityStatusCode; EmitAttribute( writer, @@ -814,91 +845,75 @@ static void WriteEventAttribute(CodeWriter writer, TypeIdentity type) AttributeTargets.Method, body => { - body.XmlSummary($"Constructs a new instance specifying the {XmlSee("StatusCode")}."); - body.XmlParam("statusCode", $"The {XmlSee("StatusCode")}."); - body.Constructor( - new(type.Name, TypeDeclarationAccessibility.Public) - { - Parameters = - [ - new("statusCode", statusCode.AsTypeReference()) - { - DefaultValue = $"{statusCode.RenderFullName}.Unset", - }, - ], - }, - ctor => ctor.Assignment("StatusCode", "statusCode") - ); + body.XmlSummary($"Constructs a new instance specifying the {XmlSee("StatusCode")}.") + .XmlParam("statusCode", $"The {XmlSee("StatusCode")}.") + .Constructor( + new(type.Name, TypeDeclarationAccessibility.Public) + { + Parameters = + [ + new("statusCode", statusCode) { DefaultValue = $"{statusCode.RenderFullName}.Unset" }, + ], + }, + ctor => ctor.Assignment("StatusCode", "statusCode") + ); + body.XmlSummary( - $"Constructs a new instance specifying the {XmlSee("Name")}, exception handling behaviour and {XmlSee("StatusCode")}." - ); - body.XmlParam("name", $"The {XmlSee("Name")}."); - body.XmlParam( - "useRecordExceptionRules", - $"Whether to use record exception rules ({XmlSee("UseRecordExceptionRules")})." - ); - body.XmlParam( - "recordExceptionAsEscaped", - $"Whether a recorded exception is escaped ({XmlSee("RecordExceptionAsEscaped")})." - ); - body.XmlParam("statusCode", $"The {XmlSee("StatusCode")}."); - body.Constructor( - new(type.Name, TypeDeclarationAccessibility.Public) - { - Parameters = - [ - new("name", PurviewTypeLibrary.System.String.AsTypeReference()), - new("useRecordExceptionRules", PurviewTypeLibrary.System.Boolean.AsTypeReference()) - { - DefaultValue = "true", - }, - new("recordExceptionAsEscaped", PurviewTypeLibrary.System.Boolean.AsTypeReference()) - { - DefaultValue = "true", - }, - new("statusCode", statusCode.AsTypeReference()) - { - DefaultValue = $"{statusCode.RenderFullName}.Unset", - }, - ], - }, - ctor => - { - ctor.Assignment("Name", "name"); - ctor.Assignment("UseRecordExceptionRules", "useRecordExceptionRules"); - ctor.Assignment("RecordExceptionAsEscaped", "recordExceptionAsEscaped"); - ctor.Assignment("StatusCode", "statusCode"); - } - ); + $"Constructs a new instance specifying the {XmlSee("Name")}, exception handling behaviour and {XmlSee("StatusCode")}." + ) + .XmlParam("name", $"The {XmlSee("Name")}.") + .XmlParam( + "useRecordExceptionRules", + $"Whether to use record exception rules ({XmlSee("UseRecordExceptionRules")})." + ) + .XmlParam( + "recordExceptionAsEscaped", + $"Whether a recorded exception is escaped ({XmlSee("RecordExceptionAsEscaped")})." + ) + .XmlParam("statusCode", $"The {XmlSee("StatusCode")}.") + .Constructor( + new(type.Name, TypeDeclarationAccessibility.Public) + { + Parameters = + [ + new("name", TypeLibrary.System.String), + new("useRecordExceptionRules", TypeLibrary.System.Boolean) { DefaultValue = "true" }, + new("recordExceptionAsEscaped", TypeLibrary.System.Boolean) { DefaultValue = "true" }, + new("statusCode", statusCode) { DefaultValue = $"{statusCode.RenderFullName}.Unset" }, + ], + }, + ctor => + { + ctor.Assignment("Name", "name"); + ctor.Assignment("UseRecordExceptionRules", "useRecordExceptionRules"); + ctor.Assignment("RecordExceptionAsEscaped", "recordExceptionAsEscaped"); + ctor.Assignment("StatusCode", "statusCode"); + } + ); WriteNullableStringProperty(body, "Name", "Optional. Gets the name of the event."); WritePublicProperty( body, "UseRecordExceptionRules", - PurviewTypeLibrary.System.Boolean.AsTypeReference(), - "true", - "Determines whether the default exception-handling rules are used." + TypeLibrary.System.Boolean, + "Determines whether the default exception-handling rules are used.", + "true" ); WritePublicProperty( body, "RecordExceptionAsEscaped", - PurviewTypeLibrary.System.Boolean.AsTypeReference(), - "true", - "Determines whether a recorded exception is escaped." - ); - WritePublicProperty( - body, - "StatusCode", - statusCode.AsTypeReference(), - summary: "Gets the status code of the event." + TypeLibrary.System.Boolean, + "Determines whether a recorded exception is escaped.", + "true" ); + WritePublicProperty(body, "StatusCode", statusCode, "Gets the status code of the event."); WriteNullableStringProperty( body, "StatusDescription", "Optional. Gets the status description of the event." ); }, - summary: "Marks a method as an activity event." + "Marks a method as an activity event." ); } @@ -908,7 +923,7 @@ static void WriteEventAttribute(CodeWriter writer, TypeIdentity type) static void WriteLoggerGenerationAttribute(CodeWriter writer, TypeIdentity type) { - var logLevel = TypeLibrary.Logging.MicrosoftExtensions.LogLevel; + var logLevel = TypeLibrary.Microsoft.Extensions.Logging.LogLevel; EmitAttribute( writer, @@ -917,34 +932,34 @@ static void WriteLoggerGenerationAttribute(CodeWriter writer, TypeIdentity type) body => { WriteEmptyConstructor(body, type, $"Constructs a new instance of the {XmlSee(type.Name)}."); - body.XmlSummary($"Constructs a new instance specifying the default {XmlSee("DefaultLevel")}."); - body.XmlParam("defaultLevel", $"The default {XmlSee("DefaultLevel")}."); - body.Constructor( - new(type.Name, TypeDeclarationAccessibility.Public) - { - Parameters = [new("defaultLevel", logLevel.AsTypeReference())], - }, - ctor => ctor.Assignment("DefaultLevel", "defaultLevel") - ); + body.XmlSummary($"Constructs a new instance specifying the default {XmlSee("DefaultLevel")}.") + .XmlParam("defaultLevel", $"The default {XmlSee("DefaultLevel")}.") + .Constructor( + new(type.Name, TypeDeclarationAccessibility.Public) + { + Parameters = [new("defaultLevel", logLevel)], + }, + ctor => ctor.Assignment("DefaultLevel", "defaultLevel") + ); WritePublicProperty( body, "DefaultLevel", - logLevel.AsTypeReference(), - $"{logLevel.RenderFullName}.Information", - "Gets or sets the default log level used by generated log methods." + logLevel, + "Gets or sets the default log level used by generated log methods.", + $"{logLevel.RenderFullName}.Information" ); WritePublicProperty( body, "GenerationMode", - TypeLibrary.Logging.LoggerGenerationMode.AsTypeReference(), - summary: "Gets or sets the log generation mode used for generated log methods." + TypeLibrary.Purview.Telemetry.LoggerGenerationMode, + "Gets or sets the log generation mode used for generated log methods." ); WritePublicProperty( body, "DefaultPrefixType", - TypeLibrary.Logging.LogPrefixType.AsTypeReference(), - summary: "Gets or sets the default log prefix type used by generated log methods." + TypeLibrary.Purview.Telemetry.LogPrefixType, + "Gets or sets the default log prefix type used by generated log methods." ); }, wrapInExcludeLoggingGuard: true, @@ -954,8 +969,8 @@ static void WriteLoggerGenerationAttribute(CodeWriter writer, TypeIdentity type) static void WriteLoggerAttribute(CodeWriter writer, TypeIdentity type) { - var logLevel = TypeLibrary.Logging.MicrosoftExtensions.LogLevel; - var logPrefixType = TypeLibrary.Logging.LogPrefixType; + var logLevel = TypeLibrary.Microsoft.Extensions.Logging.LogLevel; + var logPrefixType = TypeLibrary.Purview.Telemetry.LogPrefixType; EmitAttribute( writer, @@ -965,39 +980,36 @@ static void WriteLoggerAttribute(CodeWriter writer, TypeIdentity type) { WriteEmptyConstructor(body, type, $"Constructs a new instance of the {XmlSee(type.Name)}."); body.XmlSummary( - $"Constructs a new instance specifying the default {XmlSee("DefaultLevel")} and an optional custom prefix." - ); - body.XmlParam("defaultLevel", $"The default {XmlSee("DefaultLevel")}."); - body.XmlParam("customPrefix", $"The custom log prefix ({XmlSee("CustomPrefix")})."); - body.Constructor( - new(type.Name, TypeDeclarationAccessibility.Public) - { - Parameters = - [ - new("defaultLevel", logLevel.AsTypeReference()), - new("customPrefix", PurviewTypeLibrary.System.String.AsTypeReference()) - { - DefaultValue = "null", - }, - ], - }, - ctor => - { - ctor.Assignment("DefaultLevel", "defaultLevel"); - ctor.Assignment("CustomPrefix", "customPrefix"); - ctor.IfBlock( - "!string.IsNullOrWhiteSpace(CustomPrefix)", - block => block.Assignment("PrefixType", $"{logPrefixType.RenderFullName}.Custom") - ); - } - ); + $"Constructs a new instance specifying the default {XmlSee("DefaultLevel")} and an optional custom prefix." + ) + .XmlParam("defaultLevel", $"The default {XmlSee("DefaultLevel")}.") + .XmlParam("customPrefix", $"The custom log prefix ({XmlSee("CustomPrefix")}).") + .Constructor( + new(type.Name, TypeDeclarationAccessibility.Public) + { + Parameters = + [ + new("defaultLevel", logLevel), + new("customPrefix", TypeLibrary.System.String) { DefaultValue = "null" }, + ], + }, + ctor => + { + ctor.Assignment("DefaultLevel", "defaultLevel"); + ctor.Assignment("CustomPrefix", "customPrefix"); + ctor.IfBlock( + "!string.IsNullOrWhiteSpace(CustomPrefix)", + block => block.Assignment("PrefixType", $"{logPrefixType.RenderFullName}.Custom") + ); + } + ); WritePublicProperty( body, "DefaultLevel", - logLevel.AsTypeReference(), - $"{logLevel.RenderFullName}.Information", - "Gets or sets the default log level used by generated log methods." + logLevel, + "Gets or sets the default log level used by generated log methods.", + $"{logLevel.RenderFullName}.Information" ); WriteNullableStringProperty( body, @@ -1007,14 +1019,14 @@ static void WriteLoggerAttribute(CodeWriter writer, TypeIdentity type) WritePublicProperty( body, "PrefixType", - logPrefixType.AsTypeReference(), - summary: "Gets or sets the log prefix type used by generated log methods." + logPrefixType, + "Gets or sets the log prefix type used by generated log methods." ); WritePublicProperty( body, "GenerationMode", - TypeLibrary.Logging.LoggerGenerationMode.AsTypeReference(), - summary: "Gets or sets the log generation mode used for generated log methods." + TypeLibrary.Purview.Telemetry.LoggerGenerationMode, + "Gets or sets the log generation mode used for generated log methods." ); }, wrapInExcludeLoggingGuard: true, @@ -1024,7 +1036,7 @@ static void WriteLoggerAttribute(CodeWriter writer, TypeIdentity type) static void WriteLogAttribute(CodeWriter writer, TypeIdentity type) { - var logLevel = TypeLibrary.Logging.MicrosoftExtensions.LogLevel; + var logLevel = TypeLibrary.Microsoft.Extensions.Logging.LogLevel; EmitAttribute( writer, @@ -1040,67 +1052,61 @@ static void WriteLogAttribute(CodeWriter writer, TypeIdentity type) ); WriteEventIdConstructor(body, type, $"Constructs a new instance specifying the {XmlSee("EventId")}."); body.XmlSummary( - $"Constructs a new instance specifying the {XmlSee("Level")}, optional {XmlSee("MessageTemplate")} and {XmlSee("Name")}." - ); - body.XmlParam("level", $"The {XmlSee("Level")}."); - body.XmlParam("messageTemplate", $"The {XmlSee("MessageTemplate")}."); - body.XmlParam("name", $"The {XmlSee("Name")}."); - body.Constructor( - new(type.Name, TypeDeclarationAccessibility.Public) - { - Parameters = - [ - new("level", logLevel.AsTypeReference()), - new("messageTemplate", PurviewTypeLibrary.System.String.AsTypeReference()) - { - DefaultValue = "null", - }, - new("name", PurviewTypeLibrary.System.String.AsTypeReference()) { DefaultValue = "null" }, - ], - }, - ctor => - { - ctor.Assignment("Level", "level"); - ctor.Assignment("MessageTemplate", "messageTemplate"); - ctor.Assignment("Name", "name"); - } - ); + $"Constructs a new instance specifying the {XmlSee("Level")}, optional {XmlSee("MessageTemplate")} and {XmlSee("Name")}." + ) + .XmlParam("level", $"The {XmlSee("Level")}.") + .XmlParam("messageTemplate", $"The {XmlSee("MessageTemplate")}.") + .XmlParam("name", $"The {XmlSee("Name")}.") + .Constructor( + new(type.Name, TypeDeclarationAccessibility.Public) + { + Parameters = + [ + new("level", logLevel), + new("messageTemplate", TypeLibrary.System.String) { DefaultValue = "null" }, + new("name", TypeLibrary.System.String) { DefaultValue = "null" }, + ], + }, + ctor => + { + ctor.Assignment("Level", "level"); + ctor.Assignment("MessageTemplate", "messageTemplate"); + ctor.Assignment("Name", "name"); + } + ); body.XmlSummary( - $"Constructs a new instance specifying the {XmlSee("EventId")}, {XmlSee("Level")}, optional {XmlSee("MessageTemplate")} and {XmlSee("Name")}." - ); - body.XmlParam("eventId", $"The {XmlSee("EventId")}."); - body.XmlParam("level", $"The {XmlSee("Level")}."); - body.XmlParam("messageTemplate", $"The {XmlSee("MessageTemplate")}."); - body.XmlParam("name", $"The {XmlSee("Name")}."); - body.Constructor( - new(type.Name, TypeDeclarationAccessibility.Public) - { - Parameters = - [ - new("eventId", PurviewTypeLibrary.System.Int32.AsTypeReference()), - new("level", logLevel.AsTypeReference()), - new("messageTemplate", PurviewTypeLibrary.System.String.AsTypeReference()) - { - DefaultValue = "null", - }, - new("name", PurviewTypeLibrary.System.String.AsTypeReference()) { DefaultValue = "null" }, - ], - }, - ctor => - { - ctor.Assignment("Level", "level"); - ctor.Assignment("MessageTemplate", "messageTemplate"); - ctor.Assignment("EventId", "eventId"); - ctor.Assignment("Name", "name"); - } - ); + $"Constructs a new instance specifying the {XmlSee("EventId")}, {XmlSee("Level")}, optional {XmlSee("MessageTemplate")} and {XmlSee("Name")}." + ) + .XmlParam("eventId", $"The {XmlSee("EventId")}.") + .XmlParam("level", $"The {XmlSee("Level")}.") + .XmlParam("messageTemplate", $"The {XmlSee("MessageTemplate")}.") + .XmlParam("name", $"The {XmlSee("Name")}.") + .Constructor( + new(type.Name, TypeDeclarationAccessibility.Public) + { + Parameters = + [ + new("eventId", TypeLibrary.System.Int32), + new("level", logLevel), + new("messageTemplate", TypeLibrary.System.String) { DefaultValue = "null" }, + new("name", TypeLibrary.System.String) { DefaultValue = "null" }, + ], + }, + ctor => + { + ctor.Assignment("Level", "level"); + ctor.Assignment("MessageTemplate", "messageTemplate"); + ctor.Assignment("EventId", "eventId"); + ctor.Assignment("Name", "name"); + } + ); WritePublicProperty( body, "Level", - logLevel.AsTypeReference(), - $"{logLevel.RenderFullName}.Information", - "Gets or sets the log level of the log entry." + logLevel, + "Gets or sets the log level of the log entry.", + $"{logLevel.RenderFullName}.Information" ); WriteNullableStringProperty( body, @@ -1110,15 +1116,15 @@ static void WriteLogAttribute(CodeWriter writer, TypeIdentity type) WritePublicProperty( body, "EventId", - PurviewTypeLibrary.System.Int32.MakeNullable(writer), - summary: "Gets or sets the event identifier of the log entry." + TypeLibrary.System.Int32.MakeNullable(writer), + "Gets or sets the event identifier of the log entry." ); WriteNullableStringProperty(body, "Name", "Gets or sets the name of the log entry."); WritePublicProperty( body, "GenerationMode", - TypeLibrary.Logging.LoggerGenerationMode.AsTypeReference(), - summary: "Gets or sets the log generation mode used for the log entry." + TypeLibrary.Purview.Telemetry.LoggerGenerationMode, + "Gets or sets the log generation mode used for the log entry." ); }, wrapInExcludeLoggingGuard: true, @@ -1126,8 +1132,13 @@ static void WriteLogAttribute(CodeWriter writer, TypeIdentity type) ); } - static void WriteSpecificLogAttribute(CodeWriter writer, TypeIdentity type, string? summary = null) + static void WriteSpecificLogAttribute(CodeWriter writer, TypeIdentity type, string summary) { +#if DEBUG + if (string.IsNullOrWhiteSpace(summary)) + throw new ArgumentException("Summary must be provided for public properties.", nameof(summary)); +#endif + EmitAttribute( writer, type, @@ -1141,54 +1152,49 @@ static void WriteSpecificLogAttribute(CodeWriter writer, TypeIdentity type, stri ); WriteEventIdConstructor(body, type, $"Constructs a new instance specifying the {XmlSee("EventId")}."); body.XmlSummary( - $"Constructs a new instance specifying an optional {XmlSee("MessageTemplate")} and {XmlSee("Name")}." - ); - body.XmlParam("messageTemplate", $"The {XmlSee("MessageTemplate")}."); - body.XmlParam("name", $"The {XmlSee("Name")}."); - body.Constructor( - new(type.Name, TypeDeclarationAccessibility.Public) - { - Parameters = - [ - new("messageTemplate", PurviewTypeLibrary.System.String.AsTypeReference()) - { - DefaultValue = "null", - }, - new("name", PurviewTypeLibrary.System.String.AsTypeReference()) { DefaultValue = "null" }, - ], - }, - ctor => - { - ctor.Assignment("MessageTemplate", "messageTemplate"); - ctor.Assignment("Name", "name"); - } - ); + $"Constructs a new instance specifying an optional {XmlSee("MessageTemplate")} and {XmlSee("Name")}." + ) + .XmlParam("messageTemplate", $"The {XmlSee("MessageTemplate")}.") + .XmlParam("name", $"The {XmlSee("Name")}.") + .Constructor( + new(type.Name, TypeDeclarationAccessibility.Public) + { + Parameters = + [ + new("messageTemplate", TypeLibrary.System.String) { DefaultValue = "null" }, + new("name", TypeLibrary.System.String) { DefaultValue = "null" }, + ], + }, + ctor => + { + ctor.Assignment("MessageTemplate", "messageTemplate"); + ctor.Assignment("Name", "name"); + } + ); + body.XmlSummary( - $"Constructs a new instance specifying the {XmlSee("EventId")}, optional {XmlSee("MessageTemplate")} and {XmlSee("Name")}." - ); - body.XmlParam("eventId", $"The {XmlSee("EventId")}."); - body.XmlParam("messageTemplate", $"The {XmlSee("MessageTemplate")}."); - body.XmlParam("name", $"The {XmlSee("Name")}."); - body.Constructor( - new(type.Name, TypeDeclarationAccessibility.Public) - { - Parameters = - [ - new("eventId", PurviewTypeLibrary.System.Int32.AsTypeReference()), - new("messageTemplate", PurviewTypeLibrary.System.String.AsTypeReference()) - { - DefaultValue = "null", - }, - new("name", PurviewTypeLibrary.System.String.AsTypeReference()) { DefaultValue = "null" }, - ], - }, - ctor => - { - ctor.Assignment("MessageTemplate", "messageTemplate"); - ctor.Assignment("EventId", "eventId"); - ctor.Assignment("Name", "name"); - } - ); + $"Constructs a new instance specifying the {XmlSee("EventId")}, optional {XmlSee("MessageTemplate")} and {XmlSee("Name")}." + ) + .XmlParam("eventId", $"The {XmlSee("EventId")}.") + .XmlParam("messageTemplate", $"The {XmlSee("MessageTemplate")}.") + .XmlParam("name", $"The {XmlSee("Name")}.") + .Constructor( + new(type.Name, TypeDeclarationAccessibility.Public) + { + Parameters = + [ + new("eventId", TypeLibrary.System.Int32), + new("messageTemplate", TypeLibrary.System.String) { DefaultValue = "null" }, + new("name", TypeLibrary.System.String) { DefaultValue = "null" }, + ], + }, + ctor => + { + ctor.Assignment("MessageTemplate", "messageTemplate"); + ctor.Assignment("EventId", "eventId"); + ctor.Assignment("Name", "name"); + } + ); WriteNullableStringProperty( body, @@ -1198,15 +1204,15 @@ static void WriteSpecificLogAttribute(CodeWriter writer, TypeIdentity type, stri WritePublicProperty( body, "EventId", - PurviewTypeLibrary.System.Int32.MakeNullable(writer), - summary: "Gets or sets the event identifier of the log entry." + TypeLibrary.System.Int32.MakeNullable(writer), + "Gets or sets the event identifier of the log entry." ); WriteNullableStringProperty(body, "Name", "Gets or sets the name of the log entry."); WritePublicProperty( body, "GenerationMode", - TypeLibrary.Logging.LoggerGenerationMode.AsTypeReference(), - summary: "Gets or sets the log generation mode used for the log entry." + TypeLibrary.Purview.Telemetry.LoggerGenerationMode, + "Gets or sets the log generation mode used for the log entry." ); }, wrapInExcludeLoggingGuard: true, @@ -1223,28 +1229,26 @@ static void WriteExpandEnumerableAttribute(CodeWriter writer, TypeIdentity type) body => { body.XmlSummary( - $"Constructs a new instance specifying the maximum number of values to expand ({XmlSee("MaximumValueCount")})." - ); - body.XmlParam( - "maximumValueCount", - $"The maximum number of values to include ({XmlSee("MaximumValueCount")})." - ); - body.Constructor( - new(type.Name, TypeDeclarationAccessibility.Public) - { - Parameters = - [ - new("maximumValueCount", PurviewTypeLibrary.System.Int32.AsTypeReference()) - { - DefaultValue = "5", - }, - ], - }, - ctor => ctor.Assignment("MaximumValueCount", "maximumValueCount") - ); + $"Constructs a new instance specifying the maximum number of values to expand ({XmlSee("MaximumValueCount")})." + ) + .XmlParam( + "maximumValueCount", + $"The maximum number of values to include ({XmlSee("MaximumValueCount")})." + ) + .Constructor( + new(type.Name, TypeDeclarationAccessibility.Public) + { + Parameters = [new("maximumValueCount", TypeLibrary.System.Int32) { DefaultValue = "5" }], + }, + ctor => ctor.Assignment("MaximumValueCount", "maximumValueCount") + ); - body.XmlSummary("Gets or sets the maximum number of values to include when expanding an enumerable."); - WritePublicProperty(body, "MaximumValueCount", PurviewTypeLibrary.System.Int32.AsTypeReference()); + WritePublicProperty( + body, + "MaximumValueCount", + TypeLibrary.System.Int32, + "Gets or sets the maximum number of values to include when expanding an enumerable." + ); }, wrapInExcludeLoggingGuard: true, summary: "Marks an enumerable parameter to be expanded into multiple log entries." @@ -1257,7 +1261,7 @@ static void WriteExpandEnumerableAttribute(CodeWriter writer, TypeIdentity type) static void WriteMeterGenerationAttribute(CodeWriter writer, TypeIdentity type) { - var nameGenerationType = TypeLibrary.Metrics.MeterNameGenerationType; + var nameGenerationType = TypeLibrary.Purview.Telemetry.MeterNameGenerationType; EmitAttribute( writer, @@ -1267,60 +1271,48 @@ static void WriteMeterGenerationAttribute(CodeWriter writer, TypeIdentity type) { WriteEmptyConstructor(body, type, $"Constructs a new instance of the {XmlSee(type.Name)}."); body.XmlSummary( - "Constructs a new instance specifying the meter name, name-generation type, instrument prefix and name casing defaults." - ); - body.XmlParam("meterName", $"The {XmlSee("MeterName")}."); - body.XmlParam("nameGenerationType", $"The {XmlSee("MeterNameGenerationType")}."); - body.XmlParam("instrumentPrefix", $"The {XmlSee("InstrumentPrefix")}."); - body.XmlParam( - "lowercaseInstrumentName", - $"Whether instrument names are lowercased ({XmlSee("LowercaseInstrumentName")})." - ); - body.XmlParam("lowercaseTagKeys", $"Whether tag keys are lowercased ({XmlSee("LowercaseTagKeys")})."); - body.Constructor( - new(type.Name, TypeDeclarationAccessibility.Public) - { - Parameters = - [ - new("meterName", PurviewTypeLibrary.System.String.AsTypeReference()) - { - DefaultValue = "null", - }, - new("nameGenerationType", nameGenerationType.AsTypeReference()) - { - DefaultValue = $"{nameGenerationType.RenderFullName}.DotNet", - }, - new("instrumentPrefix", PurviewTypeLibrary.System.String.AsTypeReference()) - { - DefaultValue = "null", - }, - new("lowercaseInstrumentName", PurviewTypeLibrary.System.Boolean.AsTypeReference()) - { - DefaultValue = "true", - }, - new("lowercaseTagKeys", PurviewTypeLibrary.System.Boolean.AsTypeReference()) - { - DefaultValue = "true", - }, - ], - }, - ctor => - { - ctor.Assignment("MeterName", "meterName"); - ctor.Assignment("MeterNameGenerationType", "nameGenerationType"); - ctor.Assignment("InstrumentPrefix", "instrumentPrefix"); - ctor.Assignment("LowercaseInstrumentName", "lowercaseInstrumentName"); - ctor.Assignment("LowercaseTagKeys", "lowercaseTagKeys"); - } - ); + "Constructs a new instance specifying the meter name, name-generation type, instrument prefix and name casing defaults." + ) + .XmlParam("meterName", $"The {XmlSee("MeterName")}.") + .XmlParam("nameGenerationType", $"The {XmlSee("MeterNameGenerationType")}.") + .XmlParam("instrumentPrefix", $"The {XmlSee("InstrumentPrefix")}.") + .XmlParam( + "lowercaseInstrumentName", + $"Whether instrument names are lowercased ({XmlSee("LowercaseInstrumentName")})." + ) + .XmlParam("lowercaseTagKeys", $"Whether tag keys are lowercased ({XmlSee("LowercaseTagKeys")}).") + .Constructor( + new(type.Name, TypeDeclarationAccessibility.Public) + { + Parameters = + [ + new("meterName", TypeLibrary.System.String) { DefaultValue = "null" }, + new("nameGenerationType", nameGenerationType) + { + DefaultValue = $"{nameGenerationType.RenderFullName}.DotNet", + }, + new("instrumentPrefix", TypeLibrary.System.String) { DefaultValue = "null" }, + new("lowercaseInstrumentName", TypeLibrary.System.Boolean) { DefaultValue = "true" }, + new("lowercaseTagKeys", TypeLibrary.System.Boolean) { DefaultValue = "true" }, + ], + }, + ctor => + { + ctor.Assignment("MeterName", "meterName"); + ctor.Assignment("MeterNameGenerationType", "nameGenerationType"); + ctor.Assignment("InstrumentPrefix", "instrumentPrefix"); + ctor.Assignment("LowercaseInstrumentName", "lowercaseInstrumentName"); + ctor.Assignment("LowercaseTagKeys", "lowercaseTagKeys"); + } + ); WriteNullableStringProperty(body, "MeterName", "Gets or sets the name of the meter."); WritePublicProperty( body, "MeterNameGenerationType", - nameGenerationType.AsTypeReference(), - $"{nameGenerationType.RenderFullName}.DotNet", - "Gets or sets how meter names are generated when not explicitly specified." + nameGenerationType, + "Gets or sets how meter names are generated when not explicitly specified.", + $"{nameGenerationType.RenderFullName}.DotNet" ); WriteNullableStringProperty( body, @@ -1330,25 +1322,25 @@ static void WriteMeterGenerationAttribute(CodeWriter writer, TypeIdentity type) WritePlainStringProperty( body, "InstrumentSeparator", - "\".\"", - "Gets or sets the separator used between instrument name parts." + "Gets or sets the separator used between instrument name parts.", + "\".\"" ); WritePublicProperty( body, "LowercaseInstrumentName", - PurviewTypeLibrary.System.Boolean.AsTypeReference(), - "true", - "Determines whether instrument names are lowercased." + TypeLibrary.System.Boolean, + "Determines whether instrument names are lowercased.", + "true" ); WritePublicProperty( body, "LowercaseTagKeys", - PurviewTypeLibrary.System.Boolean.AsTypeReference(), - "true", - "Determines whether tag keys are lowercased." + TypeLibrary.System.Boolean, + "Determines whether tag keys are lowercased.", + "true" ); }, - summary: "Specifies the default meter generation behaviour for an assembly." + "Specifies the default meter generation behaviour for an assembly." ); } @@ -1372,31 +1364,36 @@ static void WriteMeterAttribute(CodeWriter writer, TypeIdentity type) WritePublicProperty( body, "IncludeAssemblyInstrumentPrefix", - PurviewTypeLibrary.System.Boolean.AsTypeReference(), - "true", - "Determines whether the assembly-level instrument prefix is included." + TypeLibrary.System.Boolean, + "Determines whether the assembly-level instrument prefix is included.", + "true" ); WritePublicProperty( body, "LowercaseInstrumentName", - PurviewTypeLibrary.System.Boolean.AsTypeReference(), - "true", - "Determines whether instrument names are lowercased." + TypeLibrary.System.Boolean, + "Determines whether instrument names are lowercased.", + "true" ); WritePublicProperty( body, "LowercaseTagKeys", - PurviewTypeLibrary.System.Boolean.AsTypeReference(), - "true", - "Determines whether tag keys are lowercased." + TypeLibrary.System.Boolean, + "Determines whether tag keys are lowercased.", + "true" ); }, - summary: "Marks an interface as a meter." + "Marks an interface as a meter." ); } - static void WriteAutoCounterAttribute(CodeWriter writer, TypeIdentity type, string? summary = null) + static void WriteAutoCounterAttribute(CodeWriter writer, TypeIdentity type, string summary) { +#if DEUBG + if (string.IsNullOrWhiteSpace(summary)) + throw new ArgumentException("Summary cannot be null or whitespace.", nameof(summary)); +#endif + EmitAttribute( writer, type, @@ -1407,19 +1404,24 @@ static void WriteAutoCounterAttribute(CodeWriter writer, TypeIdentity type, stri WriteNameUnitDescriptionConstructor( body, type, - summary: $"Constructs a new instance specifying the {XmlSee("Name")}, {XmlSee("Unit")} and {XmlSee("Description")}." + $"Constructs a new instance specifying the {XmlSee("Name")}, {XmlSee("Unit")} and {XmlSee("Description")}." ); WriteNullableStringProperty(body, "Name", "Gets or sets the name of the instrument."); WriteNullableStringProperty(body, "Unit", "Gets or sets the measurement unit of the instrument."); WriteNullableStringProperty(body, "Description", "Gets or sets the description of the instrument."); }, - summary: summary + summary ); } - static void WriteCounterLikeAttribute(CodeWriter writer, TypeIdentity type, string? summary = null) + static void WriteCounterLikeAttribute(CodeWriter writer, TypeIdentity type, string summary) { +#if DEUBG + if (string.IsNullOrWhiteSpace(summary)) + throw new ArgumentException("Summary cannot be null or whitespace.", nameof(summary)); +#endif + EmitAttribute( writer, type, @@ -1428,16 +1430,16 @@ static void WriteCounterLikeAttribute(CodeWriter writer, TypeIdentity type, stri { WriteEmptyConstructor(body, type, $"Constructs a new instance of the {XmlSee(type.Name)}."); body.XmlSummary( - $"Constructs a new instance specifying whether the counter auto-increments ({XmlSee("AutoIncrement")})." - ); - body.XmlParam("autoIncrement", $"Whether the counter auto-increments ({XmlSee("AutoIncrement")})."); - body.Constructor( - new(type.Name, TypeDeclarationAccessibility.Public) - { - Parameters = [new("autoIncrement", PurviewTypeLibrary.System.Boolean.AsTypeReference())], - }, - ctor => ctor.Assignment("AutoIncrement", "autoIncrement") - ); + $"Constructs a new instance specifying whether the counter auto-increments ({XmlSee("AutoIncrement")})." + ) + .XmlParam("autoIncrement", $"Whether the counter auto-increments ({XmlSee("AutoIncrement")}).") + .Constructor( + new(type.Name, TypeDeclarationAccessibility.Public) + { + Parameters = [new("autoIncrement", TypeLibrary.System.Boolean)], + }, + ctor => ctor.Assignment("AutoIncrement", "autoIncrement") + ); WriteNameUnitDescriptionConstructor( body, type, @@ -1448,19 +1450,24 @@ static void WriteCounterLikeAttribute(CodeWriter writer, TypeIdentity type, stri WritePublicProperty( body, "AutoIncrement", - PurviewTypeLibrary.System.Boolean.AsTypeReference(), - summary: "Determines whether the counter auto-increments." + TypeLibrary.System.Boolean, + "Determines whether the counter auto-increments." ); WriteNullableStringProperty(body, "Name", "Gets or sets the name of the instrument."); WriteNullableStringProperty(body, "Unit", "Gets or sets the measurement unit of the instrument."); WriteNullableStringProperty(body, "Description", "Gets or sets the description of the instrument."); }, - summary: summary + summary ); } - static void WriteObservableCounterLikeAttribute(CodeWriter writer, TypeIdentity type, string? summary = null) + static void WriteObservableCounterLikeAttribute(CodeWriter writer, TypeIdentity type, string summary) { +#if DEUBG + if (string.IsNullOrWhiteSpace(summary)) + throw new ArgumentException("Summary cannot be null or whitespace.", nameof(summary)); +#endif + EmitAttribute( writer, type, @@ -1477,8 +1484,8 @@ static void WriteObservableCounterLikeAttribute(CodeWriter writer, TypeIdentity WritePublicProperty( body, "AutoIncrement", - PurviewTypeLibrary.System.Boolean.AsTypeReference(), - summary: "Determines whether the counter auto-increments." + TypeLibrary.System.Boolean, + "Determines whether the counter auto-increments." ); WriteNullableStringProperty(body, "Name", "Gets or sets the name of the instrument."); WriteNullableStringProperty(body, "Unit", "Gets or sets the measurement unit of the instrument."); @@ -1486,36 +1493,43 @@ static void WriteObservableCounterLikeAttribute(CodeWriter writer, TypeIdentity WritePublicProperty( body, "ThrowOnAlreadyInitialized", - PurviewTypeLibrary.System.Boolean.AsTypeReference(), - summary: "Determines whether an exception is thrown when the instrument is initialized more than once." + TypeLibrary.System.Boolean, + "Determines whether an exception is thrown when the instrument is initialized more than once." ); }, - summary: summary + summary ); } static void WriteNameUnitDescriptionConstructor( CodeWriter writer, TypeIdentity type, + string summary, bool appendAutoIncrement = false, - bool appendThrowOnAlreadyInitialized = false, - string? summary = null + bool appendThrowOnAlreadyInitialized = false ) { - if (summary != null) +#if DEBUG + if (string.IsNullOrWhiteSpace(summary)) + throw new ArgumentException("Summary cannot be null or whitespace.", nameof(summary)); +#endif + + writer + .XmlSummary(summary) + .XmlParam("name", "The name of the instrument.") + .XmlParam("unit", "The measurement unit of the instrument.") + .XmlParam("description", "The description of the instrument."); + + if (appendAutoIncrement) + writer.XmlParam("autoIncrement", "Whether the counter should auto-increment."); + if (appendThrowOnAlreadyInitialized) { - writer.XmlSummary(summary); - writer.XmlParam("name", "The name of the instrument."); - writer.XmlParam("unit", "The measurement unit of the instrument."); - writer.XmlParam("description", "The description of the instrument."); - if (appendAutoIncrement) - writer.XmlParam("autoIncrement", "Whether the counter should auto-increment."); - if (appendThrowOnAlreadyInitialized) - writer.XmlParam( - "throwOnAlreadyInitialized", - "Whether to throw if the instrument has already been initialized." - ); + writer.XmlParam( + "throwOnAlreadyInitialized", + "Whether to throw if the instrument has already been initialized." + ); } + writer.Constructor( new(type.Name, TypeDeclarationAccessibility.Public) { @@ -1540,23 +1554,14 @@ bool appendThrowOnAlreadyInitialized ) { var parameters = ImmutableArray.Empty; - parameters = parameters.Add(new("name", PurviewTypeLibrary.System.String.AsTypeReference())); - parameters = parameters.Add( - new("unit", PurviewTypeLibrary.System.String.AsTypeReference()) { DefaultValue = "null" } - ); - parameters = parameters.Add( - new("description", PurviewTypeLibrary.System.String.AsTypeReference()) { DefaultValue = "null" } - ); + parameters = parameters.Add(new("name", TypeLibrary.System.String)); + parameters = parameters.Add(new("unit", TypeLibrary.System.String) { DefaultValue = "null" }); + parameters = parameters.Add(new("description", TypeLibrary.System.String) { DefaultValue = "null" }); if (appendAutoIncrement) - parameters = parameters.Add( - new("autoIncrement", PurviewTypeLibrary.System.Boolean.AsTypeReference()) { DefaultValue = "false" } - ); + parameters = parameters.Add(new("autoIncrement", TypeLibrary.System.Boolean) { DefaultValue = "false" }); if (appendThrowOnAlreadyInitialized) parameters = parameters.Add( - new("throwOnAlreadyInitialized", PurviewTypeLibrary.System.Boolean.AsTypeReference()) - { - DefaultValue = "false", - } + new("throwOnAlreadyInitialized", TypeLibrary.System.Boolean) { DefaultValue = "false" } ); return parameters; @@ -1569,7 +1574,7 @@ bool appendThrowOnAlreadyInitialized static void WriteTargetsEnum(CodeWriter writer, TypeIdentity type) { writer - .FileScopedNamespace(TypeLibrary.PurviewTelemetryNamespace) + .FileScopedNamespace(TypeLibrary.Purview.Telemetry.Namespace) .XmlSummary("Determines which telemetry targets a parameter is excluded from.") .Enum( type.Name, @@ -1589,7 +1594,7 @@ static void WriteTargetsEnum(CodeWriter writer, TypeIdentity type) static void WriteNamingConventionEnum(CodeWriter writer, TypeIdentity type) { writer - .FileScopedNamespace(TypeLibrary.PurviewTelemetryNamespace) + .FileScopedNamespace(TypeLibrary.Purview.Telemetry.Namespace) .XmlSummary("Determines the naming convention used for generated telemetry names.") .Enum( type.Name, @@ -1608,7 +1613,7 @@ static void WriteLogPrefixTypeEnum(CodeWriter writer, TypeIdentity type) "!EXCLUDE_PURVIEW_TELEMETRY_LOGGING", hashWriter => hashWriter - .FileScopedNamespace(TypeLibrary.PurviewTelemetryNamespace) + .FileScopedNamespace(TypeLibrary.Purview.Telemetry.Namespace) .XmlSummary("Determines the mode used to generate or override the prefix for the log entry.") .Enum( type.Name, @@ -1631,7 +1636,7 @@ static void WriteLoggerGenerationModeEnum(CodeWriter writer, TypeIdentity type) "!EXCLUDE_PURVIEW_TELEMETRY_LOGGING", hashWriter => hashWriter - .FileScopedNamespace(TypeLibrary.PurviewTelemetryNamespace) + .FileScopedNamespace(TypeLibrary.Purview.Telemetry.Namespace) .XmlSummary("Controls the generation mode used for log methods.") .Enum( type.Name, @@ -1649,7 +1654,7 @@ static void WriteLoggerGenerationModeEnum(CodeWriter writer, TypeIdentity type) static void WriteMeterNameGenerationTypeEnum(CodeWriter writer, TypeIdentity type) { writer - .FileScopedNamespace(TypeLibrary.PurviewTelemetryNamespace) + .FileScopedNamespace(TypeLibrary.Purview.Telemetry.Namespace) .XmlSummary("Determines how meter names are generated when not explicitly specified.") .Enum( type.Name, diff --git a/src/src/SourceGenerator/Emitters/LoggerGenTargetClassEmitter.Methods.cs b/src/src/SourceGenerator/Emitters/LoggerGenTargetClassEmitter.Methods.cs index 40d50b89..00113dab 100644 --- a/src/src/SourceGenerator/Emitters/LoggerGenTargetClassEmitter.Methods.cs +++ b/src/src/SourceGenerator/Emitters/LoggerGenTargetClassEmitter.Methods.cs @@ -106,7 +106,7 @@ SourceProductionContext context var returnType = methodTarget.IsScoped ? TypeLibrary.System.IDisposable.AsTypeReference().Nullable(writer) - : PurviewTypeLibrary.System.Void.AsTypeReference(); + : TypeLibrary.System.Void.AsTypeReference(); writer.NewLine(); @@ -303,7 +303,7 @@ bool useTypedState .Write( writer.IsNullableContextEnabled is null or true ? "new (" - : "new " + TypeLibrary.Logging.MicrosoftExtensions.EventId + "(" + : "new " + TypeLibrary.Microsoft.Extensions.Logging.EventId + "(" ) .Write(eventId.ToString(CultureInfo.InvariantCulture)) .Write(", nameof(") @@ -378,7 +378,7 @@ [.. methodTarget.Parameters] .Write( writer.IsNullableContextEnabled is null or true ? "new (" - : "new " + TypeLibrary.Logging.MicrosoftExtensions.EventId + "(" + : "new " + TypeLibrary.Microsoft.Extensions.Logging.EventId + "(" ) .Write(eventId.ToString(CultureInfo.InvariantCulture)) .Write(", nameof(") @@ -453,7 +453,7 @@ SourceProductionContext context .Write("var ") .Write(stateVarName) .Write(" = ") - .Write(TypeLibrary.Logging.MicrosoftExtensions.LoggerMessageHelper) + .Write(TypeLibrary.Microsoft.Extensions.Logging.LoggerMessageHelper) .Write('.') .Line("ThreadLocalState;") .Write(stateVarName) @@ -604,7 +604,7 @@ static void OutputState( writer .Write(value) .Write(" == null ? null : ") - .Write(TypeLibrary.Logging.MicrosoftExtensions.LoggerMessageHelper) + .Write(TypeLibrary.Microsoft.Extensions.Logging.LoggerMessageHelper) .Write(".Stringify(") .Write(value) .Write(')'); @@ -853,7 +853,7 @@ static void EmitLogStateStruct(CodeWriter writer, LogMethodTarget methodTarget, var count = nonExceptionParams.Count + 1; // +1 for {OriginalFormat} var kvpType = - $"global::System.Collections.Generic.KeyValuePair"; + $"global::System.Collections.Generic.KeyValuePair"; var iReadOnlyListType = $"global::System.Collections.Generic.IReadOnlyList<{kvpType}>"; var ienumeratorType = $"global::System.Collections.Generic.IEnumerator<{kvpType}>"; var ienumerableKvpType = $"global::System.Collections.Generic.IEnumerable<{kvpType}>"; @@ -873,7 +873,7 @@ static void EmitLogStateStruct(CodeWriter writer, LogMethodTarget methodTarget, ) { writer.Field( - new FieldDeclarationOptions("s_originalFormat", PurviewTypeLibrary.System.String.AsTypeReference()) + new FieldDeclarationOptions("s_originalFormat", TypeLibrary.System.String.AsTypeReference()) { IsStatic = true, IsReadOnly = true, @@ -929,7 +929,7 @@ static void EmitLogStateStruct(CodeWriter writer, LogMethodTarget methodTarget, .Property( new PropertyDeclarationOptions( "Count", - PurviewTypeLibrary.System.Int32.AsTypeReference(), + TypeLibrary.System.Int32.AsTypeReference(), TypeDeclarationAccessibility.Public ) { @@ -942,7 +942,7 @@ static void EmitLogStateStruct(CodeWriter writer, LogMethodTarget methodTarget, writer.Indexer( new IndexerDeclarationOptions( new TypeReference(new TypeIdentity(kvpType, null)), - new ParameterDeclarationOptions("index", PurviewTypeLibrary.System.Int32.AsTypeReference()) + new ParameterDeclarationOptions("index", TypeLibrary.System.Int32.AsTypeReference()) ) { Accessibility = TypeDeclarationAccessibility.Public, @@ -1036,7 +1036,7 @@ string ienumerableKvpType ); writer.Field( - new FieldDeclarationOptions("_index", PurviewTypeLibrary.System.Int32.AsTypeReference()) + new FieldDeclarationOptions("_index", TypeLibrary.System.Int32.AsTypeReference()) { IncludeGeneratedAttributes = false, } @@ -1075,7 +1075,7 @@ string ienumerableKvpType ) .NewLine() .NewLine() - .Write(PurviewTypeLibrary.System.Object.MakeNullable(writer)) + .Write(TypeLibrary.System.Object.MakeNullable(writer)) .Write(" global::System.Collections.IEnumerator.Current") .Line(" => Current;") .NewLine() @@ -1083,7 +1083,7 @@ string ienumerableKvpType .MethodExpression( new MethodDeclarationOptions( "MoveNext", - PurviewTypeLibrary.System.Boolean.AsTypeReference(), + TypeLibrary.System.Boolean.AsTypeReference(), TypeDeclarationAccessibility.Public ) { @@ -1096,7 +1096,7 @@ string ienumerableKvpType .MethodExpression( new MethodDeclarationOptions( "Reset", - PurviewTypeLibrary.System.Void.AsTypeReference(), + TypeLibrary.System.Void.AsTypeReference(), TypeDeclarationAccessibility.Public ) { @@ -1109,7 +1109,7 @@ string ienumerableKvpType .Method( new MethodDeclarationOptions( "Dispose", - PurviewTypeLibrary.System.Void.AsTypeReference(), + TypeLibrary.System.Void.AsTypeReference(), TypeDeclarationAccessibility.Public ) { @@ -1150,7 +1150,7 @@ static void EmitScopeStateStruct(CodeWriter writer, LogMethodTarget methodTarget var count = nonExceptionParams.Count + 1; // +1 for {OriginalFormat} var kvpType = - $"global::System.Collections.Generic.KeyValuePair"; + $"global::System.Collections.Generic.KeyValuePair"; var iReadOnlyListType = $"global::System.Collections.Generic.IReadOnlyList<{kvpType}>"; var ienumeratorType = $"global::System.Collections.Generic.IEnumerator<{kvpType}>"; var ienumerableKvpType = $"global::System.Collections.Generic.IEnumerable<{kvpType}>"; @@ -1170,7 +1170,7 @@ static void EmitScopeStateStruct(CodeWriter writer, LogMethodTarget methodTarget ) { writer.Field( - new FieldDeclarationOptions("s_originalFormat", PurviewTypeLibrary.System.String.AsTypeReference()) + new FieldDeclarationOptions("s_originalFormat", TypeLibrary.System.String.AsTypeReference()) { IsStatic = true, IsReadOnly = true, @@ -1234,7 +1234,7 @@ [.. methodTarget.Parameters] .Method( new MethodDeclarationOptions( "ToString", - PurviewTypeLibrary.System.String.AsTypeReference(), + TypeLibrary.System.String.AsTypeReference(), TypeDeclarationAccessibility.Public ) { @@ -1264,7 +1264,7 @@ [.. methodTarget.Parameters] .Property( new PropertyDeclarationOptions( "Count", - PurviewTypeLibrary.System.Int32.AsTypeReference(), + TypeLibrary.System.Int32.AsTypeReference(), TypeDeclarationAccessibility.Public ) { @@ -1277,7 +1277,7 @@ [.. methodTarget.Parameters] writer.Indexer( new IndexerDeclarationOptions( new TypeReference(new TypeIdentity(kvpType, null)), - new ParameterDeclarationOptions("index", PurviewTypeLibrary.System.Int32.AsTypeReference()) + new ParameterDeclarationOptions("index", TypeLibrary.System.Int32.AsTypeReference()) ) { Accessibility = TypeDeclarationAccessibility.Public, @@ -1352,7 +1352,7 @@ SourceProductionContext context var returnType = methodTarget.IsScoped ? TypeLibrary.System.IDisposable.MakeNullable(writer) - : PurviewTypeLibrary.System.Void.AsTypeReference(); + : TypeLibrary.System.Void.AsTypeReference(); writer.NewLine(); diff --git a/src/src/SourceGenerator/Emitters/LoggerGenTargetClassEmitter.cs b/src/src/SourceGenerator/Emitters/LoggerGenTargetClassEmitter.cs index 4c5320ae..6df2bd5f 100644 --- a/src/src/SourceGenerator/Emitters/LoggerGenTargetClassEmitter.cs +++ b/src/src/SourceGenerator/Emitters/LoggerGenTargetClassEmitter.cs @@ -84,7 +84,7 @@ static void EmitFields(LoggerOutputContext output, CodeWriter writer, SourceProd .Field( new FieldDeclarationOptions( PropertyLibrary.Logging.LoggerFieldName, - TypeLibrary.Logging.MicrosoftExtensions.ILogger.MakeGeneric(target.InterfaceType).AsTypeReference() + TypeLibrary.Microsoft.Extensions.Logging.ILogger.MakeGeneric(target.InterfaceType).AsTypeReference() ) { IsReadOnly = true, diff --git a/src/src/SourceGenerator/Emitters/LoggerTargetClassEmitter.Fields.cs b/src/src/SourceGenerator/Emitters/LoggerTargetClassEmitter.Fields.cs index c83f567c..9af1e8ab 100644 --- a/src/src/SourceGenerator/Emitters/LoggerTargetClassEmitter.Fields.cs +++ b/src/src/SourceGenerator/Emitters/LoggerTargetClassEmitter.Fields.cs @@ -17,7 +17,7 @@ static void EmitFields(LoggerOutputContext output, CodeWriter writer, SourceProd .Field( new FieldDeclarationOptions( PropertyLibrary.Logging.LoggerFieldName, - TypeLibrary.Logging.MicrosoftExtensions.ILogger.MakeGeneric(target.InterfaceType).AsTypeReference() + TypeLibrary.Microsoft.Extensions.Logging.ILogger.MakeGeneric(target.InterfaceType).AsTypeReference() ) { IsReadOnly = true, @@ -91,7 +91,7 @@ internal static void EmitLogActionField(CodeWriter writer, LogMethodTarget metho var typeName = (methodTarget.IsScoped ? "global::System.Func<" : "global::System.Action<") - + TypeLibrary.Logging.MicrosoftExtensions.ILogger.RenderFullNameForNullable(useNullable) + + TypeLibrary.Microsoft.Extensions.Logging.ILogger.RenderFullNameForNullable(useNullable) + string.Concat( methodTarget.ParametersSansException.Select(p => ", " + p.ParameterType.RenderFullNameForNullable(useNullable) diff --git a/src/src/SourceGenerator/Emitters/LoggerTargetClassEmitter.Methods.cs b/src/src/SourceGenerator/Emitters/LoggerTargetClassEmitter.Methods.cs index 6d8f72cf..35d39383 100644 --- a/src/src/SourceGenerator/Emitters/LoggerTargetClassEmitter.Methods.cs +++ b/src/src/SourceGenerator/Emitters/LoggerTargetClassEmitter.Methods.cs @@ -10,7 +10,7 @@ internal static void EmitThrowStub(CodeWriter writer, LogMethodTarget methodTarg { var returnType = methodTarget.IsScoped ? TypeLibrary.System.IDisposable.AsTypeReference().Nullable(writer) - : PurviewTypeLibrary.System.Void.AsTypeReference(); + : TypeLibrary.System.Void.AsTypeReference(); writer.NewLine(); using ( @@ -108,7 +108,7 @@ SourceProductionContext context var returnType = generatePrivateLogging || !methodTarget.IsScoped - ? PurviewTypeLibrary.System.Void.AsTypeReference() + ? TypeLibrary.System.Void.AsTypeReference() : TypeLibrary.System.IDisposable.AsTypeReference().Nullable(writer); writer.NewLine(); @@ -192,7 +192,7 @@ SourceProductionContext context var returnType = methodTarget.IsScoped ? TypeLibrary.System.IDisposable.AsTypeReference().Nullable(writer) - : PurviewTypeLibrary.System.Void.AsTypeReference(); + : TypeLibrary.System.Void.AsTypeReference(); writer.NewLine(); diff --git a/src/src/SourceGenerator/Emitters/MeterTargetClassEmitter.Fields.cs b/src/src/SourceGenerator/Emitters/MeterTargetClassEmitter.Fields.cs index 3b13d4ea..aceb7e37 100644 --- a/src/src/SourceGenerator/Emitters/MeterTargetClassEmitter.Fields.cs +++ b/src/src/SourceGenerator/Emitters/MeterTargetClassEmitter.Fields.cs @@ -1,5 +1,4 @@ using Microsoft.CodeAnalysis; -using Purview.Telemetry.SourceGenerator.Helpers; using Purview.Telemetry.SourceGenerator.Records; namespace Purview.Telemetry.SourceGenerator.Emitters; @@ -26,7 +25,7 @@ static void EmitFields( .Field( new FieldDeclarationOptions( MeterFieldName, - TypeLibrary.Metrics.SystemDiagnostics.Meter.AsTypeReference() + TypeLibrary.System.Diagnostics.Metrics.Meter.AsTypeReference() ) { IsReadOnly = true, @@ -41,7 +40,7 @@ static void EmitFields( .Field( new FieldDeclarationOptions( MeterFieldName, - TypeLibrary.Metrics.SystemDiagnostics.Meter.AsTypeReference() + TypeLibrary.System.Diagnostics.Metrics.Meter.AsTypeReference() ) { Initializer = writer.IsNullableContextEnabled is null or true ? "default!" : "default", @@ -66,7 +65,7 @@ static void EmitFields( } var type = TypeLibrary - .Metrics.InstrumentTypeMap[method.InstrumentAttribute.InstrumentType] + .Purview.Telemetry.InstrumentTypeMap[method.InstrumentAttribute.InstrumentType] .MakeGeneric(method.InstrumentMeasurementType); // Observable instruments are registered via callback, not assigned in the constructor, diff --git a/src/src/SourceGenerator/Emitters/MeterTargetClassEmitter.InitializationMethod.cs b/src/src/SourceGenerator/Emitters/MeterTargetClassEmitter.InitializationMethod.cs index efddda15..d9f4894b 100644 --- a/src/src/SourceGenerator/Emitters/MeterTargetClassEmitter.InitializationMethod.cs +++ b/src/src/SourceGenerator/Emitters/MeterTargetClassEmitter.InitializationMethod.cs @@ -18,7 +18,7 @@ static void EmitInitializationMethod(MeterOutputContext output, CodeWriter write writer.MethodScope( new MethodDeclarationOptions( PropertyLibrary.Metrics.MeterInitializationMethod, - PurviewTypeLibrary.System.Void.AsTypeReference() + TypeLibrary.System.Void.AsTypeReference() ) { Parameters = supportsIMeterFactory @@ -26,7 +26,7 @@ static void EmitInitializationMethod(MeterOutputContext output, CodeWriter write [ new ParameterDeclarationOptions( PropertyLibrary.Metrics.MeterFactoryParameterName, - TypeLibrary.Metrics.SystemDiagnostics.IMeterFactory.AsTypeReference() + TypeLibrary.System.Diagnostics.Metrics.IMeterFactory.AsTypeReference() ), ] : [], @@ -72,7 +72,7 @@ static void EmitInlineConstructor(MeterOutputContext output, CodeWriter writer, [ new ParameterDeclarationOptions( PropertyLibrary.Metrics.MeterFactoryParameterName, - TypeLibrary.Metrics.SystemDiagnostics.IMeterFactory.AsTypeReference() + TypeLibrary.System.Diagnostics.Metrics.IMeterFactory.AsTypeReference() ), ] : [], @@ -103,7 +103,7 @@ static void EmitInitializationBodyContent(MeterOutputContext output, CodeWriter .Write(" = ") .Write(PropertyLibrary.Metrics.MeterFactoryParameterName) .Write(".Create(new ") - .Write(TypeLibrary.Metrics.SystemDiagnostics.MeterOptions) + .Write(TypeLibrary.System.Diagnostics.Metrics.MeterOptions) .Write("(") .Write(target.MeterName!.Wrap()) .Write(") {") @@ -119,7 +119,7 @@ static void EmitInitializationBodyContent(MeterOutputContext output, CodeWriter writer .Write(MeterFieldName) .Write(" = new ") - .Write(TypeLibrary.Metrics.SystemDiagnostics.Meter) + .Write(TypeLibrary.System.Diagnostics.Metrics.Meter) .Write('(') .Write(target.MeterName!.Wrap()) .Line(");") diff --git a/src/src/SourceGenerator/Emitters/MeterTargetClassEmitter.Methods.cs b/src/src/SourceGenerator/Emitters/MeterTargetClassEmitter.Methods.cs index 69114ad6..f1d9c97b 100644 --- a/src/src/SourceGenerator/Emitters/MeterTargetClassEmitter.Methods.cs +++ b/src/src/SourceGenerator/Emitters/MeterTargetClassEmitter.Methods.cs @@ -138,7 +138,7 @@ SourceProductionContext context var returnType = isMultiTarget && !metricsOwnsPublicMethod - ? PurviewTypeLibrary.System.Void.AsTypeReference() + ? TypeLibrary.System.Void.AsTypeReference() : methodTarget.ReturnType; var parameters = BuildParameters(methodTarget); @@ -212,12 +212,12 @@ .. methodTarget.Parameters.Select(p => var type = methodTarget.InstrumentMeasurementType; if (methodTarget.MeasurementParameter!.IsMeasurement) - type = TypeLibrary.Metrics.SystemDiagnostics.Measurement.MakeGeneric(type); + type = TypeLibrary.System.Diagnostics.Metrics.Measurement.MakeGeneric(type); if (methodTarget.MeasurementParameter!.IsIEnumerable) - type = TypeLibrary.System.GenericIEnumerable.MakeGeneric(type); + type = TypeLibrary.System.Collections.Generic.IEnumerable.MakeGeneric(type); - type = PurviewTypeLibrary.System.Func.MakeGeneric(type); + type = TypeLibrary.System.Func.MakeGeneric(type); return new ParameterDeclarationOptions(p.ParameterName, new TypeReference(type)); }), @@ -373,7 +373,7 @@ static void EmitInstrumentBody( } var tagVariableName = Utilities.LowercaseFirstChar(methodTarget.MethodName + "TagList"); - writer.Assignment(TypeLibrary.System.TagList, tagVariableName, "new()").NewLine(); + writer.Assignment(TypeLibrary.System.Diagnostics.TagList, tagVariableName, "new()").NewLine(); foreach (var param in methodTarget.Tags) { diff --git a/src/src/SourceGenerator/Emitters/MeterTargetClassEmitter.cs b/src/src/SourceGenerator/Emitters/MeterTargetClassEmitter.cs index e0a339ee..515eb438 100644 --- a/src/src/SourceGenerator/Emitters/MeterTargetClassEmitter.cs +++ b/src/src/SourceGenerator/Emitters/MeterTargetClassEmitter.cs @@ -7,9 +7,9 @@ namespace Purview.Telemetry.SourceGenerator.Emitters; static partial class MeterTargetClassEmitter { static TypeReference GetDictionaryType(CodeWriter writer) => - TypeLibrary.System.Dictionary.MakeGeneric( - PurviewTypeLibrary.System.String.AsTypeReference(), - PurviewTypeLibrary.System.Object.AsTypeReference().Nullable(writer) + TypeLibrary.System.Collections.Generic.Dictionary.MakeGeneric( + TypeLibrary.System.String.AsTypeReference(), + TypeLibrary.System.Object.AsTypeReference().Nullable(writer) ); const string MeterFieldName = "_meter"; diff --git a/src/src/SourceGenerator/Emitters/TelemetryNamesEmitter.cs b/src/src/SourceGenerator/Emitters/TelemetryNamesEmitter.cs index 02f5b558..680063ee 100644 --- a/src/src/SourceGenerator/Emitters/TelemetryNamesEmitter.cs +++ b/src/src/SourceGenerator/Emitters/TelemetryNamesEmitter.cs @@ -35,7 +35,7 @@ GenerationContext generationContext ) ) { - var stringArrayType = PurviewTypeLibrary.System.String.AsTypeReference().MakeArray(); + var stringArrayType = TypeLibrary.System.String.AsTypeReference().MakeArray(); writer.XmlSummary("Gets the names of the meters generated for the assembly."); writer.Field( new("MeterNames", stringArrayType, TypeDeclarationAccessibility.Public) diff --git a/src/src/SourceGenerator/Extensions/Purview/SourceGeneratorFramework/TypeLibraryExtensions.cs b/src/src/SourceGenerator/Extensions/Purview/SourceGeneratorFramework/TypeLibraryExtensions.cs new file mode 100644 index 00000000..ad8992ab --- /dev/null +++ b/src/src/SourceGenerator/Extensions/Purview/SourceGeneratorFramework/TypeLibraryExtensions.cs @@ -0,0 +1,58 @@ +using System.Collections.Immutable; +using Purview.Telemetry.SourceGenerator.Records; + +namespace Purview.SourceGeneratorFramework; + +static class TypeLibraryExtensions +{ + static readonly ImmutableArray LogAttributeTargets = ImmutableArray.Create( + TypeLibrary.Purview.Telemetry.LogAttribute, + TypeLibrary.Purview.Telemetry.TraceAttribute, + TypeLibrary.Purview.Telemetry.DebugAttribute, + TypeLibrary.Purview.Telemetry.InfoAttribute, + TypeLibrary.Purview.Telemetry.WarningAttribute, + TypeLibrary.Purview.Telemetry.ErrorAttribute, + TypeLibrary.Purview.Telemetry.CriticalAttribute + ); + + static readonly ImmutableDictionary InstrumentTypeMap = Create(); + + static readonly ImmutableDictionary LogLevelMap = new Dictionary< + TypeIdentity, + LogLevelDetails + > + { + { TypeLibrary.Purview.Telemetry.TraceAttribute, new(TypeLibrary.Purview.Telemetry.TraceAttribute, 0, "Trace") }, + { TypeLibrary.Purview.Telemetry.DebugAttribute, new(TypeLibrary.Purview.Telemetry.DebugAttribute, 1, "Debug") }, + { TypeLibrary.Purview.Telemetry.InfoAttribute, new(TypeLibrary.Purview.Telemetry.InfoAttribute, 2, "Info") }, + { + TypeLibrary.Purview.Telemetry.WarningAttribute, + new(TypeLibrary.Purview.Telemetry.WarningAttribute, 3, "Warning") + }, + { TypeLibrary.Purview.Telemetry.ErrorAttribute, new(TypeLibrary.Purview.Telemetry.ErrorAttribute, 4, "Error") }, + { + TypeLibrary.Purview.Telemetry.CriticalAttribute, + new(TypeLibrary.Purview.Telemetry.CriticalAttribute, 5, "Critical") + }, + }.ToImmutableDictionary(); + + static ImmutableDictionary Create() => + new Dictionary + { + { InstrumentTypes.Counter, TypeLibrary.System.Diagnostics.Metrics.Counter }, + { InstrumentTypes.UpDownCounter, TypeLibrary.System.Diagnostics.Metrics.UpDownCounter }, + { InstrumentTypes.Histogram, TypeLibrary.System.Diagnostics.Metrics.Histogram }, + { InstrumentTypes.ObservableCounter, TypeLibrary.System.Diagnostics.Metrics.ObservableCounter }, + { InstrumentTypes.ObservableGauge, TypeLibrary.System.Diagnostics.Metrics.ObservableGauge }, + { InstrumentTypes.ObservableUpDownCounter, TypeLibrary.System.Diagnostics.Metrics.ObservableUpDownCounter }, + }.ToImmutableDictionary(); + + extension(TypeLibrary.Purview.Telemetry) + { + public static ImmutableArray LogAttributeTargets => LogAttributeTargets; + + public static ImmutableDictionary LogLevelMap => LogLevelMap; + + public static ImmutableDictionary InstrumentTypeMap => InstrumentTypeMap; + } +} diff --git a/src/src/SourceGenerator/Generators/TelemetrySourceGenerator.Activities.cs b/src/src/SourceGenerator/Generators/TelemetrySourceGenerator.Activities.cs index 0db12697..755e915c 100644 --- a/src/src/SourceGenerator/Generators/TelemetrySourceGenerator.Activities.cs +++ b/src/src/SourceGenerator/Generators/TelemetrySourceGenerator.Activities.cs @@ -22,6 +22,14 @@ IncrementalValueProvider> generationCon source: outputContexts, action: static (spc, output) => { + if (output.Context.Settings.IsSourceGeneratorDisabled) + { + output.Context.Debug( + $"Activity generation skipped for {output.Target.FullyQualifiedName} because the generator is disabled" + ); + return; + } + output.Context.Debug($"Activity generation target: {output.Target.FullyQualifiedName}"); RunSafely(spc, () => ActivitySourceTargetClassEmitter.GenerateImplementation(output, spc)); diff --git a/src/src/SourceGenerator/Generators/TelemetrySourceGenerator.Logging.cs b/src/src/SourceGenerator/Generators/TelemetrySourceGenerator.Logging.cs index ac5d087b..94ef3add 100644 --- a/src/src/SourceGenerator/Generators/TelemetrySourceGenerator.Logging.cs +++ b/src/src/SourceGenerator/Generators/TelemetrySourceGenerator.Logging.cs @@ -15,7 +15,7 @@ IncrementalValueProvider> generationCon // Register var loggerTargetsPredicate = IncrementalPipeline.ForAttributeWithMetadataName( context, - TypeLibrary.Logging.LoggerAttribute, + TypeLibrary.Purview.Telemetry.LoggerAttribute, transform: static (context, cancellationToken) => PipelineHelpers.BuildLoggerTransform(context, cancellationToken), predicate: static (node, token) => PipelineHelpers.HasLoggerTargetAttribute(node, token), @@ -33,6 +33,14 @@ IncrementalValueProvider> generationCon source: outputContexts, action: static (spc, output) => { + if (output.Context.Settings.IsSourceGeneratorDisabled) + { + output.Context.Debug( + $"Logger generation skipped for {output.Target.FullyQualifiedName} because the generator is disabled" + ); + return; + } + output.Context.Debug($"Logger generation target: {output.Target.FullyQualifiedName}"); if (output.Target.UseMSLoggingTelemetryBasedGeneration) diff --git a/src/src/SourceGenerator/Generators/TelemetrySourceGenerator.Metrics.cs b/src/src/SourceGenerator/Generators/TelemetrySourceGenerator.Metrics.cs index cc476c13..9182e5b1 100644 --- a/src/src/SourceGenerator/Generators/TelemetrySourceGenerator.Metrics.cs +++ b/src/src/SourceGenerator/Generators/TelemetrySourceGenerator.Metrics.cs @@ -22,6 +22,14 @@ IncrementalValueProvider> generationCon source: outputContexts, action: static (spc, output) => { + if (output.Context.Settings.IsSourceGeneratorDisabled) + { + output.Context.Debug( + $"Meter generation skipped for {output.Target.FullyQualifiedName} because the generator is disabled" + ); + return; + } + output.Context.Debug($"Meter generation target: {output.Target.FullyQualifiedName}"); RunSafely(spc, () => MeterTargetClassEmitter.GenerateImplementation(output, spc)); } diff --git a/src/src/SourceGenerator/Generators/TelemetrySourceGenerator.TelemetryNames.cs b/src/src/SourceGenerator/Generators/TelemetrySourceGenerator.TelemetryNames.cs index f0bfcaec..6e26ceec 100644 --- a/src/src/SourceGenerator/Generators/TelemetrySourceGenerator.TelemetryNames.cs +++ b/src/src/SourceGenerator/Generators/TelemetrySourceGenerator.TelemetryNames.cs @@ -41,6 +41,14 @@ IncrementalValueProvider> generationCon static void GenerateTelemetryNames(TelemetryNamesOutputContext output, SourceProductionContext spc) { + if (output.Context.Settings.IsSourceGeneratorDisabled) + { + output.Context.Debug( + $"Telemetry names generation skipped for {output.AssemblyName} because the generator is disabled" + ); + return; + } + // Only generate if we have at least one target if (output.MeterTargets.IsEmpty && output.ActivityTargets.IsEmpty) { diff --git a/src/src/SourceGenerator/Generators/TelemetrySourceGenerator.cs b/src/src/SourceGenerator/Generators/TelemetrySourceGenerator.cs index dd291cb6..d8a0d1f5 100644 --- a/src/src/SourceGenerator/Generators/TelemetrySourceGenerator.cs +++ b/src/src/SourceGenerator/Generators/TelemetrySourceGenerator.cs @@ -44,13 +44,13 @@ public void Initialize(IncrementalGeneratorInitializationContext context) var generationContext = IncrementalPipeline.GenerationContextValueProvider< TelemetryCapabilities, TelemetrySourceGenerator - >(context, BuildCapabilities, null); + >(context, BuildCapabilities, PropertyLibrary.DisableTelemetryGenerator); // Create shared providers so Activities/Metrics pipelines aren't registered twice. var activityProvider = IncrementalPipeline .ForAttributeWithMetadataName( context, - TypeLibrary.Activities.ActivitySourceAttribute, + TypeLibrary.Purview.Telemetry.ActivitySourceAttribute, transform: static (ctx, cancellationToken) => PipelineHelpers.BuildActivityTransform(ctx, cancellationToken), predicate: static (node, token) => PipelineHelpers.HasActivityTargetAttribute(node, token), @@ -61,7 +61,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context) var meterProvider = IncrementalPipeline .ForAttributeWithMetadataName( context, - TypeLibrary.Metrics.MeterAttribute, + TypeLibrary.Purview.Telemetry.MeterAttribute, transform: static (ctx, cancellationToken) => PipelineHelpers.BuildMeterTransform(ctx, cancellationToken), predicate: static (node, token) => PipelineHelpers.HasMeterTargetAttribute(node, token), diff --git a/src/src/SourceGenerator/Helpers/DiagnosticLibrary.Activities.cs b/src/src/SourceGenerator/Helpers/DiagnosticLibrary.Activities.cs index f5c7a1f6..b3432a42 100644 --- a/src/src/SourceGenerator/Helpers/DiagnosticLibrary.Activities.cs +++ b/src/src/SourceGenerator/Helpers/DiagnosticLibrary.Activities.cs @@ -34,7 +34,7 @@ public static class Activities new DiagnosticDescriptor( id: "TSG3002", title: "Invalid return type", - messageFormat: $"An activity or event must return either void or an {TypeLibrary.Activities.SystemDiagnostics.Activity.Name}.", + messageFormat: $"An activity or event must return either void or an {TypeLibrary.System.Diagnostics.Activity.Name}.", defaultSeverity: DiagnosticSeverity.Error, category: Categories.Activity.Usage, isEnabledByDefault: true diff --git a/src/src/SourceGenerator/Helpers/DiagnosticLibrary.General.cs b/src/src/SourceGenerator/Helpers/DiagnosticLibrary.General.cs index 9d21ad99..9c9ef77b 100644 --- a/src/src/SourceGenerator/Helpers/DiagnosticLibrary.General.cs +++ b/src/src/SourceGenerator/Helpers/DiagnosticLibrary.General.cs @@ -1,5 +1,4 @@ using Microsoft.CodeAnalysis; -using Purview.Telemetry.SourceGenerator.Helpers; namespace Purview.Telemetry.SourceGenerator; @@ -23,10 +22,10 @@ public static class General id: "TSG1001", title: "Inferring generation targets is not supported when using multi-target generation", messageFormat: "When using multiple generation targets - Activities, Logs or Metrics, each method must be either excluded or have an explicit generation target: " - + $"{TypeLibrary.Activities.ActivityAttribute.Name}, {TypeLibrary.Activities.EventAttribute.Name}, {TypeLibrary.Activities.ContextAttribute.Name}, {TypeLibrary.Logging.LogAttribute.Name}, " - + $"{TypeLibrary.Logging.WarningAttribute.Name}, " - + $"{TypeLibrary.Metrics.CounterAttribute.Name}, {TypeLibrary.Metrics.HistogramAttribute.Name}, {TypeLibrary.Metrics.UpDownCounterAttribute.Name}, " - + $"{TypeLibrary.Metrics.ObservableCounterAttribute.Name}, {TypeLibrary.Metrics.ObservableGaugeAttribute.Name} or {TypeLibrary.Metrics.ObservableUpDownCounterAttribute.Name}.", + + $"{TypeLibrary.Purview.Telemetry.ActivityAttribute.Name}, {TypeLibrary.Purview.Telemetry.EventAttribute.Name}, {TypeLibrary.Purview.Telemetry.ContextAttribute.Name}, {TypeLibrary.Purview.Telemetry.LogAttribute.Name}, " + + $"{TypeLibrary.Purview.Telemetry.WarningAttribute.Name}, " + + $"{TypeLibrary.Purview.Telemetry.CounterAttribute.Name}, {TypeLibrary.Purview.Telemetry.HistogramAttribute.Name}, {TypeLibrary.Purview.Telemetry.UpDownCounterAttribute.Name}, " + + $"{TypeLibrary.Purview.Telemetry.ObservableCounterAttribute.Name}, {TypeLibrary.Purview.Telemetry.ObservableGaugeAttribute.Name} or {TypeLibrary.Purview.Telemetry.ObservableUpDownCounterAttribute.Name}.", defaultSeverity: DiagnosticSeverity.Error, category: Categories.Usage, isEnabledByDefault: true @@ -118,7 +117,7 @@ public static class General id: "TSG1010", title: "Method target not registered on interface", messageFormat: "Method has attribute(s) for a generation target that is not registered on the interface. " - + $"Add the corresponding source attribute ([{TypeLibrary.Activities.ActivitySourceAttribute.Name}], [{TypeLibrary.Logging.LoggerAttribute.Name}], or [{TypeLibrary.Metrics.MeterAttribute.Name}]) " + + $"Add the corresponding source attribute ([{TypeLibrary.Purview.Telemetry.ActivitySourceAttribute.Name}], [{TypeLibrary.Purview.Telemetry.LoggerAttribute.Name}], or [{TypeLibrary.Purview.Telemetry.MeterAttribute.Name}]) " + "to the interface to enable generation for the target(s) used by this method.", defaultSeverity: DiagnosticSeverity.Error, category: Categories.Usage, diff --git a/src/src/SourceGenerator/Helpers/InstrumentMethodModelBuilder.cs b/src/src/SourceGenerator/Helpers/InstrumentMethodModelBuilder.cs index 3db44374..672f0e07 100644 --- a/src/src/SourceGenerator/Helpers/InstrumentMethodModelBuilder.cs +++ b/src/src/SourceGenerator/Helpers/InstrumentMethodModelBuilder.cs @@ -34,7 +34,7 @@ CancellationToken token { token.ThrowIfCancellationRequested(); - if (TypeHelpers.HasAttribute(method, TypeLibrary.TelemetryShared.ExcludeAttribute)) + if (TypeHelpers.HasAttribute(method, TypeLibrary.Purview.Telemetry.ExcludeAttribute)) continue; if (method.Arity > 0) @@ -80,7 +80,7 @@ CancellationToken token GenerationType.Metrics ); - var instrumentMeasurementType = measurementParameter?.InstrumentType ?? PurviewTypeLibrary.System.Int32; + var instrumentMeasurementType = measurementParameter?.InstrumentType ?? TypeLibrary.System.Int32; methodTargets.Add( new( @@ -168,10 +168,10 @@ CancellationToken token // Skip Activity-related parameters - they are not valid for metrics var paramType = TypeReference.Create(parameter.Type); if ( - paramType.Identity.Equals(TypeLibrary.Activities.SystemDiagnostics.Activity) - || paramType.Identity.Equals(TypeLibrary.Activities.SystemDiagnostics.ActivityContext) - || paramType.Identity.Equals(TypeLibrary.Activities.SystemDiagnostics.ActivityLink) - || paramType.Identity.Equals(TypeLibrary.Activities.SystemDiagnostics.ActivityLinkArray) + paramType.Identity.Equals(TypeLibrary.System.Diagnostics.Activity) + || paramType.Identity.Equals(TypeLibrary.System.Diagnostics.ActivityContext) + || paramType.Identity.Equals(TypeLibrary.System.Diagnostics.ActivityLink) + || paramType.Identity.Equals(TypeLibrary.System.Diagnostics.ActivityLinkArray) ) { continue; @@ -238,7 +238,7 @@ out InstrumentParameterDestination destination if ( Utilities.TryContainsAttribute( parameter, - TypeLibrary.TelemetryShared.TagAttribute, + TypeLibrary.Purview.Telemetry.TagAttribute, token, out var attribute ) @@ -248,7 +248,7 @@ out var attribute return SharedHelpers.GetTagOrBaggageAttribute(attribute!, token); } - if (TypeHelpers.HasAttribute(parameter, TypeLibrary.Metrics.InstrumentMeasurementAttribute)) + if (TypeHelpers.HasAttribute(parameter, TypeLibrary.Purview.Telemetry.InstrumentMeasurementAttribute)) destination = InstrumentParameterDestination.Measurement; return null; @@ -284,14 +284,14 @@ out var attribute if ( funcArg is INamedTypeSymbol enumerableType - && TypeLibrary.System.GenericIEnumerable.Equals(enumerableType.ConstructedFrom) + && TypeLibrary.System.Collections.Generic.IEnumerable.Equals(enumerableType.ConstructedFrom) ) { // Func> var enumerableArg = enumerableType.TypeArguments[0]; if ( enumerableArg is INamedTypeSymbol measurementContainer - && TypeLibrary.Metrics.SystemDiagnostics.Measurement.Equals(measurementContainer.ConstructedFrom) + && TypeLibrary.System.Diagnostics.Metrics.Measurement.Equals(measurementContainer.ConstructedFrom) ) { // Func>> @@ -311,7 +311,7 @@ enumerableArg is INamedTypeSymbol measurementContainer if ( funcArg is INamedTypeSymbol funcMeasurementType - && TypeLibrary.Metrics.SystemDiagnostics.Measurement.Equals(funcMeasurementType.ConstructedFrom) + && TypeLibrary.System.Diagnostics.Metrics.Measurement.Equals(funcMeasurementType.ConstructedFrom) ) { // Func> diff --git a/src/src/SourceGenerator/Helpers/LogMethodModelBuilder.cs b/src/src/SourceGenerator/Helpers/LogMethodModelBuilder.cs index a4668bcd..62888f43 100644 --- a/src/src/SourceGenerator/Helpers/LogMethodModelBuilder.cs +++ b/src/src/SourceGenerator/Helpers/LogMethodModelBuilder.cs @@ -29,7 +29,7 @@ CancellationToken token List methodTargets = []; foreach (var method in PipelineHelpers.GetAllInterfaceMethods(interfaceSymbol, token)) { - if (Utilities.ContainsAttribute(method, TypeLibrary.TelemetryShared.ExcludeAttribute, token)) + if (Utilities.ContainsAttribute(method, TypeLibrary.Purview.Telemetry.ExcludeAttribute, token)) continue; // For multi-target interfaces (generationType != GenerationType.Logging means interface has multiple targets): @@ -422,11 +422,11 @@ out bool hasError // Skip Activity-related parameters and TagList - they are not valid for logging var parameterType = TypeReference.Create(parameter.Type); if ( - parameterType.Identity.Equals(TypeLibrary.Activities.SystemDiagnostics.Activity) - || parameterType.Identity.Equals(TypeLibrary.Activities.SystemDiagnostics.ActivityContext) - || parameterType.Identity.Equals(TypeLibrary.Activities.SystemDiagnostics.ActivityLink) - || parameterType.Identity.Equals(TypeLibrary.Activities.SystemDiagnostics.ActivityLinkArray) - || parameterType.Identity.Equals(TypeLibrary.System.TagList) + parameterType.Identity.Equals(TypeLibrary.System.Diagnostics.Activity) + || parameterType.Identity.Equals(TypeLibrary.System.Diagnostics.ActivityContext) + || parameterType.Identity.Equals(TypeLibrary.System.Diagnostics.ActivityLink) + || parameterType.Identity.Equals(TypeLibrary.System.Diagnostics.ActivityLinkArray) + || parameterType.Identity.Equals(TypeLibrary.System.Diagnostics.TagList) ) { continue; @@ -454,7 +454,7 @@ out bool hasError if ( Utilities.ContainsAttribute( property, - TypeLibrary.Logging.MicrosoftExtensions.LogPropertyIgnoreAttribute, + TypeLibrary.Microsoft.Extensions.Logging.LogPropertyIgnoreAttribute, token ) ) diff --git a/src/src/SourceGenerator/Helpers/PipelineHelpers.Activities.cs b/src/src/SourceGenerator/Helpers/PipelineHelpers.Activities.cs index d94ad0f4..d254e429 100644 --- a/src/src/SourceGenerator/Helpers/PipelineHelpers.Activities.cs +++ b/src/src/SourceGenerator/Helpers/PipelineHelpers.Activities.cs @@ -143,7 +143,7 @@ CancellationToken token continue; } - if (TypeHelpers.HasAttribute(method, TypeLibrary.TelemetryShared.ExcludeAttribute)) + if (TypeHelpers.HasAttribute(method, TypeLibrary.Purview.Telemetry.ExcludeAttribute)) continue; var (methodType, isInferred) = GetMethodType( @@ -184,7 +184,7 @@ out var eventAttribute ReturnType: TypeReference.Create(method.ReturnType), ActivityOrEventName: activityOrEventName!, HasActivityParameter: parameters.Any(m => - m.ParameterType.Identity.Equals(TypeLibrary.Activities.SystemDiagnostics.Activity) + m.ParameterType.Identity.Equals(TypeLibrary.System.Diagnostics.Activity) ), ActivityAttribute: activityAttribute, EventAttribute: eventAttribute, @@ -267,11 +267,11 @@ out EventAttributeData? eventAttribute if (eventAttribute != null) return (ActivityMethodType.Event, false); - if (Utilities.ContainsAttribute(method, TypeLibrary.Activities.ContextAttribute, token)) + if (Utilities.ContainsAttribute(method, TypeLibrary.Purview.Telemetry.ContextAttribute, token)) return (ActivityMethodType.Context, false); var returnType = method.ReturnType; - if (TypeLibrary.Activities.SystemDiagnostics.Activity.Equals(returnType)) + if (TypeLibrary.System.Diagnostics.Activity.Equals(returnType)) return (ActivityMethodType.Activity, true); if (method.Name.EndsWith("Event", StringComparison.Ordinal)) @@ -280,7 +280,7 @@ out EventAttributeData? eventAttribute { if ( method.Parameters.Length > 0 - && TypeLibrary.Activities.SystemDiagnostics.Activity.Equals(method.Parameters[0].Type) + && TypeLibrary.System.Diagnostics.Activity.Equals(method.Parameters[0].Type) ) return (ActivityMethodType.Event, true); } @@ -303,34 +303,41 @@ CancellationToken token if ( Utilities.TryContainsAttribute( parameter, - TypeLibrary.TelemetryShared.TagAttribute, + TypeLibrary.Purview.Telemetry.TagAttribute, token, out var attribute ) ) return (ActivityParameterDestination.Tag, attribute); - if (Utilities.TryContainsAttribute(parameter, TypeLibrary.Activities.BaggageAttribute, token, out attribute)) + if ( + Utilities.TryContainsAttribute( + parameter, + TypeLibrary.Purview.Telemetry.BaggageAttribute, + token, + out attribute + ) + ) return (ActivityParameterDestination.Baggage, attribute); - if (Utilities.ContainsAttribute(parameter, TypeLibrary.Activities.EscapeAttribute, token)) + if (Utilities.ContainsAttribute(parameter, TypeLibrary.Purview.Telemetry.EscapeAttribute, token)) return (ActivityParameterDestination.Escape, null); - if (Utilities.ContainsAttribute(parameter, TypeLibrary.Activities.StatusDescriptionAttribute, token)) + if (Utilities.ContainsAttribute(parameter, TypeLibrary.Purview.Telemetry.StatusDescriptionAttribute, token)) return (ActivityParameterDestination.StatusDescription, null); - if (parameterType.Identity.Equals(TypeLibrary.Activities.SystemDiagnostics.Activity)) + if (parameterType.Identity.Equals(TypeLibrary.System.Diagnostics.Activity)) return (ActivityParameterDestination.Activity, null); if ( - parameterType.Identity.Equals(TypeLibrary.Activities.SystemDiagnostics.ActivityTagsCollection) - || TypeLibrary.Activities.SystemDiagnostics.ActivityTagIEnumerable.Similar(parameterType) - || parameterType.Identity.Equals(TypeLibrary.System.TagList) + parameterType.Identity.Equals(TypeLibrary.System.Diagnostics.ActivityTagsCollection) + || TypeLibrary.System.Diagnostics.ActivityTagIEnumerable.Similar(parameterType) + || parameterType.Identity.Equals(TypeLibrary.System.Diagnostics.TagList) ) return (ActivityParameterDestination.TagsEnumerable, null); if ( - parameterType.Identity.Equals(TypeLibrary.Activities.SystemDiagnostics.ActivityContext) + parameterType.Identity.Equals(TypeLibrary.System.Diagnostics.ActivityContext) || ( parameter.Name == PropertyLibrary.Activities.ParentIdParameterName && parameterType.Identity.SpecialType == SpecialType.System_String @@ -339,8 +346,8 @@ out var attribute return (ActivityParameterDestination.ParentContextOrId, null); if ( - parameterType.Identity.Equals(TypeLibrary.Activities.SystemDiagnostics.ActivityLinkArray) - || TypeLibrary.Activities.SystemDiagnostics.ActivityLinkIEnumerable.Equals(parameterType) + parameterType.Identity.Equals(TypeLibrary.System.Diagnostics.ActivityLinkArray) + || TypeLibrary.System.Diagnostics.ActivityLinkIEnumerable.Equals(parameterType) ) return (ActivityParameterDestination.LinksEnumerable, null); diff --git a/src/src/SourceGenerator/Helpers/PipelineHelpers.Logger.cs b/src/src/SourceGenerator/Helpers/PipelineHelpers.Logger.cs index 528dd960..b3d05195 100644 --- a/src/src/SourceGenerator/Helpers/PipelineHelpers.Logger.cs +++ b/src/src/SourceGenerator/Helpers/PipelineHelpers.Logger.cs @@ -25,7 +25,7 @@ CancellationToken token return GeneratorResult.Empty; var iLoggerTypeSymbol = compilation.GetTypeByMetadataName( - TypeLibrary.Logging.MicrosoftExtensions.ILogger.MetadataFullName + TypeLibrary.Microsoft.Extensions.Logging.ILogger.MetadataFullName ); if (iLoggerTypeSymbol is null) return GeneratorResult.Empty; diff --git a/src/src/SourceGenerator/Helpers/PropertyLibrary.cs b/src/src/SourceGenerator/Helpers/PropertyLibrary.cs index 1a7c08f6..c50b8308 100644 --- a/src/src/SourceGenerator/Helpers/PropertyLibrary.cs +++ b/src/src/SourceGenerator/Helpers/PropertyLibrary.cs @@ -12,6 +12,7 @@ static class PropertyLibrary public const string PurviewTelemetryNamespace = TelemetryAttributeNames.PurviewTelemetryNamespace; public const string SystemDiagnosticsNamespace = TelemetryAttributeNames.SystemDiagnosticsNamespace; public const string EmbedAttributesHashDefineName = "PURVIEW_TELEMETRY_ATTRIBUTES"; + public const string DisableTelemetryGenerator = "DisableTelemetryGenerator"; public static readonly Lazy Version = new(() => typeof(PropertyLibrary).Assembly.GetName().Version); @@ -65,23 +66,28 @@ public static class Activities public const string Tag_ExceptionStackTrace = "exception.stacktrace"; public const string RecordExceptionMethodName = "RecordExceptionInternal"; - public static readonly string ActivityKind_Internal = - TypeLibrary.Activities.SystemDiagnostics.ActivityKind.StaticMember("Internal"); - public static readonly string ActivityKind_Server = - TypeLibrary.Activities.SystemDiagnostics.ActivityKind.StaticMember("Server"); - public static readonly string ActivityKind_Client = - TypeLibrary.Activities.SystemDiagnostics.ActivityKind.StaticMember("Client"); - public static readonly string ActivityKind_Producer = - TypeLibrary.Activities.SystemDiagnostics.ActivityKind.StaticMember("Producer"); - public static readonly string ActivityKind_Consumer = - TypeLibrary.Activities.SystemDiagnostics.ActivityKind.StaticMember("Consumer"); + public static readonly string ActivityKind_Internal = TypeLibrary.System.Diagnostics.ActivityKind.StaticMember( + "Internal" + ); + public static readonly string ActivityKind_Server = TypeLibrary.System.Diagnostics.ActivityKind.StaticMember( + "Server" + ); + public static readonly string ActivityKind_Client = TypeLibrary.System.Diagnostics.ActivityKind.StaticMember( + "Client" + ); + public static readonly string ActivityKind_Producer = TypeLibrary.System.Diagnostics.ActivityKind.StaticMember( + "Producer" + ); + public static readonly string ActivityKind_Consumer = TypeLibrary.System.Diagnostics.ActivityKind.StaticMember( + "Consumer" + ); public static readonly string ActivityStatusCode_Unset = - TypeLibrary.Activities.SystemDiagnostics.ActivityStatusCode.StaticMember("Unset"); + TypeLibrary.System.Diagnostics.ActivityStatusCode.StaticMember("Unset"); public static readonly string ActivityStatusCode_Ok = - TypeLibrary.Activities.SystemDiagnostics.ActivityStatusCode.StaticMember("Ok"); + TypeLibrary.System.Diagnostics.ActivityStatusCode.StaticMember("Ok"); public static readonly string ActivityStatusCode_Error = - TypeLibrary.Activities.SystemDiagnostics.ActivityStatusCode.StaticMember("Error"); + TypeLibrary.System.Diagnostics.ActivityStatusCode.StaticMember("Error"); public static readonly ImmutableDictionary ActivityKindTypeMap = new Dictionary { @@ -112,24 +118,23 @@ public static class Logging public static string ILoggerOfTMetadataName => TelemetryAttributeNames.Logging.ILoggerOfT.MetadataFullName; - public static readonly string LogLevel_Trace = TypeLibrary.Logging.MicrosoftExtensions.LogLevel.StaticMember( + public static readonly string LogLevel_Trace = TypeLibrary.Microsoft.Extensions.Logging.LogLevel.StaticMember( "Trace" ); - public static readonly string LogLevel_Debug = TypeLibrary.Logging.MicrosoftExtensions.LogLevel.StaticMember( + public static readonly string LogLevel_Debug = TypeLibrary.Microsoft.Extensions.Logging.LogLevel.StaticMember( "Debug" ); public static readonly string LogLevel_Information = - TypeLibrary.Logging.MicrosoftExtensions.LogLevel.StaticMember("Information"); - public static readonly string LogLevel_Warning = TypeLibrary.Logging.MicrosoftExtensions.LogLevel.StaticMember( + TypeLibrary.Microsoft.Extensions.Logging.LogLevel.StaticMember("Information"); + public static readonly string LogLevel_Warning = TypeLibrary.Microsoft.Extensions.Logging.LogLevel.StaticMember( "Warning" ); - public static readonly string LogLevel_Error = TypeLibrary.Logging.MicrosoftExtensions.LogLevel.StaticMember( + public static readonly string LogLevel_Error = TypeLibrary.Microsoft.Extensions.Logging.LogLevel.StaticMember( "Error" ); - public static readonly string LogLevel_Critical = TypeLibrary.Logging.MicrosoftExtensions.LogLevel.StaticMember( - "Critical" - ); - public static readonly string LogLevel_None = TypeLibrary.Logging.MicrosoftExtensions.LogLevel.StaticMember( + public static readonly string LogLevel_Critical = + TypeLibrary.Microsoft.Extensions.Logging.LogLevel.StaticMember("Critical"); + public static readonly string LogLevel_None = TypeLibrary.Microsoft.Extensions.Logging.LogLevel.StaticMember( "None" ); @@ -188,8 +193,7 @@ public static class Metrics public static class DependencyInjection { public const string DependencyInjectionNamespace = "Microsoft.Extensions.DependencyInjection"; - public static readonly string Singleton = TypeLibrary.DependencyInjection.ServiceLifetime.StaticMember( - "Singleton" - ); + public static readonly string Singleton = + TypeLibrary.Microsoft.Extensions.DependencyInjection.ServiceLifetime.StaticMember("Singleton"); } } diff --git a/src/src/SourceGenerator/Helpers/SharedHelpers.Activities.cs b/src/src/SourceGenerator/Helpers/SharedHelpers.Activities.cs index 41c3f1a5..65fad1e2 100644 --- a/src/src/SourceGenerator/Helpers/SharedHelpers.Activities.cs +++ b/src/src/SourceGenerator/Helpers/SharedHelpers.Activities.cs @@ -15,7 +15,7 @@ CancellationToken token if ( !Utilities.TryContainsAttribute( symbol, - TypeLibrary.Activities.ActivitySourceAttribute, + TypeLibrary.Purview.Telemetry.ActivitySourceAttribute, token, out var attributeData ) @@ -42,7 +42,7 @@ CancellationToken token if ( !Utilities.TryContainsAttribute( symbol, - TypeLibrary.Activities.ActivitySourceGenerationAttribute, + TypeLibrary.Purview.Telemetry.ActivitySourceGenerationAttribute, token, out var attributeData ) @@ -67,7 +67,7 @@ out var attributeData if ( !Utilities.TryContainsAttribute( symbol, - TypeLibrary.Activities.ActivityAttribute, + TypeLibrary.Purview.Telemetry.ActivityAttribute, token, out var attributeData ) @@ -83,7 +83,12 @@ out var attributeData public static EventAttributeData? GetActivityEventAttribute(ISymbol symbol, CancellationToken token) { if ( - !Utilities.TryContainsAttribute(symbol, TypeLibrary.Activities.EventAttribute, token, out var attributeData) + !Utilities.TryContainsAttribute( + symbol, + TypeLibrary.Purview.Telemetry.EventAttribute, + token, + out var attributeData + ) ) { return null; @@ -101,8 +106,8 @@ out var attributeData public static bool IsActivityMethod(IMethodSymbol method, CancellationToken token) { - return Utilities.ContainsAttribute(method, TypeLibrary.Activities.ActivityAttribute, token) - || Utilities.ContainsAttribute(method, TypeLibrary.Activities.EventAttribute, token) - || Utilities.ContainsAttribute(method, TypeLibrary.Activities.ContextAttribute, token); + return Utilities.ContainsAttribute(method, TypeLibrary.Purview.Telemetry.ActivityAttribute, token) + || Utilities.ContainsAttribute(method, TypeLibrary.Purview.Telemetry.EventAttribute, token) + || Utilities.ContainsAttribute(method, TypeLibrary.Purview.Telemetry.ContextAttribute, token); } } diff --git a/src/src/SourceGenerator/Helpers/SharedHelpers.Logging.cs b/src/src/SourceGenerator/Helpers/SharedHelpers.Logging.cs index c59d4a03..ba8f89c0 100644 --- a/src/src/SourceGenerator/Helpers/SharedHelpers.Logging.cs +++ b/src/src/SourceGenerator/Helpers/SharedHelpers.Logging.cs @@ -10,7 +10,7 @@ partial class SharedHelpers if ( !Utilities.TryContainsAttribute( symbol, - TypeLibrary.Logging.LogAttributeTargets, + TypeLibrary.Purview.Telemetry.LogAttributeTargets, token, out var matchingType, out var attributeData @@ -20,7 +20,7 @@ out var attributeData return null; } - if (matchingType == TypeLibrary.Logging.LogAttribute) + if (matchingType == TypeLibrary.Purview.Telemetry.LogAttribute) { var data = LogAttributeData.FromAttributeData(attributeData!); return data.Exists @@ -37,31 +37,31 @@ out var attributeData static LogAttributeData GetSpecificLogData(TypeIdentity template, AttributeData attributeData) { - if (template == TypeLibrary.Logging.TraceAttribute) + if (template == TypeLibrary.Purview.Telemetry.TraceAttribute) { var data = TraceAttributeData.FromAttributeData(attributeData); return data.ToLogAttribute(); } - if (template == TypeLibrary.Logging.DebugAttribute) + if (template == TypeLibrary.Purview.Telemetry.DebugAttribute) { var data = DebugAttributeData.FromAttributeData(attributeData); return data.ToLogAttribute(); } - if (template == TypeLibrary.Logging.InfoAttribute) + if (template == TypeLibrary.Purview.Telemetry.InfoAttribute) { var data = InfoAttributeData.FromAttributeData(attributeData); return data.ToLogAttribute(); } - if (template == TypeLibrary.Logging.WarningAttribute) + if (template == TypeLibrary.Purview.Telemetry.WarningAttribute) { var data = WarningAttributeData.FromAttributeData(attributeData); return data.ToLogAttribute(); } - if (template == TypeLibrary.Logging.ErrorAttribute) + if (template == TypeLibrary.Purview.Telemetry.ErrorAttribute) { var data = ErrorAttributeData.FromAttributeData(attributeData); return data.ToLogAttribute(); @@ -73,7 +73,14 @@ static LogAttributeData GetSpecificLogData(TypeIdentity template, AttributeData public static LoggerAttributeData? GetLoggerAttribute(ISymbol symbol, CancellationToken token) { - if (!Utilities.TryContainsAttribute(symbol, TypeLibrary.Logging.LoggerAttribute, token, out var attributeData)) + if ( + !Utilities.TryContainsAttribute( + symbol, + TypeLibrary.Purview.Telemetry.LoggerAttribute, + token, + out var attributeData + ) + ) { return null; } @@ -87,7 +94,7 @@ static LogAttributeData GetSpecificLogData(TypeIdentity template, AttributeData if ( !Utilities.TryContainsAttribute( symbol, - TypeLibrary.Logging.LoggerGenerationAttribute, + TypeLibrary.Purview.Telemetry.LoggerGenerationAttribute, token, out var attributeData ) @@ -105,7 +112,7 @@ out var attributeData if ( !Utilities.TryContainsAttribute( symbol, - TypeLibrary.Logging.MicrosoftExtensions.LogPropertiesAttribute, + TypeLibrary.Microsoft.Extensions.Logging.LogPropertiesAttribute, token, out var attributeData ) @@ -123,7 +130,7 @@ out var attributeData if ( !Utilities.TryContainsAttribute( symbol, - TypeLibrary.Logging.ExpandEnumerableAttribute, + TypeLibrary.Purview.Telemetry.ExpandEnumerableAttribute, token, out var attributeData ) diff --git a/src/src/SourceGenerator/Helpers/SharedHelpers.Metrics.cs b/src/src/SourceGenerator/Helpers/SharedHelpers.Metrics.cs index 3338f0b5..c129e751 100644 --- a/src/src/SourceGenerator/Helpers/SharedHelpers.Metrics.cs +++ b/src/src/SourceGenerator/Helpers/SharedHelpers.Metrics.cs @@ -12,7 +12,14 @@ CancellationToken token public static MeterAttributeData? GetMeterAttribute(ISymbol symbol, CancellationToken token) { - if (!Utilities.TryContainsAttribute(symbol, TypeLibrary.Metrics.MeterAttribute, token, out var attributeData)) + if ( + !Utilities.TryContainsAttribute( + symbol, + TypeLibrary.Purview.Telemetry.MeterAttribute, + token, + out var attributeData + ) + ) { return null; } @@ -32,7 +39,7 @@ CancellationToken token if ( !Utilities.TryContainsAttribute( symbol, - TypeLibrary.Metrics.MeterGenerationAttribute, + TypeLibrary.Purview.Telemetry.MeterGenerationAttribute, token, out var attributeData ) diff --git a/src/src/SourceGenerator/Helpers/SharedHelpers.cs b/src/src/SourceGenerator/Helpers/SharedHelpers.cs index 8a36be12..e44b293e 100644 --- a/src/src/SourceGenerator/Helpers/SharedHelpers.cs +++ b/src/src/SourceGenerator/Helpers/SharedHelpers.cs @@ -11,13 +11,13 @@ public static GenerationType GetGenerationTypes(ISymbol symbol, CancellationToke var generationType = GenerationType.None; - if (Utilities.ContainsAttribute(symbol, TypeLibrary.Activities.ActivitySourceAttribute, token)) + if (Utilities.ContainsAttribute(symbol, TypeLibrary.Purview.Telemetry.ActivitySourceAttribute, token)) generationType |= GenerationType.Activities; - if (Utilities.ContainsAttribute(symbol, TypeLibrary.Logging.LoggerAttribute, token)) + if (Utilities.ContainsAttribute(symbol, TypeLibrary.Purview.Telemetry.LoggerAttribute, token)) generationType |= GenerationType.Logging; - if (Utilities.ContainsAttribute(symbol, TypeLibrary.Metrics.MeterAttribute, token)) + if (Utilities.ContainsAttribute(symbol, TypeLibrary.Purview.Telemetry.MeterAttribute, token)) generationType |= GenerationType.Metrics; return generationType; @@ -154,7 +154,7 @@ CancellationToken token if ( !Utilities.TryContainsAttribute( parameter, - TypeLibrary.TelemetryShared.ExcludeTargetsAttribute, + TypeLibrary.Purview.Telemetry.ExcludeTargetsAttribute, token, out var attributeData ) diff --git a/src/src/SourceGenerator/Helpers/TypeLibrary.cs b/src/src/SourceGenerator/Helpers/TypeLibrary.cs deleted file mode 100644 index 4124f34e..00000000 --- a/src/src/SourceGenerator/Helpers/TypeLibrary.cs +++ /dev/null @@ -1,341 +0,0 @@ -using System.Collections.Concurrent; -using System.Collections.Immutable; -using Purview.Telemetry.SourceGenerator.Records; - -namespace Purview.Telemetry.SourceGenerator.Helpers; - -/// -/// Registry of the type identities and references used during generation. -/// -static class TypeLibrary -{ - public const string PurviewTelemetryNamespace = "Purview.Telemetry"; - - public static class System - { - public static readonly TypeIdentity Exception = TypeIdentity.Create(); - public static readonly TypeIdentity IDisposable = TypeIdentity.Create(); - public static readonly TypeIdentity DateTimeOffset = TypeIdentity.Create(); - public static readonly TypeIdentity IEnumerable = TypeIdentity.Create(); - public static readonly TypeIdentity GenericIEnumerable = new(typeof(IEnumerable<>)); - public static readonly TypeIdentity List = new(typeof(List<>)); - public static readonly TypeIdentity Dictionary = new(typeof(Dictionary<,>)); - public static readonly TypeIdentity ConcurrentDictionary = new(typeof(ConcurrentDictionary<,>)); - public static readonly TypeIdentity TagList = new(nameof(TagList), "System.Diagnostics"); - } - - public static class Activities - { - public static class SystemDiagnostics - { - public const string DiagnosticsNamespace = "System.Diagnostics"; - - public static readonly TypeIdentity Activity = new(nameof(Activity), DiagnosticsNamespace); - public static readonly TypeIdentity ActivitySource = new(nameof(ActivitySource), DiagnosticsNamespace); - public static readonly TypeIdentity ActivityEvent = new(nameof(ActivityEvent), DiagnosticsNamespace); - public static readonly TypeIdentity ActivityContext = new(nameof(ActivityContext), DiagnosticsNamespace); - public static readonly TypeIdentity ActivityKind = new(nameof(ActivityKind), DiagnosticsNamespace); - public static readonly TypeIdentity ActivityStatusCode = new( - nameof(ActivityStatusCode), - DiagnosticsNamespace - ); - public static readonly TypeIdentity ActivityTagsCollection = new( - nameof(ActivityTagsCollection), - DiagnosticsNamespace - ); - public static readonly TypeIdentity ActivityLink = new(nameof(ActivityLink), DiagnosticsNamespace); - - public static readonly TypeReference ActivityTagIEnumerable = System.GenericIEnumerable.MakeGeneric( - new TypeReference( - new TypeIdentity("KeyValuePair", "System.Collections.Generic").MakeGeneric( - PurviewTypeLibrary.System.String.AsTypeReference(), - PurviewTypeLibrary.System.Object.AsTypeReference() - ) - ) - ); - - public static readonly TypeReference ActivityLinkIEnumerable = System.GenericIEnumerable.MakeGeneric( - ActivityLink.AsTypeReference() - ); - - public static readonly TypeReference ActivityLinkArray = new TypeReference(ActivityLink).MakeArray(); - } - - public static readonly TypeIdentity ActivitySourceGenerationAttribute = new( - nameof(ActivitySourceGenerationAttribute), - PurviewTelemetryNamespace - ); - public static readonly TypeIdentity ActivitySourceAttribute = new( - nameof(ActivitySourceAttribute), - PurviewTelemetryNamespace - ); - public static readonly TypeIdentity ActivityAttribute = new( - nameof(ActivityAttribute), - PurviewTelemetryNamespace - ); - public static readonly TypeIdentity EventAttribute = new(nameof(EventAttribute), PurviewTelemetryNamespace); - public static readonly TypeIdentity ContextAttribute = new(nameof(ContextAttribute), PurviewTelemetryNamespace); - public static readonly TypeIdentity BaggageAttribute = new(nameof(BaggageAttribute), PurviewTelemetryNamespace); - public static readonly TypeIdentity EscapeAttribute = new(nameof(EscapeAttribute), PurviewTelemetryNamespace); - public static readonly TypeIdentity StatusDescriptionAttribute = new( - nameof(StatusDescriptionAttribute), - PurviewTelemetryNamespace - ); - - public static ImmutableArray GetGeneratedTypes() => - [ - ActivitySourceGenerationAttribute, - ActivitySourceAttribute, - ActivityAttribute, - EventAttribute, - ContextAttribute, - BaggageAttribute, - EscapeAttribute, - StatusDescriptionAttribute, - ]; - } - - public static class Logging - { - public static class MicrosoftExtensions - { - public const string LoggingNamespace = "Microsoft.Extensions.Logging"; - - public static readonly TypeIdentity ILogger = new(nameof(ILogger), LoggingNamespace); - public static readonly TypeIdentity LoggerMessage = new(nameof(LoggerMessage), LoggingNamespace); - public static readonly TypeIdentity LogLevel = new(nameof(LogLevel), LoggingNamespace); - public static readonly TypeIdentity EventId = new(nameof(EventId), LoggingNamespace); - public static readonly TypeIdentity LoggerMessageHelper = new( - nameof(LoggerMessageHelper), - LoggingNamespace - ); - public static readonly TypeIdentity LogPropertiesAttribute = new( - nameof(LogPropertiesAttribute), - LoggingNamespace - ); - public static readonly TypeIdentity LogPropertyIgnoreAttribute = new( - nameof(LogPropertyIgnoreAttribute), - LoggingNamespace - ); - } - - public static readonly TypeIdentity LoggerGenerationAttribute = new( - nameof(LoggerGenerationAttribute), - PurviewTelemetryNamespace - ); - public static readonly TypeIdentity LoggerAttribute = new(nameof(LoggerAttribute), PurviewTelemetryNamespace); - public static readonly TypeIdentity LogAttribute = new(nameof(LogAttribute), PurviewTelemetryNamespace); - public static readonly TypeIdentity LogPrefixType = new(nameof(LogPrefixType), PurviewTelemetryNamespace); - public static readonly TypeIdentity LoggerGenerationMode = new( - nameof(LoggerGenerationMode), - PurviewTelemetryNamespace - ); - public static readonly TypeIdentity ExpandEnumerableAttribute = new( - nameof(ExpandEnumerableAttribute), - PurviewTelemetryNamespace - ); - public static readonly TypeIdentity TraceAttribute = new(nameof(TraceAttribute), PurviewTelemetryNamespace); - public static readonly TypeIdentity DebugAttribute = new(nameof(DebugAttribute), PurviewTelemetryNamespace); - public static readonly TypeIdentity InfoAttribute = new(nameof(InfoAttribute), PurviewTelemetryNamespace); - public static readonly TypeIdentity WarningAttribute = new(nameof(WarningAttribute), PurviewTelemetryNamespace); - public static readonly TypeIdentity ErrorAttribute = new(nameof(ErrorAttribute), PurviewTelemetryNamespace); - public static readonly TypeIdentity CriticalAttribute = new( - nameof(CriticalAttribute), - PurviewTelemetryNamespace - ); - - public static readonly ImmutableArray LogAttributeTargets = - [ - LogAttribute, - TraceAttribute, - DebugAttribute, - InfoAttribute, - WarningAttribute, - ErrorAttribute, - CriticalAttribute, - ]; - - public static ImmutableArray GetGeneratedTypes() => - [ - LoggerGenerationAttribute, - LoggerAttribute, - LogAttribute, - LogPrefixType, - LoggerGenerationMode, - ExpandEnumerableAttribute, - TraceAttribute, - DebugAttribute, - InfoAttribute, - WarningAttribute, - ErrorAttribute, - CriticalAttribute, - ]; - - public static ImmutableDictionary LogLevelMap = new Dictionary< - TypeIdentity, - LogLevelDetails - > - { - { TraceAttribute, new(TraceAttribute, 0, "Trace") }, - { DebugAttribute, new(DebugAttribute, 1, "Debug") }, - { InfoAttribute, new(InfoAttribute, 2, "Info") }, - { WarningAttribute, new(WarningAttribute, 3, "Warning") }, - { ErrorAttribute, new(ErrorAttribute, 4, "Error") }, - { CriticalAttribute, new(CriticalAttribute, 5, "Critical") }, - }.ToImmutableDictionary(); - } - - public static class Metrics - { - public static class SystemDiagnostics - { - public const string SystemDiagnosticsMetricsNamespace = "System.Diagnostics.Metrics"; - - public static readonly TypeIdentity Meter = new(nameof(Meter), SystemDiagnosticsMetricsNamespace); - public static readonly TypeIdentity IMeterFactory = new( - nameof(IMeterFactory), - SystemDiagnosticsMetricsNamespace - ); - public static readonly TypeIdentity MeterOptions = new( - nameof(MeterOptions), - SystemDiagnosticsMetricsNamespace - ); - public static readonly TypeIdentity Measurement = new( - nameof(Measurement), - SystemDiagnosticsMetricsNamespace - ) - { - GenericArity = 1, - }; - public static readonly TypeIdentity Counter = new(nameof(Counter), SystemDiagnosticsMetricsNamespace); - public static readonly TypeIdentity UpDownCounter = new( - nameof(UpDownCounter), - SystemDiagnosticsMetricsNamespace - ); - public static readonly TypeIdentity Histogram = new(nameof(Histogram), SystemDiagnosticsMetricsNamespace); - public static readonly TypeIdentity ObservableCounter = new( - nameof(ObservableCounter), - SystemDiagnosticsMetricsNamespace - ); - public static readonly TypeIdentity ObservableGauge = new( - nameof(ObservableGauge), - SystemDiagnosticsMetricsNamespace - ); - public static readonly TypeIdentity ObservableUpDownCounter = new( - nameof(ObservableUpDownCounter), - SystemDiagnosticsMetricsNamespace - ); - } - - public static readonly TypeIdentity MeterGenerationAttribute = new( - nameof(MeterGenerationAttribute), - PurviewTelemetryNamespace - ); - public static readonly TypeIdentity MeterAttribute = new(nameof(MeterAttribute), PurviewTelemetryNamespace); - public static readonly TypeIdentity MeterNameGenerationType = new( - nameof(MeterNameGenerationType), - PurviewTelemetryNamespace - ); - public static readonly TypeIdentity InstrumentMeasurementAttribute = new( - nameof(InstrumentMeasurementAttribute), - PurviewTelemetryNamespace - ); - public static readonly TypeIdentity AutoCounterAttribute = new( - nameof(AutoCounterAttribute), - PurviewTelemetryNamespace - ); - public static readonly TypeIdentity CounterAttribute = new(nameof(CounterAttribute), PurviewTelemetryNamespace); - public static readonly TypeIdentity UpDownCounterAttribute = new( - nameof(UpDownCounterAttribute), - PurviewTelemetryNamespace - ); - public static readonly TypeIdentity HistogramAttribute = new( - nameof(HistogramAttribute), - PurviewTelemetryNamespace - ); - public static readonly TypeIdentity ObservableCounterAttribute = new( - nameof(ObservableCounterAttribute), - PurviewTelemetryNamespace - ); - public static readonly TypeIdentity ObservableUpDownCounterAttribute = new( - nameof(ObservableUpDownCounterAttribute), - PurviewTelemetryNamespace - ); - public static readonly TypeIdentity ObservableGaugeAttribute = new( - nameof(ObservableGaugeAttribute), - PurviewTelemetryNamespace - ); - - public static readonly ImmutableDictionary InstrumentTypeMap = new Dictionary< - InstrumentTypes, - TypeIdentity - > - { - { InstrumentTypes.Counter, SystemDiagnostics.Counter }, - { InstrumentTypes.UpDownCounter, SystemDiagnostics.UpDownCounter }, - { InstrumentTypes.Histogram, SystemDiagnostics.Histogram }, - { InstrumentTypes.ObservableCounter, SystemDiagnostics.ObservableCounter }, - { InstrumentTypes.ObservableGauge, SystemDiagnostics.ObservableGauge }, - { InstrumentTypes.ObservableUpDownCounter, SystemDiagnostics.ObservableUpDownCounter }, - }.ToImmutableDictionary(); - - public static ImmutableArray GetGeneratedTypes() => - [ - MeterGenerationAttribute, - MeterAttribute, - MeterNameGenerationType, - InstrumentMeasurementAttribute, - AutoCounterAttribute, - CounterAttribute, - UpDownCounterAttribute, - HistogramAttribute, - ObservableCounterAttribute, - ObservableUpDownCounterAttribute, - ObservableGaugeAttribute, - ]; - } - - public static class DependencyInjection - { - public const string DependencyInjectionNamespace = "Microsoft.Extensions.DependencyInjection"; - - public static readonly TypeIdentity IServiceCollection = new( - nameof(IServiceCollection), - DependencyInjectionNamespace - ); - public static readonly TypeIdentity ServiceDescriptor = new( - nameof(ServiceDescriptor), - DependencyInjectionNamespace - ); - public static readonly TypeIdentity ServiceLifetime = new( - nameof(ServiceLifetime), - DependencyInjectionNamespace - ); - } - - public static class TelemetryShared - { - public static readonly TypeIdentity TagAttribute = new(nameof(TagAttribute), PurviewTelemetryNamespace); - public static readonly TypeIdentity ExcludeAttribute = new(nameof(ExcludeAttribute), PurviewTelemetryNamespace); - public static readonly TypeIdentity TelemetryGenerationAttribute = new( - nameof(TelemetryGenerationAttribute), - PurviewTelemetryNamespace - ); - public static readonly TypeIdentity Targets = new(nameof(Targets), PurviewTelemetryNamespace); - public static readonly TypeIdentity NamingConvention = new(nameof(NamingConvention), PurviewTelemetryNamespace); - public static readonly TypeIdentity ExcludeTargetsAttribute = new( - nameof(ExcludeTargetsAttribute), - PurviewTelemetryNamespace - ); - - public static ImmutableArray GetGeneratedTypes() => - [ - TagAttribute, - ExcludeAttribute, - TelemetryGenerationAttribute, - Targets, - NamingConvention, - ExcludeTargetsAttribute, - ]; - } -} diff --git a/src/src/SourceGenerator/Helpers/TypeLibraryGenerator.Activities.cs b/src/src/SourceGenerator/Helpers/TypeLibraryGenerator.Activities.cs new file mode 100644 index 00000000..91138ceb --- /dev/null +++ b/src/src/SourceGenerator/Helpers/TypeLibraryGenerator.Activities.cs @@ -0,0 +1,47 @@ +namespace Purview.Telemetry.SourceGenerator.Helpers; + +partial class TypeLibraryGenerator +{ + [TypeRef(SystemDiagnosticsNamespace)] + static readonly TypeIdentity TagList = default; + + [TypeRef(SystemDiagnosticsNamespace)] + static readonly TypeIdentity Activity = default; + + [TypeRef(SystemDiagnosticsNamespace)] + static readonly TypeIdentity ActivitySource = default; + + [TypeRef(SystemDiagnosticsNamespace)] + static readonly TypeIdentity ActivityEvent = default; + + [TypeRef(SystemDiagnosticsNamespace)] + static readonly TypeIdentity ActivityContext = default; + + [TypeRef(SystemDiagnosticsNamespace)] + static readonly TypeIdentity ActivityKind = default; + + [TypeRef(SystemDiagnosticsNamespace)] + static readonly TypeIdentity ActivityStatusCode = default; + + [TypeRef(SystemDiagnosticsNamespace)] + static readonly TypeIdentity ActivityTagsCollection = default; + + [TypeRef(SystemDiagnosticsNamespace)] + static readonly TypeIdentity ActivityLink = default; + + [TypeRef(SystemDiagnosticsNamespace)] + internal static readonly TypeReference ActivityTagIEnumerable = + TypeLibrary.System.Collections.Generic.IEnumerable.MakeGeneric( + TypeLibrary.System.Collections.Generic.KeyValuePair.MakeGeneric( + TypeLibrary.System.String, + TypeLibrary.System.Object + ) + ); + + [TypeRef(SystemDiagnosticsNamespace)] + internal static readonly TypeReference ActivityLinkIEnumerable = + TypeLibrary.System.Collections.Generic.IEnumerable.MakeGeneric(ActivityLink); + + [TypeRef(SystemDiagnosticsNamespace)] + internal static readonly TypeReference ActivityLinkArray = new TypeReference(ActivityLink).MakeArray(); +} diff --git a/src/src/SourceGenerator/Helpers/TypeLibraryGenerator.Logging.cs b/src/src/SourceGenerator/Helpers/TypeLibraryGenerator.Logging.cs new file mode 100644 index 00000000..0f4606a8 --- /dev/null +++ b/src/src/SourceGenerator/Helpers/TypeLibraryGenerator.Logging.cs @@ -0,0 +1,25 @@ +namespace Purview.Telemetry.SourceGenerator.Helpers; + +partial class TypeLibraryGenerator +{ + [TypeRef(LoggingNamespace)] + static readonly TypeIdentity ILogger = default; + + [TypeRef(LoggingNamespace)] + static readonly TypeIdentity LoggerMessage = default; + + [TypeRef(LoggingNamespace)] + static readonly TypeIdentity LogLevel = default; + + [TypeRef(LoggingNamespace)] + static readonly TypeIdentity EventId = default; + + [TypeRef(LoggingNamespace)] + static readonly TypeIdentity LoggerMessageHelper = default; + + [TypeRef(LoggingNamespace)] + static readonly TypeIdentity LogPropertiesAttribute = default; + + [TypeRef(LoggingNamespace)] + static readonly TypeIdentity LogPropertyIgnoreAttribute = default; +} diff --git a/src/src/SourceGenerator/Helpers/TypeLibraryGenerator.Metrics.cs b/src/src/SourceGenerator/Helpers/TypeLibraryGenerator.Metrics.cs new file mode 100644 index 00000000..c0ef500b --- /dev/null +++ b/src/src/SourceGenerator/Helpers/TypeLibraryGenerator.Metrics.cs @@ -0,0 +1,34 @@ +namespace Purview.Telemetry.SourceGenerator.Helpers; + +partial class TypeLibraryGenerator +{ + [TypeRef(SystemDiagnosticsMetricsNamespace)] + static readonly TypeIdentity Meter = default; + + [TypeRef(SystemDiagnosticsMetricsNamespace)] + static readonly TypeIdentity IMeterFactory = default; + + [TypeRef(SystemDiagnosticsMetricsNamespace)] + static readonly TypeIdentity MeterOptions = default; + + [TypeRef(SystemDiagnosticsMetricsNamespace, 1)] + static readonly TypeIdentity Measurement = default; + + [TypeRef(SystemDiagnosticsMetricsNamespace)] + static readonly TypeIdentity Counter = default; + + [TypeRef(SystemDiagnosticsMetricsNamespace)] + static readonly TypeIdentity UpDownCounter = default; + + [TypeRef(SystemDiagnosticsMetricsNamespace)] + static readonly TypeIdentity Histogram = default; + + [TypeRef(SystemDiagnosticsMetricsNamespace)] + static readonly TypeIdentity ObservableCounter = default; + + [TypeRef(SystemDiagnosticsMetricsNamespace)] + static readonly TypeIdentity ObservableGauge = default; + + [TypeRef(SystemDiagnosticsMetricsNamespace)] + static readonly TypeIdentity ObservableUpDownCounter = default; +} diff --git a/src/src/SourceGenerator/Helpers/TypeLibraryGenerator.cs b/src/src/SourceGenerator/Helpers/TypeLibraryGenerator.cs new file mode 100644 index 00000000..c828e994 --- /dev/null +++ b/src/src/SourceGenerator/Helpers/TypeLibraryGenerator.cs @@ -0,0 +1,126 @@ +namespace Purview.Telemetry.SourceGenerator.Helpers; + +[GenerateTypeLibrary] +static partial class TypeLibraryGenerator +{ + const string PurviewTelemetryNamespace = "Purview.Telemetry"; + const string LoggingNamespace = "Microsoft.Extensions.Logging"; + const string SystemDiagnosticsNamespace = "System.Diagnostics"; + const string SystemDiagnosticsMetricsNamespace = "System.Diagnostics.Metrics"; + + // Purview Telemetry types + // Activities + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity ActivitySourceGenerationAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity ActivitySourceAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity ActivityAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity EventAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity ContextAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity BaggageAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity EscapeAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity StatusDescriptionAttribute = default; + + // Logging + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity LoggerGenerationAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity LoggerAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity LogAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity LogPrefixType = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity LoggerGenerationMode = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity ExpandEnumerableAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity TraceAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity DebugAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity InfoAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity WarningAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity ErrorAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity CriticalAttribute = default; + + // Metric + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity MeterGenerationAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity MeterAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity MeterNameGenerationType = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity InstrumentMeasurementAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity AutoCounterAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity CounterAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity UpDownCounterAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity HistogramAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity ObservableCounterAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity ObservableUpDownCounterAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity ObservableGaugeAttribute = default; + + // Shared + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity TagAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity ExcludeAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity TelemetryGenerationAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity Targets = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity NamingConvention = default; + + [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] + static readonly TypeIdentity ExcludeTargetsAttribute = default; +} diff --git a/src/src/SourceGenerator/Helpers/Utilities.cs b/src/src/SourceGenerator/Helpers/Utilities.cs index d0a6c234..53b1f389 100644 --- a/src/src/SourceGenerator/Helpers/Utilities.cs +++ b/src/src/SourceGenerator/Helpers/Utilities.cs @@ -93,27 +93,27 @@ GenerationType requestedType } static bool IsActivityAttribute(TypeReference attributeType) => - TypeLibrary.Activities.ActivityAttribute == attributeType - || TypeLibrary.Activities.EventAttribute == attributeType - || TypeLibrary.Activities.ContextAttribute == attributeType; + TypeLibrary.Purview.Telemetry.ActivityAttribute == attributeType + || TypeLibrary.Purview.Telemetry.EventAttribute == attributeType + || TypeLibrary.Purview.Telemetry.ContextAttribute == attributeType; static bool IsLoggingAttribute(TypeReference attributeType) => - TypeLibrary.Logging.LogAttribute == attributeType - || TypeLibrary.Logging.TraceAttribute == attributeType - || TypeLibrary.Logging.DebugAttribute == attributeType - || TypeLibrary.Logging.InfoAttribute == attributeType - || TypeLibrary.Logging.WarningAttribute == attributeType - || TypeLibrary.Logging.ErrorAttribute == attributeType - || TypeLibrary.Logging.CriticalAttribute == attributeType; + TypeLibrary.Purview.Telemetry.LogAttribute == attributeType + || TypeLibrary.Purview.Telemetry.TraceAttribute == attributeType + || TypeLibrary.Purview.Telemetry.DebugAttribute == attributeType + || TypeLibrary.Purview.Telemetry.InfoAttribute == attributeType + || TypeLibrary.Purview.Telemetry.WarningAttribute == attributeType + || TypeLibrary.Purview.Telemetry.ErrorAttribute == attributeType + || TypeLibrary.Purview.Telemetry.CriticalAttribute == attributeType; static bool IsMetricsAttribute(TypeReference attributeType) => - TypeLibrary.Metrics.CounterAttribute == attributeType - || TypeLibrary.Metrics.AutoCounterAttribute == attributeType - || TypeLibrary.Metrics.UpDownCounterAttribute == attributeType - || TypeLibrary.Metrics.HistogramAttribute == attributeType - || TypeLibrary.Metrics.ObservableCounterAttribute == attributeType - || TypeLibrary.Metrics.ObservableGaugeAttribute == attributeType - || TypeLibrary.Metrics.ObservableUpDownCounterAttribute == attributeType; + TypeLibrary.Purview.Telemetry.CounterAttribute == attributeType + || TypeLibrary.Purview.Telemetry.AutoCounterAttribute == attributeType + || TypeLibrary.Purview.Telemetry.UpDownCounterAttribute == attributeType + || TypeLibrary.Purview.Telemetry.HistogramAttribute == attributeType + || TypeLibrary.Purview.Telemetry.ObservableCounterAttribute == attributeType + || TypeLibrary.Purview.Telemetry.ObservableGaugeAttribute == attributeType + || TypeLibrary.Purview.Telemetry.ObservableUpDownCounterAttribute == attributeType; static int CountFlags(GenerationType type) { @@ -144,7 +144,7 @@ static GenerationType ToGenerationType(bool activities, bool logging, bool metri foreach (var param in method.Parameters) { var paramType = TypeReference.Create(param.Type); - if (paramType.Identity.Equals(TypeLibrary.Activities.SystemDiagnostics.Activity)) + if (paramType.Identity.Equals(TypeLibrary.System.Diagnostics.Activity)) return param.Name; } @@ -274,7 +274,7 @@ public static bool IsIEnumerable(this ITypeSymbol typeSymbol, Compilation compil return true; // Get the `IEnumerable` symbol from the compilation - var ienumerableSymbol = compilation.GetTypeByMetadataName(TypeLibrary.System.IEnumerable); + var ienumerableSymbol = compilation.GetTypeByMetadataName("System.Collections.IEnumerable"); // Check if the type implements `IEnumerable` return ienumerableSymbol != null @@ -475,12 +475,12 @@ public static string GenerateInstrumentPrefixFromInterfaceName(string interfaceN /// public static bool HasMetricsAttribute(IMethodSymbol method, CancellationToken token) { - return ContainsAttribute(method, TypeLibrary.Metrics.CounterAttribute, token) - || ContainsAttribute(method, TypeLibrary.Metrics.AutoCounterAttribute, token) - || ContainsAttribute(method, TypeLibrary.Metrics.UpDownCounterAttribute, token) - || ContainsAttribute(method, TypeLibrary.Metrics.HistogramAttribute, token) - || ContainsAttribute(method, TypeLibrary.Metrics.ObservableCounterAttribute, token) - || ContainsAttribute(method, TypeLibrary.Metrics.ObservableGaugeAttribute, token) - || ContainsAttribute(method, TypeLibrary.Metrics.ObservableUpDownCounterAttribute, token); + return ContainsAttribute(method, TypeLibrary.Purview.Telemetry.CounterAttribute, token) + || ContainsAttribute(method, TypeLibrary.Purview.Telemetry.AutoCounterAttribute, token) + || ContainsAttribute(method, TypeLibrary.Purview.Telemetry.UpDownCounterAttribute, token) + || ContainsAttribute(method, TypeLibrary.Purview.Telemetry.HistogramAttribute, token) + || ContainsAttribute(method, TypeLibrary.Purview.Telemetry.ObservableCounterAttribute, token) + || ContainsAttribute(method, TypeLibrary.Purview.Telemetry.ObservableGaugeAttribute, token) + || ContainsAttribute(method, TypeLibrary.Purview.Telemetry.ObservableUpDownCounterAttribute, token); } } diff --git a/src/src/SourceGenerator/Records/AttributeDataModels.cs b/src/src/SourceGenerator/Records/AttributeDataModels.cs index 774edc6c..aaeb49da 100644 --- a/src/src/SourceGenerator/Records/AttributeDataModels.cs +++ b/src/src/SourceGenerator/Records/AttributeDataModels.cs @@ -112,7 +112,7 @@ readonly partial record struct TraceAttributeData([NestedModel] LogAttributeData public LogAttributeData ToLogAttribute() => Log with { - Level = TypeLibrary.Logging.LogLevelMap[TypeLibrary.Logging.TraceAttribute].Value, + Level = TypeLibrary.Purview.Telemetry.LogLevelMap[TypeLibrary.Purview.Telemetry.TraceAttribute].Value, MessageTemplate = SharedHelpers.NullIfWhitespace(Log.MessageTemplate), Name = SharedHelpers.NullIfWhitespace(Log.Name), }; @@ -124,7 +124,7 @@ readonly partial record struct DebugAttributeData([NestedModel] LogAttributeData public LogAttributeData ToLogAttribute() => Log with { - Level = TypeLibrary.Logging.LogLevelMap[TypeLibrary.Logging.DebugAttribute].Value, + Level = TypeLibrary.Purview.Telemetry.LogLevelMap[TypeLibrary.Purview.Telemetry.DebugAttribute].Value, MessageTemplate = SharedHelpers.NullIfWhitespace(Log.MessageTemplate), Name = SharedHelpers.NullIfWhitespace(Log.Name), }; @@ -136,7 +136,7 @@ readonly partial record struct InfoAttributeData([NestedModel] LogAttributeData public LogAttributeData ToLogAttribute() => Log with { - Level = TypeLibrary.Logging.LogLevelMap[TypeLibrary.Logging.InfoAttribute].Value, + Level = TypeLibrary.Purview.Telemetry.LogLevelMap[TypeLibrary.Purview.Telemetry.InfoAttribute].Value, MessageTemplate = SharedHelpers.NullIfWhitespace(Log.MessageTemplate), Name = SharedHelpers.NullIfWhitespace(Log.Name), }; @@ -148,7 +148,7 @@ readonly partial record struct WarningAttributeData([NestedModel] LogAttributeDa public LogAttributeData ToLogAttribute() => Log with { - Level = TypeLibrary.Logging.LogLevelMap[TypeLibrary.Logging.WarningAttribute].Value, + Level = TypeLibrary.Purview.Telemetry.LogLevelMap[TypeLibrary.Purview.Telemetry.WarningAttribute].Value, MessageTemplate = SharedHelpers.NullIfWhitespace(Log.MessageTemplate), Name = SharedHelpers.NullIfWhitespace(Log.Name), }; @@ -160,7 +160,7 @@ readonly partial record struct ErrorAttributeData([NestedModel] LogAttributeData public LogAttributeData ToLogAttribute() => Log with { - Level = TypeLibrary.Logging.LogLevelMap[TypeLibrary.Logging.ErrorAttribute].Value, + Level = TypeLibrary.Purview.Telemetry.LogLevelMap[TypeLibrary.Purview.Telemetry.ErrorAttribute].Value, }; } @@ -170,7 +170,7 @@ readonly partial record struct CriticalAttributeData([NestedModel] LogAttributeD public LogAttributeData ToLogAttribute() => Log with { - Level = TypeLibrary.Logging.LogLevelMap[TypeLibrary.Logging.CriticalAttribute].Value, + Level = TypeLibrary.Purview.Telemetry.LogLevelMap[TypeLibrary.Purview.Telemetry.CriticalAttribute].Value, MessageTemplate = SharedHelpers.NullIfWhitespace(Log.MessageTemplate), Name = SharedHelpers.NullIfWhitespace(Log.Name), }; diff --git a/src/src/SourceGenerator/Records/TelemetryRules.Activities.cs b/src/src/SourceGenerator/Records/TelemetryRules.Activities.cs index 19905e6c..e44a82bb 100644 --- a/src/src/SourceGenerator/Records/TelemetryRules.Activities.cs +++ b/src/src/SourceGenerator/Records/TelemetryRules.Activities.cs @@ -1,6 +1,5 @@ using System.Collections.Immutable; using Microsoft.CodeAnalysis; -using Purview.Telemetry.SourceGenerator.Helpers; using Purview.Telemetry.SourceGenerator.Records; namespace Purview.Telemetry.SourceGenerator; @@ -72,12 +71,12 @@ CancellationToken token var isValidReturnType = isEvent ? method.ReturnType.Identity.SpecialType == SpecialType.System_Void : method.ReturnType.Identity.SpecialType == SpecialType.System_Void - || method.ReturnType.Identity.Equals(TypeLibrary.Activities.SystemDiagnostics.Activity); + || method.ReturnType.Identity.Equals(TypeLibrary.System.Diagnostics.Activity); // TSG3013/TSG3022: activity methods should return a nullable Activity. if (method.MethodType == ActivityMethodType.Activity && isValidReturnType) { - var returnsActivity = method.ReturnType.Identity.Equals(TypeLibrary.Activities.SystemDiagnostics.Activity); + var returnsActivity = method.ReturnType.Identity.Equals(TypeLibrary.System.Diagnostics.Activity); if (!returnsActivity) diagnostics.Add( DiagnosticInfo.Create(DiagnosticLibrary.Activities.DoesNotReturnActivity.Descriptor, methodSymbol) diff --git a/src/src/SourceGenerator/Records/TelemetryRules.Logging.cs b/src/src/SourceGenerator/Records/TelemetryRules.Logging.cs index 237646ce..d5883b28 100644 --- a/src/src/SourceGenerator/Records/TelemetryRules.Logging.cs +++ b/src/src/SourceGenerator/Records/TelemetryRules.Logging.cs @@ -19,7 +19,7 @@ CancellationToken token { var diagnostics = ImmutableArray.CreateBuilder(); - if (!Utilities.ContainsAttribute(interfaceSymbol, TypeLibrary.Logging.LoggerAttribute, token)) + if (!Utilities.ContainsAttribute(interfaceSymbol, TypeLibrary.Purview.Telemetry.LoggerAttribute, token)) return diagnostics.ToImmutable(); var generationType = SharedHelpers.GetGenerationTypes(interfaceSymbol, token); @@ -32,7 +32,7 @@ CancellationToken token var methods = interfaceSymbol .GetMembers() .OfType() - .Where(m => !TypeHelpers.HasAttribute(m, TypeLibrary.TelemetryShared.ExcludeAttribute) && m.Arity == 0); + .Where(m => !TypeHelpers.HasAttribute(m, TypeLibrary.Purview.Telemetry.ExcludeAttribute) && m.Arity == 0); foreach (var method in methods) { @@ -222,7 +222,7 @@ internal static bool IsInvalidLogReturnType(IMethodSymbol method, CancellationTo } } - var isActivity = TypeLibrary.Activities.SystemDiagnostics.Activity.Equals(returnType); + var isActivity = TypeLibrary.System.Diagnostics.Activity.Equals(returnType); if (isActivity && SharedHelpers.IsActivityMethod(method, token)) return false; diff --git a/src/src/SourceGenerator/Records/TelemetryRules.cs b/src/src/SourceGenerator/Records/TelemetryRules.cs index b6945c3a..cef5f6c4 100644 --- a/src/src/SourceGenerator/Records/TelemetryRules.cs +++ b/src/src/SourceGenerator/Records/TelemetryRules.cs @@ -135,11 +135,19 @@ CancellationToken token var hasActivitySource = Utilities.ContainsAttribute( interfaceSymbol, - TypeLibrary.Activities.ActivitySourceAttribute, + TypeLibrary.Purview.Telemetry.ActivitySourceAttribute, + token + ); + var hasLogger = Utilities.ContainsAttribute( + interfaceSymbol, + TypeLibrary.Purview.Telemetry.LoggerAttribute, + token + ); + var hasMeter = Utilities.ContainsAttribute( + interfaceSymbol, + TypeLibrary.Purview.Telemetry.MeterAttribute, token ); - var hasLogger = Utilities.ContainsAttribute(interfaceSymbol, TypeLibrary.Logging.LoggerAttribute, token); - var hasMeter = Utilities.ContainsAttribute(interfaceSymbol, TypeLibrary.Metrics.MeterAttribute, token); if (!hasActivitySource && !hasLogger && !hasMeter) return diagnostics.ToImmutable(); @@ -148,7 +156,7 @@ CancellationToken token if (hasLogger) { var iLoggerSymbol = compilation.GetTypeByMetadataName( - TypeLibrary.Logging.MicrosoftExtensions.ILogger.MetadataFullName + TypeLibrary.Microsoft.Extensions.Logging.ILogger.MetadataFullName ); if (iLoggerSymbol is null) diagnostics.Add( @@ -212,7 +220,7 @@ static void ApplyPerMethodRules( CancellationToken token ) { - if (TypeHelpers.HasAttribute(method, TypeLibrary.TelemetryShared.ExcludeAttribute)) + if (TypeHelpers.HasAttribute(method, TypeLibrary.Purview.Telemetry.ExcludeAttribute)) return; // TSG1005: generic method. diff --git a/src/src/SourceGenerator/SourceGenerator.csproj b/src/src/SourceGenerator/SourceGenerator.csproj index 5578ba7d..3784c3e5 100644 --- a/src/src/SourceGenerator/SourceGenerator.csproj +++ b/src/src/SourceGenerator/SourceGenerator.csproj @@ -26,6 +26,7 @@ README.md logs;log;logger;logging;source-generator;high-performance-logging;otel;open-telemetry;telemetry;traces;tracing;metric;metrics;meter;meters;instrumentation;instruments;events;distributed-traces;distributed-tracing;melt;dotnet;aspnet; + true diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorActivityTests.BasicContextGen.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorActivityTests.BasicContextGen.cs index af159562..dc9775c9 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorActivityTests.BasicContextGen.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorActivityTests.BasicContextGen.cs @@ -32,13 +32,12 @@ public interface ITestActivities var query = generationResult.Generated(); var implClass = query.GetClass("TestActivitiesCore", "Testing"); await Assert - .That(implClass.HasMethod(query, "Activity")) + .That(implClass.HasMethod("Activity")) .IsTrue() .Because("the generated implementation must contain the activity method"); await Assert .That( implClass.HasMethod( - query, "Context", TypeReference.Create(), TypeReference.Create(), @@ -83,7 +82,6 @@ public interface ITestActivities await Assert .That( implClass.HasMethod( - query, "Context", TypeReference.Create(), TypeReference.Create(), @@ -94,7 +92,7 @@ await Assert .IsTrue() .Because("the generated implementation must contain the context method"); await Assert - .That(implClass.HasMethodReturnType(query, "Context", TypeReference.Create())) + .That(implClass.HasMethodReturnType("Context", TypeReference.Create())) .IsTrue() .Because("the context method must return an Activity"); } @@ -134,7 +132,6 @@ public interface ITestActivities { await Assert .That( implClass.HasMethod( - query, "Context", TypeReference.Create(), TypeReference.Create(), @@ -147,7 +144,6 @@ await Assert await Assert .That( implClass.HasMethod( - query, "ContextWithNullableReturnActivity", TypeReference.Create(), TypeReference.Create(), @@ -160,7 +156,6 @@ await Assert await Assert .That( implClass.HasMethodReturnType( - query, "ContextWithNullableReturnActivity", TypeReference.Create().Nullable(GenerationSettings.Create()) ) @@ -205,7 +200,6 @@ public interface ITestActivities await Assert .That( implClass.HasMethod( - query, "Context", TypeReference.Create(), TypeReference.Create(), @@ -218,7 +212,6 @@ await Assert await Assert .That( implClass.HasMethod( - query, "ContextWithNullableParams", TypeReference.Create(), TypeReference.Create(), @@ -264,7 +257,6 @@ public interface ITestActivities await Assert .That( implClass.HasMethod( - query, "Context", TypeReference.Create(), TypeReference.Create(), @@ -277,7 +269,6 @@ await Assert await Assert .That( implClass.HasMethod( - query, "ContextWithNullableParams", TypeReference.Create(), TypeReference.Create(), @@ -325,7 +316,6 @@ public interface ITestActivities await Assert .That( implClass.HasMethod( - query, "Context", TypeReference.Create(), TypeReference.Create(), @@ -338,7 +328,6 @@ await Assert await Assert .That( implClass.HasMethod( - query, "ContextWithNullableParams", TypeReference.Create(), TypeReference.Create(), diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorActivityTests.BasicEventGen.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorActivityTests.BasicEventGen.cs index 39fffa6b..cb75abb3 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorActivityTests.BasicEventGen.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorActivityTests.BasicEventGen.cs @@ -40,13 +40,12 @@ public interface ITestActivities var query = generationResult.Generated(); var implClass = query.GetClass("TestActivitiesCore", "Testing"); await Assert - .That(implClass.HasMethod(query, "Activity")) + .That(implClass.HasMethod("Activity")) .IsTrue() .Because("the generated implementation must contain the activity method"); await Assert .That( implClass.HasMethod( - query, "ThisIsAMethod", TypeReference.Create(), TypeReference.Create(), @@ -87,13 +86,12 @@ public interface ITestActivities var query = generationResult.Generated(); var implClass = query.GetClass("TestActivitiesCore", "Testing"); await Assert - .That(implClass.HasMethod(query, "Activity")) + .That(implClass.HasMethod("Activity")) .IsTrue() .Because("the generated implementation must contain the activity method"); await Assert .That( implClass.HasMethod( - query, "Event", TypeReference.Create(), TypeReference.Create(), @@ -136,13 +134,12 @@ public interface ITestActivities var query = generationResult.Generated(); var implClass = query.GetClass("TestActivitiesCore", "Testing"); await Assert - .That(implClass.HasMethod(query, "Activity")) + .That(implClass.HasMethod("Activity")) .IsTrue() .Because("the generated implementation must contain the activity method"); await Assert .That( implClass.HasMethod( - query, "Event", TypeReference.Create(), TypeReference.Create(), @@ -185,11 +182,11 @@ public interface ITestActivities var query = generationResult.Generated(); var implClass = query.GetClass("TestActivitiesCore", "Testing"); await Assert - .That(implClass.HasMethod(query, "Activity")) + .That(implClass.HasMethod("Activity")) .IsTrue() .Because("the generated implementation must contain the activity method"); await Assert - .That(implClass.HasMethod(query, "Event", TypeReference.Create())) + .That(implClass.HasMethod("Event", TypeReference.Create())) .IsTrue() .Because("the generated implementation must contain the event method"); } @@ -225,11 +222,11 @@ public interface ITestActivities var query = generationResult.Generated(); var implClass = query.GetClass("TestActivitiesCore", "Testing"); await Assert - .That(implClass.HasMethod(query, "Activity")) + .That(implClass.HasMethod("Activity")) .IsTrue() .Because("the generated implementation must contain the activity method"); await Assert - .That(implClass.HasMethod(query, "Event", TypeReference.Create())) + .That(implClass.HasMethod("Event", TypeReference.Create())) .IsTrue() .Because("the generated implementation must contain the error-status event method"); } @@ -330,13 +327,11 @@ public interface ITestActivities var query = generationResult.Generated(); var implClass = query.GetClass("TestActivitiesCore", "Testing"); await Assert - .That(implClass.HasMethod(query, "Event", TypeReference.Create(), TypeReference.Create())) + .That(implClass.HasMethod("Event", TypeReference.Create(), TypeReference.Create())) .IsTrue() .Because("the generated implementation must contain the first status-description event method"); await Assert - .That( - implClass.HasMethod(query, "Event2", TypeReference.Create(), TypeReference.Create()) - ) + .That(implClass.HasMethod("Event2", TypeReference.Create(), TypeReference.Create())) .IsTrue() .Because("the generated implementation must contain the second status-description event method"); } diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorActivityTests.BasicGen.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorActivityTests.BasicGen.cs index 31844f87..c0bfda6f 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorActivityTests.BasicGen.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorActivityTests.BasicGen.cs @@ -35,7 +35,6 @@ public interface ITestActivities { await Assert .That( implClass.HasMethod( - query, "Activity", TypeReference.Create(), TypeReference.Create(), @@ -47,7 +46,6 @@ await Assert await Assert .That( implClass.HasMethodReturnType( - query, "Activity", TypeReference.Create().Nullable(GenerationSettings.Create()) ) @@ -57,7 +55,6 @@ await Assert await Assert .That( implClass.HasMethod( - query, "Event", TypeReference.Create(), TypeReference.Create(), @@ -130,7 +127,6 @@ public interface ITestActivities await Assert .That( implClass.HasMethod( - query, "Activity", TypeReference.Create(), TypeReference.Create(), @@ -142,7 +138,6 @@ await Assert await Assert .That( implClass.HasMethod( - query, "Event", TypeReference.Create(), TypeReference.Create(), @@ -285,7 +280,6 @@ public interface ITestActivities { await Assert .That( implClass.HasMethod( - query, "Activity", TypeReference.Create(), TypeReference.Create().Nullable(GenerationSettings.Create()), @@ -297,7 +291,6 @@ await Assert await Assert .That( implClass.HasMethod( - query, "ActivityWithNullableParams", TypeReference.Create(), TypeReference.Create().Nullable(GenerationSettings.Create()), diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorActivityTests.CSharp73.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorActivityTests.CSharp73.cs index 13ffcca3..b1ef1670 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorActivityTests.CSharp73.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorActivityTests.CSharp73.cs @@ -41,7 +41,6 @@ public interface ITestActivities { await Assert .That( implClass.HasMethod( - query, "Activity", TypeReference.Create(), TypeReference.Create(), @@ -53,7 +52,6 @@ await Assert await Assert .That( implClass.HasMethod( - query, "Event", TypeReference.Create(), TypeReference.Create(), diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorActivityTests.DI.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorActivityTests.DI.cs index 387c656c..b092f9f6 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorActivityTests.DI.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorActivityTests.DI.cs @@ -43,7 +43,6 @@ public interface ITestActivities { await Assert .That( implClass.HasMethod( - query, "Activity", TypeReference.Create(), TypeReference.Create(), @@ -55,7 +54,6 @@ await Assert await Assert .That( implClass.HasMethodReturnType( - query, "Activity", TypeReference.Create().Nullable(GenerationSettings.Create()) ) @@ -65,7 +63,7 @@ await Assert var diClass = query.GetClass("TestActivitiesCoreDIExtension", "Microsoft.Extensions.DependencyInjection"); await Assert - .That(diClass.HasMethod(query, "AddTestActivities", TypeReference.Create())) + .That(diClass.HasMethod("AddTestActivities", TypeReference.Create())) .IsTrue() .Because("the DI extension must register the implementation via AddTestActivities"); } @@ -105,7 +103,6 @@ public interface ITestActivities { await Assert .That( implClass.HasMethod( - query, "Activity", TypeReference.Create(), TypeReference.Create(), @@ -116,7 +113,7 @@ await Assert .Because("the generated implementation must contain the activity method"); var diClass = query.GetClass("TestActivitiesCoreDIExtension", "Microsoft.Extensions.DependencyInjection"); await Assert - .That(diClass.HasMethod(query, "AddTestActivities", TypeReference.Create())) + .That(diClass.HasMethod("AddTestActivities", TypeReference.Create())) .IsTrue() .Because("the DI extension must register the implementation via AddTestActivities"); } @@ -160,7 +157,6 @@ public interface ITestActivities { await Assert .That( implClass.HasMethod( - query, "Activity", TypeReference.Create(), TypeReference.Create(), @@ -171,7 +167,7 @@ await Assert .Because("the generated implementation must contain the activity method"); var diClass = query.GetClass("TestActivitiesCoreDIExtension", "Microsoft.Extensions.DependencyInjection"); await Assert - .That(diClass.HasMethod(query, "AddTestActivities", TypeReference.Create())) + .That(diClass.HasMethod("AddTestActivities", TypeReference.Create())) .IsTrue() .Because("the DI extension must be generated when the interface opts in"); } @@ -215,7 +211,6 @@ public interface ITestActivities { await Assert .That( implClass.HasMethod( - query, "Activity", TypeReference.Create(), TypeReference.Create(), @@ -268,7 +263,6 @@ public interface ITestActivities { await Assert .That( implClass.HasMethod( - query, "Activity", TypeReference.Create(), TypeReference.Create(), @@ -279,7 +273,7 @@ await Assert .Because("the generated implementation must contain the activity method"); var diClass = query.GetClass("TestActivitiesCoreDIExtension", "Microsoft.Extensions.DependencyInjection"); await Assert - .That(diClass.HasMethod(query, "AddTestActivities", TypeReference.Create())) + .That(diClass.HasMethod("AddTestActivities", TypeReference.Create())) .IsTrue() .Because("the public DI extension must register the implementation via AddTestActivities"); } diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorActivityTests.ParentTests.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorActivityTests.ParentTests.cs index 136d6fc6..94eaf912 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorActivityTests.ParentTests.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorActivityTests.ParentTests.cs @@ -31,7 +31,7 @@ public interface ITestActivities { var query = generationResult.Generated(); var implClass = query.GetClass("TestActivitiesCore", "Testing"); await Assert - .That(implClass.HasMethod(query, "Activity", TypeReference.Create())) + .That(implClass.HasMethod("Activity", TypeReference.Create())) .IsTrue() .Because("the generated implementation must contain the activity method with an ActivityContext parameter"); } @@ -64,7 +64,6 @@ public interface ITestActivities { await Assert .That( implClass.HasMethod( - query, "Activity", TypeReference .Create() @@ -101,7 +100,7 @@ public interface ITestActivities { var query = generationResult.Generated(); var implClass = query.GetClass("TestActivitiesCore", "Testing"); await Assert - .That(implClass.HasMethod(query, "Activity", TypeReference.Create())) + .That(implClass.HasMethod("Activity", TypeReference.Create())) .IsTrue() .Because("the generated implementation must contain the activity method with a parent-id string parameter"); } @@ -132,7 +131,7 @@ public interface ITestActivities { var query = generationResult.Generated(); var implClass = query.GetClass("TestActivitiesCore", "Testing"); await Assert - .That(implClass.HasMethod(query, "Activity", TypeReference.Create())) + .That(implClass.HasMethod("Activity", TypeReference.Create())) .IsTrue() .Because( "the generated implementation must contain the activity method with a nullable parent-id string parameter" diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorActivityTests.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorActivityTests.cs index 94c8db80..a921d63e 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorActivityTests.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorActivityTests.cs @@ -39,15 +39,15 @@ public interface ITestActivities var query = generationResult.Generated(); var implClass = query.GetClass("TestActivitiesCore", "Testing"); await Assert - .That(implClass.HasMethod(query, "Activity")) + .That(implClass.HasMethod("Activity")) .IsTrue() .Because("the generated implementation must contain the activity method"); await Assert - .That(implClass.HasMethod(query, "Event")) + .That(implClass.HasMethod("Event")) .IsTrue() .Because("the generated implementation must contain the event method"); await Assert - .That(implClass.HasMethod(query, "Context")) + .That(implClass.HasMethod("Context")) .IsTrue() .Because("the generated implementation must contain the context method"); } diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingGen2Tests.CSharp73.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingGen2Tests.CSharp73.cs index 1e9256d9..c8bae867 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingGen2Tests.CSharp73.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingGen2Tests.CSharp73.cs @@ -35,7 +35,6 @@ public interface ITestLogger { await Assert .That( loggerClass.HasMethod( - query, "Log", TypeReference.Create(), TypeReference.Create(), diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingGen2Tests.ExceptionTests.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingGen2Tests.ExceptionTests.cs index 2d5643e2..732a44c3 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingGen2Tests.ExceptionTests.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingGen2Tests.ExceptionTests.cs @@ -30,11 +30,7 @@ public interface ITestLogger { var loggerClass = query.GetClass("TestLoggerCore", "Testing"); await Assert .That( - loggerClass.HasMethod( - query, - "LogEntryWithCustomExceptionType", - TypeReference.Create() - ) + loggerClass.HasMethod("LogEntryWithCustomExceptionType", TypeReference.Create()) ) .IsTrue() .Because("the generated logger must treat the non-specific exception type as the exception parameter"); @@ -68,7 +64,6 @@ public class BadLuckException : Exception { } await Assert .That( loggerClass.HasMethod( - query, "LogEntryWithCustomExceptionType", new TypeReference(new TypeIdentity("BadLuckException", "Testing")) ) diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingGen2Tests.ExpandEnumerable.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingGen2Tests.ExpandEnumerable.cs index b3324950..622fbf64 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingGen2Tests.ExpandEnumerable.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingGen2Tests.ExpandEnumerable.cs @@ -31,7 +31,7 @@ public interface ITestLogger var query = generationResult.Generated(); var loggerClass = query.GetClass("TestLoggerCore", "Testing"); await Assert - .That(loggerClass.HasMethod(query, "Log")) + .That(loggerClass.HasMethod("Log")) .IsTrue() .Because("the generated logger must contain the log method with the expandable parameter"); } diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingGen2Tests.LogProperties.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingGen2Tests.LogProperties.cs index ec967872..a0b61ae0 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingGen2Tests.LogProperties.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingGen2Tests.LogProperties.cs @@ -39,11 +39,7 @@ public class WeatherForecast var loggerClass = query.GetClass("TestLoggerCore", "Testing"); await Assert .That( - loggerClass.HasMethod( - query, - "LogWeather", - new TypeReference(new TypeIdentity("WeatherForecast", "Testing")) - ) + loggerClass.HasMethod("LogWeather", new TypeReference(new TypeIdentity("WeatherForecast", "Testing"))) ) .IsTrue() .Because("the generated logger must contain the log method with the class-typed parameter"); @@ -118,9 +114,7 @@ public interface ITestLogger var query = generationResult.Generated(); var loggerClass = query.GetClass("TestLoggerCore", "Testing"); await Assert - .That( - loggerClass.HasMethod(query, "Log", TypeReference.Create(), TypeReference.Create()) - ) + .That(loggerClass.HasMethod("Log", TypeReference.Create(), TypeReference.Create())) .IsTrue() .Because("the generated logger must contain the log method with the exception parameter"); await Assert @@ -164,7 +158,6 @@ public class WeatherForecast await Assert .That( loggerClass.HasMethod( - query, "LogWeatherWithOmit", new TypeReference(new TypeIdentity("WeatherForecast", "Testing")) ) @@ -211,11 +204,7 @@ public class WeatherForecast var loggerClass = query.GetClass("TestLoggerCore", "Testing"); await Assert .That( - loggerClass.HasMethod( - query, - "LogWeather", - new TypeReference(new TypeIdentity("WeatherForecast", "Testing")) - ) + loggerClass.HasMethod("LogWeather", new TypeReference(new TypeIdentity("WeatherForecast", "Testing"))) ) .IsTrue() .Because("the generated logger must contain the log method with the class-typed parameter"); @@ -259,11 +248,7 @@ public class WeatherForecast var loggerClass = query.GetClass("TestLoggerCore", "Testing"); await Assert .That( - loggerClass.HasMethod( - query, - "LogWeather", - new TypeReference(new TypeIdentity("WeatherForecast", "Testing")) - ) + loggerClass.HasMethod("LogWeather", new TypeReference(new TypeIdentity("WeatherForecast", "Testing"))) ) .IsTrue() .Because("the generated logger must contain the log method with the class-typed parameter"); @@ -310,11 +295,7 @@ public class WeatherForecast var loggerClass = query.GetClass("TestLoggerCore", "Testing"); await Assert .That( - loggerClass.HasMethod( - query, - "LogWeather", - new TypeReference(new TypeIdentity("WeatherForecast", "Testing")) - ) + loggerClass.HasMethod("LogWeather", new TypeReference(new TypeIdentity("WeatherForecast", "Testing"))) ) .IsTrue() .Because("the generated logger must contain the log method with the class-typed parameter"); diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingGen2Tests.PerMethodV1.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingGen2Tests.PerMethodV1.cs index 1c234962..c2682872 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingGen2Tests.PerMethodV1.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingGen2Tests.PerMethodV1.cs @@ -31,11 +31,11 @@ public interface ITestLogger { var query = generationResult.Generated(); var loggerClass = query.GetClass("TestLoggerCore", "Testing"); await Assert - .That(loggerClass.HasMethod(query, "RegularV2LogEntry", TypeReference.Create())) + .That(loggerClass.HasMethod("RegularV2LogEntry", TypeReference.Create())) .IsTrue() .Because("the generated logger must contain the regular V2 log method"); await Assert - .That(loggerClass.HasMethod(query, "HotPathV1LogEntry", TypeReference.Create())) + .That(loggerClass.HasMethod("HotPathV1LogEntry", TypeReference.Create())) .IsTrue() .Because("the generated logger must contain the V1-overridden log method"); } @@ -66,11 +66,11 @@ public interface ITestLogger { var query = generationResult.Generated(); var loggerClass = query.GetClass("TestLoggerCore", "Testing"); await Assert - .That(loggerClass.HasMethod(query, "RegularV2LogEntry", TypeReference.Create())) + .That(loggerClass.HasMethod("RegularV2LogEntry", TypeReference.Create())) .IsTrue() .Because("the generated logger must contain the regular V2 log method"); await Assert - .That(loggerClass.HasMethod(query, "HotPathDebugEntry", TypeReference.Create())) + .That(loggerClass.HasMethod("HotPathDebugEntry", TypeReference.Create())) .IsTrue() .Because("the generated logger must contain the V1-overridden debug log method"); } diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingGen2Tests.ScopedGen.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingGen2Tests.ScopedGen.cs index ef37942d..1c53b40c 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingGen2Tests.ScopedGen.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingGen2Tests.ScopedGen.cs @@ -34,11 +34,11 @@ public interface ITestLogger var query = generationResult.Generated(); var loggerClass = query.GetClass("TestLoggerCore", "Testing"); await Assert - .That(loggerClass.HasMethod(query, "BasicScoped")) + .That(loggerClass.HasMethod("BasicScoped")) .IsTrue() .Because("the generated logger must contain the scoped log method"); await Assert - .That(loggerClass.HasMethodReturnType(query, "BasicScoped", TypeReference.Create())) + .That(loggerClass.HasMethodReturnType("BasicScoped", TypeReference.Create())) .IsTrue() .Because("the scoped log method must return IDisposable"); } @@ -70,7 +70,6 @@ public interface ITestLogger await Assert .That( loggerClass.HasMethod( - query, "BasicScoped", TypeReference.Create(), TypeReference.Create(), @@ -80,7 +79,7 @@ await Assert .IsTrue() .Because("the generated logger must contain the scoped log method with its parameter signature"); await Assert - .That(loggerClass.HasMethodReturnType(query, "BasicScoped", TypeReference.Create())) + .That(loggerClass.HasMethodReturnType("BasicScoped", TypeReference.Create())) .IsTrue() .Because("the scoped log method must return IDisposable"); } @@ -114,7 +113,6 @@ public interface ITestLogger await Assert .That( loggerClass.HasMethod( - query, "BasicScoped", TypeReference.Create(), TypeReference.Create(), @@ -124,7 +122,7 @@ await Assert .IsTrue() .Because("the generated logger must contain the scoped log method with its parameter signature"); await Assert - .That(loggerClass.HasMethodReturnType(query, "BasicScoped", TypeReference.Create())) + .That(loggerClass.HasMethodReturnType("BasicScoped", TypeReference.Create())) .IsTrue() .Because("the scoped log method must return IDisposable"); } @@ -158,7 +156,6 @@ public interface ITestLogger await Assert .That( loggerClass.HasMethod( - query, "BasicScoped", TypeReference.Create(), TypeReference.Create(), @@ -168,7 +165,7 @@ await Assert .IsTrue() .Because("the generated logger must contain the scoped log method with its parameter signature"); await Assert - .That(loggerClass.HasMethodReturnType(query, "BasicScoped", TypeReference.Create())) + .That(loggerClass.HasMethodReturnType("BasicScoped", TypeReference.Create())) .IsTrue() .Because("the scoped log method must return IDisposable"); } diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingGen2Tests.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingGen2Tests.cs index c185d6ad..141e7ffc 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingGen2Tests.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingGen2Tests.cs @@ -32,7 +32,7 @@ public interface ITestLogger var query = generationResult.Generated(); var loggerClass = query.GetClass("TestLoggerCore", "Testing"); await Assert - .That(loggerClass.HasMethod(query, "LogEntryWithGenericTypeParam")) + .That(loggerClass.HasMethod("LogEntryWithGenericTypeParam")) .IsTrue() .Because("the generated logger must contain the log method"); } @@ -121,7 +121,7 @@ public interface ITestLogger { var query = generationResult.Generated(); var loggerClass = query.GetClass("TestLoggerCore", "Testing"); await Assert - .That(loggerClass.HasMethod(query, "LogEntryWithMoreThanSixParams")) + .That(loggerClass.HasMethod("LogEntryWithMoreThanSixParams")) .IsTrue() .Because("the generated logger must contain the log method with more than six parameters"); } diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.BasicGen.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.BasicGen.cs index 14bce164..b661d674 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.BasicGen.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.BasicGen.cs @@ -32,7 +32,6 @@ public interface ITestLogger { await Assert .That( loggerClass.HasMethod( - query, "Log", TypeReference.Create(), TypeReference.Create(), @@ -69,7 +68,6 @@ public interface ITestLogger { await Assert .That( loggerClass.HasMethod( - query, "Log", TypeReference.Create(), TypeReference.Create(), @@ -111,7 +109,6 @@ public interface ITestLogger {{ await Assert .That( loggerClass.HasMethod( - query, "Log", TypeReference.Create(), TypeReference.Create(), @@ -229,11 +226,11 @@ public interface ITestLogger { var query = generationResult.Generated(); var loggerClass = query.GetClass("TestLoggerCore", "Testing"); await Assert - .That(loggerClass.HasMethod(query, "Log")) + .That(loggerClass.HasMethod("Log")) .IsTrue() .Because("the generated logger must contain the scoped log method"); await Assert - .That(loggerClass.HasMethodReturnType(query, "Log", TypeReference.Create())) + .That(loggerClass.HasMethodReturnType("Log", TypeReference.Create())) .IsTrue() .Because("the scoped log method must return IDisposable"); } @@ -264,7 +261,6 @@ public interface ITestLogger { await Assert .That( loggerClass.HasMethod( - query, "Log", TypeReference.Create(), TypeReference.Create(), @@ -274,7 +270,7 @@ await Assert .IsTrue() .Because("the generated logger must contain the scoped log method with its parameter signature"); await Assert - .That(loggerClass.HasMethodReturnType(query, "Log", TypeReference.Create())) + .That(loggerClass.HasMethodReturnType("Log", TypeReference.Create())) .IsTrue() .Because("the scoped log method must return IDisposable"); } @@ -303,11 +299,11 @@ public interface ITestLogger { var query = generationResult.Generated(); var loggerClass = query.GetClass("TestLoggerCore", "Testing"); await Assert - .That(loggerClass.HasMethod(query, "Log", TypeReference.Create(), TypeReference.Create())) + .That(loggerClass.HasMethod("Log", TypeReference.Create(), TypeReference.Create())) .IsTrue() .Because("the generated logger must contain the scoped log method with its parameter signature"); await Assert - .That(loggerClass.HasMethodReturnType(query, "Log", TypeReference.Create())) + .That(loggerClass.HasMethodReturnType("Log", TypeReference.Create())) .IsTrue() .Because("the scoped log method must return IDisposable"); } diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.CSharp73.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.CSharp73.cs index 545abaf5..d6a14a38 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.CSharp73.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.CSharp73.cs @@ -33,7 +33,6 @@ public interface ITestLogger { await Assert .That( loggerClass.HasMethod( - query, "Log", TypeReference.Create(), TypeReference.Create(), diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.DI.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.DI.cs index 712d57d4..c11f9256 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.DI.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.DI.cs @@ -36,7 +36,6 @@ public interface ITestLogger { await Assert .That( loggerClass.HasMethod( - query, "Log", TypeReference.Create(), TypeReference.Create(), @@ -47,7 +46,7 @@ await Assert .Because("the generated logger must contain the log method"); var diClass = query.GetClass("TestLoggerCoreDIExtension", "Microsoft.Extensions.DependencyInjection"); await Assert - .That(diClass.HasMethod(query, "AddTestLogger", TypeReference.Create())) + .That(diClass.HasMethod("AddTestLogger", TypeReference.Create())) .IsTrue() .Because("the DI extension must register the logger via AddTestLogger"); } @@ -82,7 +81,6 @@ public interface ITestLogger { await Assert .That( loggerClass.HasMethod( - query, "Log", TypeReference.Create(), TypeReference.Create(), @@ -93,7 +91,7 @@ await Assert .Because("the generated logger must contain the log method"); var diClass = query.GetClass("TestLoggerCoreDIExtension", "Microsoft.Extensions.DependencyInjection"); await Assert - .That(diClass.HasMethod(query, "AddTestLogger", TypeReference.Create())) + .That(diClass.HasMethod("AddTestLogger", TypeReference.Create())) .IsTrue() .Because("the DI extension must be generated when the interface opts in"); } @@ -132,7 +130,6 @@ public interface ITestLogger { await Assert .That( loggerClass.HasMethod( - query, "Log", TypeReference.Create(), TypeReference.Create(), @@ -143,7 +140,7 @@ await Assert .Because("the generated logger must contain the log method"); var diClass = query.GetClass("TestLoggerCoreDIExtension", "Microsoft.Extensions.DependencyInjection"); await Assert - .That(diClass.HasMethod(query, "AddTestLogger", TypeReference.Create())) + .That(diClass.HasMethod("AddTestLogger", TypeReference.Create())) .IsTrue() .Because("the DI extension must be generated when the interface overrides the disabled assembly default"); } @@ -182,7 +179,6 @@ public interface ITestLogger { await Assert .That( loggerClass.HasMethod( - query, "Log", TypeReference.Create(), TypeReference.Create(), diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.LogAttribute.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.LogAttribute.cs index bda151ab..c3de7a3b 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.LogAttribute.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.LogAttribute.cs @@ -34,7 +34,6 @@ public interface ITestLogger { await Assert .That( loggerClass.HasMethod( - query, "Log", TypeReference.Create(), TypeReference.Create(), @@ -86,7 +85,6 @@ public interface ITestLogger { await Assert .That( loggerClass.HasMethod( - query, "Log", TypeReference.Create(), TypeReference.Create(), diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.Nested.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.Nested.cs index 1b3055b7..378ddbda 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.Nested.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.Nested.cs @@ -32,11 +32,11 @@ public interface ITestLogger {{ var query = generationResult.Generated(); var loggerClass = query.GetClass("TestLoggerCore", @namespace); await Assert - .That(loggerClass.HasMethod(query, "Log", TypeReference.Create(), TypeReference.Create())) + .That(loggerClass.HasMethod("Log", TypeReference.Create(), TypeReference.Create())) .IsTrue() .Because("the generated logger must contain the scoped log method"); await Assert - .That(loggerClass.HasMethodReturnType(query, "Log", TypeReference.Create())) + .That(loggerClass.HasMethodReturnType("Log", TypeReference.Create())) .IsTrue() .Because("the scoped log method must return IDisposable"); } @@ -71,11 +71,11 @@ public interface ITestLogger {{ var query = generationResult.Generated(); var loggerClass = query.GetClass("TestLoggerCore", @namespace); await Assert - .That(loggerClass.HasMethod(query, "Log", TypeReference.Create(), TypeReference.Create())) + .That(loggerClass.HasMethod("Log", TypeReference.Create(), TypeReference.Create())) .IsTrue() .Because("the generated logger must contain the scoped log method"); await Assert - .That(loggerClass.HasMethodReturnType(query, "Log", TypeReference.Create())) + .That(loggerClass.HasMethodReturnType("Log", TypeReference.Create())) .IsTrue() .Because("the scoped log method must return IDisposable"); } @@ -114,11 +114,11 @@ public interface ITestLogger {{ var query = generationResult.Generated(); var loggerClass = query.GetClass("TestLoggerCore", @namespace); await Assert - .That(loggerClass.HasMethod(query, "Log", TypeReference.Create(), TypeReference.Create())) + .That(loggerClass.HasMethod("Log", TypeReference.Create(), TypeReference.Create())) .IsTrue() .Because("the generated logger must contain the scoped log method"); await Assert - .That(loggerClass.HasMethodReturnType(query, "Log", TypeReference.Create())) + .That(loggerClass.HasMethodReturnType("Log", TypeReference.Create())) .IsTrue() .Because("the scoped log method must return IDisposable"); } diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.NoILoggerRef.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.NoILoggerRef.cs index ed9eae2f..d13ccfcc 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.NoILoggerRef.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.NoILoggerRef.cs @@ -39,7 +39,6 @@ public interface ITestActivities { await Assert .That( implClass.HasMethod( - query, "Activity", TypeReference.Create(), TypeReference.Create(), diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.SpecificLogAttribute.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.SpecificLogAttribute.cs index e04e4e09..3e91cd6c 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.SpecificLogAttribute.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.SpecificLogAttribute.cs @@ -34,7 +34,6 @@ public interface ITestLogger await Assert .That( loggerClass.HasMethod( - query, "Log", TypeReference.Create(), TypeReference.Create(), @@ -91,7 +90,6 @@ public interface ITestLogger await Assert .That( loggerClass.HasMethod( - query, "Log", TypeReference.Create(), TypeReference.Create(), @@ -103,7 +101,6 @@ await Assert await Assert .That( loggerClass.HasMethod( - query, "Log_EventId_1", TypeReference.Create(), TypeReference.Create(), @@ -115,7 +112,6 @@ await Assert await Assert .That( loggerClass.HasMethod( - query, "Log_EventId_3", TypeReference.Create(), TypeReference.Create(), @@ -127,7 +123,6 @@ await Assert await Assert .That( loggerClass.HasMethod( - query, "Log_MessageTemplate_1", TypeReference.Create(), TypeReference.Create(), @@ -139,7 +134,6 @@ await Assert await Assert .That( loggerClass.HasMethod( - query, "Log_MessageTemplate_2", TypeReference.Create(), TypeReference.Create(), @@ -151,7 +145,6 @@ await Assert await Assert .That( loggerClass.HasMethod( - query, "Log_MessageTemplate_3", TypeReference.Create(), TypeReference.Create(), diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.cs index af7aa907..d0d8a7d5 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorLoggingTests.cs @@ -30,7 +30,7 @@ public interface ITestLogger {{ var query = generationResult.Generated(); var loggerClass = query.GetClass("TestLoggerCore", "Testing"); await Assert - .That(loggerClass.HasMethod(query, "LogEntryWithGenericTypeParam")) + .That(loggerClass.HasMethod("LogEntryWithGenericTypeParam")) .IsTrue() .Because("the generated logger must contain the log method"); } diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.CSharp73.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.CSharp73.cs index cd284e32..1d80f27f 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.CSharp73.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.CSharp73.cs @@ -44,28 +44,19 @@ public interface ITestMetrics { var query = generationResult.Generated(); var metricsClass = query.GetClass("TestMetricsCore", "Testing"); await Assert - .That(metricsClass.HasMethod(query, "AutoCounter", TypeReference.Create())) + .That(metricsClass.HasMethod("AutoCounter", TypeReference.Create())) .IsTrue() .Because("the generated metrics class must contain the auto-counter method"); await Assert - .That(metricsClass.HasMethod(query, "Counter", TypeReference.Create(), TypeReference.Create())) + .That(metricsClass.HasMethod("Counter", TypeReference.Create(), TypeReference.Create())) .IsTrue() .Because("the generated metrics class must contain the counter method"); await Assert - .That( - metricsClass.HasMethod(query, "Histogram", TypeReference.Create(), TypeReference.Create()) - ) + .That(metricsClass.HasMethod("Histogram", TypeReference.Create(), TypeReference.Create())) .IsTrue() .Because("the generated metrics class must contain the histogram method"); await Assert - .That( - metricsClass.HasMethod( - query, - "UpDownCounter", - TypeReference.Create(), - TypeReference.Create() - ) - ) + .That(metricsClass.HasMethod("UpDownCounter", TypeReference.Create(), TypeReference.Create())) .IsTrue() .Because("the generated metrics class must contain the up-down counter method"); } diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.Counters.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.Counters.cs index 0f049b46..bfae7f7d 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.Counters.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.Counters.cs @@ -32,7 +32,7 @@ public interface ITestMetrics var query = generationResult.Generated(); var metricsClass = query.GetClass("TestMetricsCore", "Testing"); await Assert - .That(metricsClass.HasMethod(query, "AutoCounter", TypeReference.Create())) + .That(metricsClass.HasMethod("AutoCounter", TypeReference.Create())) .IsTrue() .Because("the generated metrics class must contain the auto-counter method"); } @@ -93,9 +93,7 @@ public interface ITestMetrics var query = generationResult.Generated(); var metricsClass = query.GetClass("TestMetricsCore", "Testing"); await Assert - .That( - metricsClass.HasMethod(query, "AutoCounter", TypeReference.Create(), TypeReference.Create()) - ) + .That(metricsClass.HasMethod("AutoCounter", TypeReference.Create(), TypeReference.Create())) .IsTrue() .Because("the generated metrics class must contain the auto-counter method"); } @@ -176,7 +174,7 @@ public interface ITestMetrics { foreach (var methodName in counterMethods) { await Assert - .That(metricsClass.HasMethod(query, methodName)) + .That(metricsClass.HasMethod(methodName)) .IsTrue() .Because($"the generated metrics class must contain the {methodName} method"); } @@ -215,7 +213,7 @@ public interface ITestMetrics { foreach (var methodName in counterMethods) { await Assert - .That(metricsClass.HasMethod(query, methodName)) + .That(metricsClass.HasMethod(methodName)) .IsTrue() .Because($"the generated metrics class must contain the {methodName} method"); } @@ -253,15 +251,15 @@ public interface ITestMetrics { var query = generationResult.Generated(); var metricsClass = query.GetClass("TestMetricsCore", "Testing"); await Assert - .That(metricsClass.HasMethod(query, "ObservableCounter")) + .That(metricsClass.HasMethod("ObservableCounter")) .IsTrue() .Because("the generated metrics class must contain the observable counter method"); await Assert - .That(metricsClass.HasMethod(query, "ObservableCounter2")) + .That(metricsClass.HasMethod("ObservableCounter2")) .IsTrue() .Because("the generated metrics class must contain the second observable counter method"); await Assert - .That(metricsClass.HasMethod(query, "ObservableCounter3")) + .That(metricsClass.HasMethod("ObservableCounter3")) .IsTrue() .Because("the generated metrics class must contain the third observable counter method"); } diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.DI.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.DI.cs index 2818fe9b..0d1961fa 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.DI.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.DI.cs @@ -37,7 +37,6 @@ public interface ITestMetrics { await Assert .That( metricsClass.HasMethod( - query, "Counter", TypeReference.Create(), TypeReference.Create(), @@ -48,7 +47,7 @@ await Assert .Because("the generated metrics class must contain the counter method"); var diClass = query.GetClass("TestMetricsCoreDIExtension", "Microsoft.Extensions.DependencyInjection"); await Assert - .That(diClass.HasMethod(query, "AddTestMetrics", TypeReference.Create())) + .That(diClass.HasMethod("AddTestMetrics", TypeReference.Create())) .IsTrue() .Because("the DI extension must register the metrics via AddTestMetrics"); } @@ -84,7 +83,6 @@ public interface ITestMetrics { await Assert .That( metricsClass.HasMethod( - query, "Counter", TypeReference.Create(), TypeReference.Create(), @@ -95,7 +93,7 @@ await Assert .Because("the generated metrics class must contain the counter method"); var diClass = query.GetClass("TestMetricsCoreDIExtension", "Microsoft.Extensions.DependencyInjection"); await Assert - .That(diClass.HasMethod(query, "AddTestMetrics", TypeReference.Create())) + .That(diClass.HasMethod("AddTestMetrics", TypeReference.Create())) .IsTrue() .Because("the DI extension must be generated when the interface opts in"); } @@ -135,7 +133,6 @@ public interface ITestMetrics { await Assert .That( metricsClass.HasMethod( - query, "Counter", TypeReference.Create(), TypeReference.Create(), @@ -146,7 +143,7 @@ await Assert .Because("the generated metrics class must contain the counter method"); var diClass = query.GetClass("TestMetricsCoreDIExtension", "Microsoft.Extensions.DependencyInjection"); await Assert - .That(diClass.HasMethod(query, "AddTestMetrics", TypeReference.Create())) + .That(diClass.HasMethod("AddTestMetrics", TypeReference.Create())) .IsTrue() .Because("the DI extension must be generated when the interface overrides the disabled assembly default"); } @@ -186,7 +183,6 @@ public interface ITestMetrics { await Assert .That( metricsClass.HasMethod( - query, "Counter", TypeReference.Create(), TypeReference.Create(), diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.Gauge.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.Gauge.cs index ce90a4c4..f8711fdd 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.Gauge.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.Gauge.cs @@ -34,15 +34,15 @@ public interface ITestMetrics { var query = generationResult.Generated(); var metricsClass = query.GetClass("TestMetricsCore", "Testing"); await Assert - .That(metricsClass.HasMethod(query, "ObservableGauge")) + .That(metricsClass.HasMethod("ObservableGauge")) .IsTrue() .Because("the generated metrics class must contain the observable gauge method"); await Assert - .That(metricsClass.HasMethod(query, "ObservableGauge2")) + .That(metricsClass.HasMethod("ObservableGauge2")) .IsTrue() .Because("the generated metrics class must contain the second observable gauge method"); await Assert - .That(metricsClass.HasMethod(query, "ObservableGauge3")) + .That(metricsClass.HasMethod("ObservableGauge3")) .IsTrue() .Because("the generated metrics class must contain the third observable gauge method"); } diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.Histogram.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.Histogram.cs index cbc1e9f2..844d4e96 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.Histogram.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.Histogram.cs @@ -33,7 +33,6 @@ public interface ITestMetrics { await Assert .That( metricsClass.HasMethod( - query, "Histogram", TypeReference.Create(), TypeReference.Create(), @@ -45,7 +44,6 @@ await Assert await Assert .That( metricsClass.HasMethod( - query, "Histogram1", TypeReference.Create(), TypeReference.Create(), diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.MeterNaming.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.MeterNaming.cs index 7c4cb884..cedfe557 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.MeterNaming.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.MeterNaming.cs @@ -29,7 +29,7 @@ interface ITestMetrics var query = generationResult.Generated(); var metricsClass = query.GetClass("TestMetricsCore", "Testing"); await Assert - .That(metricsClass.HasMethod(query, "AutoCounterMetric")) + .That(metricsClass.HasMethod("AutoCounterMetric")) .IsTrue() .Because("the generated metrics class must contain the auto-counter method"); await Assert @@ -67,7 +67,7 @@ interface ITestMetrics var query = generationResult.Generated(); var metricsClass = query.GetClass("TestMetricsCore", "Testing"); await Assert - .That(metricsClass.HasMethod(query, "AutoCounterMetric")) + .That(metricsClass.HasMethod("AutoCounterMetric")) .IsTrue() .Because("the generated metrics class must contain the auto-counter method"); await Assert @@ -105,7 +105,7 @@ interface ITestMetrics var query = generationResult.Generated(); var metricsClass = query.GetClass("TestMetricsCore", "Testing"); await Assert - .That(metricsClass.HasMethod(query, "AutoCounterMetric")) + .That(metricsClass.HasMethod("AutoCounterMetric")) .IsTrue() .Because("the generated metrics class must contain the auto-counter method"); await Assert @@ -143,7 +143,7 @@ interface ITestMetrics var query = generationResult.Generated(); var metricsClass = query.GetClass("TestMetricsCore", "Testing"); await Assert - .That(metricsClass.HasMethod(query, "AutoCounterMetric")) + .That(metricsClass.HasMethod("AutoCounterMetric")) .IsTrue() .Because("the generated metrics class must contain the auto-counter method"); await Assert @@ -179,7 +179,7 @@ interface ITestMetrics var query = generationResult.Generated(); var metricsClass = query.GetClass("TestMetricsCore", "Testing"); await Assert - .That(metricsClass.HasMethod(query, "AutoCounterMetric")) + .That(metricsClass.HasMethod("AutoCounterMetric")) .IsTrue() .Because("the generated metrics class must contain the auto-counter method"); await Assert @@ -215,7 +215,7 @@ interface ITestMetrics var query = generationResult.Generated(); var metricsClass = query.GetClass("TestMetricsCore", "Testing"); await Assert - .That(metricsClass.HasMethod(query, "AutoCounterMetric")) + .That(metricsClass.HasMethod("AutoCounterMetric")) .IsTrue() .Because("the generated metrics class must contain the auto-counter method"); await Assert @@ -251,7 +251,7 @@ interface ITestMetrics var query = generationResult.Generated(); var metricsClass = query.GetClass("TestMetricsCore", "Testing"); await Assert - .That(metricsClass.HasMethod(query, "AutoCounterMetric")) + .That(metricsClass.HasMethod("AutoCounterMetric")) .IsTrue() .Because("the generated metrics class must contain the auto-counter method"); await Assert @@ -287,7 +287,7 @@ interface ITestMetrics var query = generationResult.Generated(); var metricsClass = query.GetClass("TestMetricsCore", "Testing"); await Assert - .That(metricsClass.HasMethod(query, "AutoCounterMetric")) + .That(metricsClass.HasMethod("AutoCounterMetric")) .IsTrue() .Because("the generated metrics class must contain the auto-counter method"); await Assert @@ -323,7 +323,7 @@ interface ITestMetrics var query = generationResult.Generated(); var metricsClass = query.GetClass("TestMetricsCore", "Testing"); await Assert - .That(metricsClass.HasMethod(query, "AutoCounterMetric")) + .That(metricsClass.HasMethod("AutoCounterMetric")) .IsTrue() .Because("the generated metrics class must contain the auto-counter method"); await Assert @@ -361,7 +361,7 @@ interface ITestMetrics var query = generationResult.Generated(); var metricsClass = query.GetClass("TestMetricsCore", "Testing"); await Assert - .That(metricsClass.HasMethod(query, "AutoCounterMetric")) + .That(metricsClass.HasMethod("AutoCounterMetric")) .IsTrue() .Because("the generated metrics class must contain the auto-counter method"); await Assert @@ -397,7 +397,7 @@ interface ITestMetrics var query = generationResult.Generated(); var metricsClass = query.GetClass("TestMetricsCore", "Testing"); await Assert - .That(metricsClass.HasMethod(query, "AutoCounterMetric")) + .That(metricsClass.HasMethod("AutoCounterMetric")) .IsTrue() .Because("the generated metrics class must contain the auto-counter method"); await Assert diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.NameUnitsDescription.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.NameUnitsDescription.cs index 35eb7a95..1e60b42d 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.NameUnitsDescription.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.NameUnitsDescription.cs @@ -33,7 +33,7 @@ public interface ITestMetrics { var query = generationResult.Generated(); var metricsClass = query.GetClass("TestMetricsCore", "Testing"); await Assert - .That(metricsClass.HasMethod(query, "Metric")) + .That(metricsClass.HasMethod("Metric")) .IsTrue() .Because("the generated metrics class must contain the instrument method"); diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.ObservableSpecific.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.ObservableSpecific.cs index c7932b8b..95707c5f 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.ObservableSpecific.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.ObservableSpecific.cs @@ -33,15 +33,15 @@ public interface ITestMetrics var query = generationResult.Generated(); var metricsClass = query.GetClass("TestMetricsCore", "Testing"); await Assert - .That(metricsClass.HasMethod(query, "Counter")) + .That(metricsClass.HasMethod("Counter")) .IsTrue() .Because("the generated metrics class must contain the observable counter method"); await Assert - .That(metricsClass.HasMethod(query, "Gauge")) + .That(metricsClass.HasMethod("Gauge")) .IsTrue() .Because("the generated metrics class must contain the observable gauge method"); await Assert - .That(metricsClass.HasMethod(query, "UpDown")) + .That(metricsClass.HasMethod("UpDown")) .IsTrue() .Because("the generated metrics class must contain the observable up-down counter method"); } @@ -78,15 +78,15 @@ public interface ITestMetrics { var query = generationResult.Generated(); var metricsClass = query.GetClass("TestMetricsCore", "Testing"); await Assert - .That(metricsClass.HasMethod(query, "Counter")) + .That(metricsClass.HasMethod("Counter")) .IsTrue() .Because("the generated metrics class must contain the observable counter method"); await Assert - .That(metricsClass.HasMethod(query, "Gauge")) + .That(metricsClass.HasMethod("Gauge")) .IsTrue() .Because("the generated metrics class must contain the observable gauge method"); await Assert - .That(metricsClass.HasMethod(query, "UpDown")) + .That(metricsClass.HasMethod("UpDown")) .IsTrue() .Because("the generated metrics class must contain the observable up-down counter method"); } diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.TagListCount.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.TagListCount.cs index 42ad3dbf..34cbf1d6 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.TagListCount.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.TagListCount.cs @@ -58,7 +58,7 @@ public interface ITestMetrics foreach (var methodName in autoCounters) { await Assert - .That(metricsClass.HasMethod(query, methodName)) + .That(metricsClass.HasMethod(methodName)) .IsTrue() .Because($"the generated metrics class must contain the {methodName} method"); } diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.UpDown.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.UpDown.cs index 31897663..f134157a 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.UpDown.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.UpDown.cs @@ -33,7 +33,6 @@ public interface ITestMetrics { await Assert .That( metricsClass.HasMethod( - query, "UpDown", TypeReference.Create(), TypeReference.Create(), @@ -45,7 +44,6 @@ await Assert await Assert .That( metricsClass.HasMethod( - query, "UpDown2", TypeReference.Create(), TypeReference.Create(), @@ -88,15 +86,15 @@ public interface ITestMetrics { var query = generationResult.Generated(); var metricsClass = query.GetClass("TestMetricsCore", "Testing"); await Assert - .That(metricsClass.HasMethod(query, "ObservableUpDown")) + .That(metricsClass.HasMethod("ObservableUpDown")) .IsTrue() .Because("the generated metrics class must contain the observable up-down counter method"); await Assert - .That(metricsClass.HasMethod(query, "ObservableUpDown2")) + .That(metricsClass.HasMethod("ObservableUpDown2")) .IsTrue() .Because("the generated metrics class must contain the second observable up-down counter method"); await Assert - .That(metricsClass.HasMethod(query, "ObservableUpDown3")) + .That(metricsClass.HasMethod("ObservableUpDown3")) .IsTrue() .Because("the generated metrics class must contain the third observable up-down counter method"); } diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.cs index 7ee2541a..d4e28678 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorMetricsTests.cs @@ -55,35 +55,35 @@ public interface ITestMetrics var query = generationResult.Generated(); var metricsClass = query.GetClass("TestMetricsCore", "Testing"); await Assert - .That(metricsClass.HasMethod(query, "AutoCounter")) + .That(metricsClass.HasMethod("AutoCounter")) .IsTrue() .Because("the generated metrics class must contain the auto-counter method"); await Assert - .That(metricsClass.HasMethod(query, "Counter_AutoIncrement")) + .That(metricsClass.HasMethod("Counter_AutoIncrement")) .IsTrue() .Because("the generated metrics class must contain the auto-increment counter method"); await Assert - .That(metricsClass.HasMethod(query, "Counter")) + .That(metricsClass.HasMethod("Counter")) .IsTrue() .Because("the generated metrics class must contain the counter method"); await Assert - .That(metricsClass.HasMethod(query, "Histogram")) + .That(metricsClass.HasMethod("Histogram")) .IsTrue() .Because("the generated metrics class must contain the histogram method"); await Assert - .That(metricsClass.HasMethod(query, "UpDownCounter")) + .That(metricsClass.HasMethod("UpDownCounter")) .IsTrue() .Because("the generated metrics class must contain the up-down counter method"); await Assert - .That(metricsClass.HasMethod(query, "ObservableCounter")) + .That(metricsClass.HasMethod("ObservableCounter")) .IsTrue() .Because("the generated metrics class must contain the observable counter method"); await Assert - .That(metricsClass.HasMethod(query, "ObservableGauge")) + .That(metricsClass.HasMethod("ObservableGauge")) .IsTrue() .Because("the generated metrics class must contain the observable gauge method"); await Assert - .That(metricsClass.HasMethod(query, "ObservableUpDownCounter")) + .That(metricsClass.HasMethod("ObservableUpDownCounter")) .IsTrue() .Because("the generated metrics class must contain the observable up-down counter method"); } diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorTests.InvalidReturnTypes.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorTests.InvalidReturnTypes.cs index 5a68727f..54e79f89 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorTests.InvalidReturnTypes.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorTests.InvalidReturnTypes.cs @@ -272,7 +272,7 @@ public interface IInvalidTelemetry var query = generationResult.Generated(); var loggerClass = query.GetClass("InvalidTelemetryCore", "Testing"); await Assert - .That(loggerClass.HasMethod(query, "ValidNonScopedLog", TypeReference.Create())) + .That(loggerClass.HasMethod("ValidNonScopedLog", TypeReference.Create())) .IsTrue() .Because("the generated logger must contain the valid non-scoped log method"); } diff --git a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorTests.cs b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorTests.cs index 410be0a3..521750d3 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorTests.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Generators/TelemetrySourceGeneratorTests.cs @@ -5,6 +5,31 @@ namespace Purview.Telemetry.SourceGenerator; public partial class TelemetrySourceGeneratorTests : IncrementalSourceGeneratorTestBase { + [Test] + public async Task Generate_GivenGeneratedAttributes_GeneratesWithGenerationAttributes( + CancellationToken cancellationToken + ) + { + // Arrange + const string empty = "namespace Testing;"; + var generatedAttributes = TypeLibrary.Purview.Telemetry.GetTypes().Select(m => m.Identity); + + // Act + var generationResult = await GenerateAsync(empty, cancellationToken: cancellationToken); + var query = generationResult.Generated(); + + // Assert + foreach (var type in generatedAttributes) + { + var generatedType = query.GetTypeDeclaration(type); + + await Assert.That(generatedType).IsNotNull().Because($"the {type.Name} must be generated"); + + var attributes = query.GetAttributes(generatedType); + await Assert.That(attributes).IsNotEmpty(); + } + } + [Test] public async Task Generate_GivenGeneratedAttributes_GeneratesAsExpected(CancellationToken cancellationToken) { diff --git a/src/tests/SourceGenerator.IntegrationTests/Infra/TelemetrySourceGeneratorTestOptions.cs b/src/tests/SourceGenerator.IntegrationTests/Infra/TelemetrySourceGeneratorTestOptions.cs index cd56f770..e69f158f 100644 --- a/src/tests/SourceGenerator.IntegrationTests/Infra/TelemetrySourceGeneratorTestOptions.cs +++ b/src/tests/SourceGenerator.IntegrationTests/Infra/TelemetrySourceGeneratorTestOptions.cs @@ -2,9 +2,7 @@ using System.Diagnostics.Metrics; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Purview.SourceGeneratorFramework; using Purview.Telemetry.SourceGenerator.Analyzers; -using Purview.Telemetry.SourceGenerator.Helpers; namespace Purview.Telemetry.SourceGenerator.Infra; @@ -33,11 +31,8 @@ public TelemetrySourceGeneratorTestOptions() ExcludeGeneratedSourceHintNames = [ - PurviewTypeLibrary.Microsoft.CodeAnalysis.EmbeddedAttribute, - .. TypeLibrary.TelemetryShared.GetGeneratedTypes().Select(c => c.MetadataFullName), - .. TypeLibrary.Activities.GetGeneratedTypes().Select(c => c.MetadataFullName), - .. TypeLibrary.Logging.GetGeneratedTypes().Select(c => c.MetadataFullName), - .. TypeLibrary.Metrics.GetGeneratedTypes().Select(c => c.MetadataFullName), + TypeLibrary.Microsoft.CodeAnalysis.EmbeddedAttribute, + .. TypeLibrary.Purview.Telemetry.GetTypes().Select(c => c.Identity.MetadataFullName), ]; } From 9ab479e6638f0e51b2464da4aaac131cb43942e1 Mon Sep 17 00:00:00 2001 From: Kieron Lanning Date: Tue, 8 Sep 2026 08:01:03 +0100 Subject: [PATCH 2/2] feat: add Purview telemetry attributes to TypeLibraryGenerator --- .../TypeLibraryGenerator.PurviewGenTypes.cs | 119 ++++++++++++++++++ .../Helpers/TypeLibraryGenerator.cs | 116 ----------------- 2 files changed, 119 insertions(+), 116 deletions(-) create mode 100644 src/src/SourceGenerator/Helpers/TypeLibraryGenerator.PurviewGenTypes.cs diff --git a/src/src/SourceGenerator/Helpers/TypeLibraryGenerator.PurviewGenTypes.cs b/src/src/SourceGenerator/Helpers/TypeLibraryGenerator.PurviewGenTypes.cs new file mode 100644 index 00000000..b66f4f20 --- /dev/null +++ b/src/src/SourceGenerator/Helpers/TypeLibraryGenerator.PurviewGenTypes.cs @@ -0,0 +1,119 @@ +namespace Purview.Telemetry.SourceGenerator.Helpers; + +partial class TypeLibraryGenerator +{ + // Activities + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity ActivitySourceGenerationAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity ActivitySourceAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity ActivityAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity EventAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity ContextAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity BaggageAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity EscapeAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity StatusDescriptionAttribute = default; + + // Logging + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity LoggerGenerationAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity LoggerAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity LogAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity LogPrefixType = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity LoggerGenerationMode = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity ExpandEnumerableAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity TraceAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity DebugAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity InfoAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity WarningAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity ErrorAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity CriticalAttribute = default; + + // Metric + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity MeterGenerationAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity MeterAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity MeterNameGenerationType = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity InstrumentMeasurementAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity AutoCounterAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity CounterAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity UpDownCounterAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity HistogramAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity ObservableCounterAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity ObservableUpDownCounterAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity ObservableGaugeAttribute = default; + + // Shared + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity TagAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity ExcludeAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity TelemetryGenerationAttribute = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity Targets = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity NamingConvention = default; + + [TypeRef(PurviewTelemetryNamespace, includeInGetTypes: true)] + static readonly TypeIdentity ExcludeTargetsAttribute = default; +} diff --git a/src/src/SourceGenerator/Helpers/TypeLibraryGenerator.cs b/src/src/SourceGenerator/Helpers/TypeLibraryGenerator.cs index c828e994..a99b35b1 100644 --- a/src/src/SourceGenerator/Helpers/TypeLibraryGenerator.cs +++ b/src/src/SourceGenerator/Helpers/TypeLibraryGenerator.cs @@ -7,120 +7,4 @@ static partial class TypeLibraryGenerator const string LoggingNamespace = "Microsoft.Extensions.Logging"; const string SystemDiagnosticsNamespace = "System.Diagnostics"; const string SystemDiagnosticsMetricsNamespace = "System.Diagnostics.Metrics"; - - // Purview Telemetry types - // Activities - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity ActivitySourceGenerationAttribute = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity ActivitySourceAttribute = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity ActivityAttribute = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity EventAttribute = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity ContextAttribute = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity BaggageAttribute = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity EscapeAttribute = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity StatusDescriptionAttribute = default; - - // Logging - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity LoggerGenerationAttribute = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity LoggerAttribute = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity LogAttribute = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity LogPrefixType = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity LoggerGenerationMode = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity ExpandEnumerableAttribute = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity TraceAttribute = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity DebugAttribute = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity InfoAttribute = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity WarningAttribute = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity ErrorAttribute = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity CriticalAttribute = default; - - // Metric - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity MeterGenerationAttribute = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity MeterAttribute = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity MeterNameGenerationType = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity InstrumentMeasurementAttribute = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity AutoCounterAttribute = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity CounterAttribute = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity UpDownCounterAttribute = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity HistogramAttribute = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity ObservableCounterAttribute = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity ObservableUpDownCounterAttribute = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity ObservableGaugeAttribute = default; - - // Shared - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity TagAttribute = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity ExcludeAttribute = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity TelemetryGenerationAttribute = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity Targets = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity NamingConvention = default; - - [TypeRef(PurviewTelemetryNamespace, IncludeInGetTypes = true)] - static readonly TypeIdentity ExcludeTargetsAttribute = default; }