Skip to content

Commit

Permalink
Merge pull request #21 from purview-dev/fix-generic-parameters
Browse files Browse the repository at this point in the history
Fix generic parameters
  • Loading branch information
kieronlanning authored Apr 30, 2024
2 parents 1ac75a6 + b36de94 commit 7aff205
Show file tree
Hide file tree
Showing 871 changed files with 54,645 additions and 141 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SOLUTION_FILE = $(ROOT_FOLDER)Purview.Telemetry.SourceGenerator.sln
TEST_PROJECT = $(ROOT_FOLDER)Purview.Telemetry.SourceGenerator.sln
CONFIGURATION = Release

PACK_VERSION = 1.0.2
PACK_VERSION = 1.0.3
ARTIFACT_FOLDER = p:/sync-projects/.local-nuget/

# Targets
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ interface IMeterTelemetry
[Counter]
void CounterMeter([InstrumentMeasurement]int measurement, [Tag]float someValue);

[AutoCounter]
void AutoCounterMeter([Tag]float someValue);

[Histogram]
void HistogramMeter([InstrumentMeasurement]int measurement, [Tag]int someValue, [Tag]bool anotherValue);

Expand Down
24 changes: 20 additions & 4 deletions docs/METRICS.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The signature is: `partial void PopulateMeterTags(System.Collections.Generic.Dic

There are several supported meter types: counter, histogram, up-down counter, observable counter, observable gauge and observable up-down counter. Each are determined by the corresponding attribute:

* `CounterAttribute` generates the [Counter<T>](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.metrics.counter-1) instrument.
* `AutoCounterAttribute` and `CounterAttribute` generates the [Counter<T>](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.metrics.counter-1) instrument.
* `HistogramAttribute` generates the [Histogram<T>](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.metrics.histogram-1) instrument.
* `UpDownCounterAttribute` generates the [UpDownCounter<T>](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.metrics.updowncounter-1) instrument.
* `ObservableCounterAttribute` generates the [ObservableCounter<T>](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.metrics.observablecounter-1) instrument.
Expand All @@ -36,13 +36,13 @@ The measurement type used by the meter must be one of the following: `byte`, `sh

This is determined by decorating the desired parameter with the `InstrumentMeasurementAttribute`.

#### Counter, Histogram and Up/Down Counter
#### AutoCount, Counter, Histogram and Up/Down Counter

All of these counters types require a measurement parameter, with the exception of the counter when `CounterAttribute.AutoIncrement` is set to true.
All of these counters types require a measurement parameter, with the exception of the counter when `AutoCounterAttribute` is present, or `CounterAttribute.AutoIncrement` is set to true.

If a measurement parameter is not defined, the first parameter with a matching type is used.

When using `CounterAttribute.AutoIncrement`, the meter increments by one each time the method is called.
When using `AutoCounterAttribute` or `CounterAttribute.AutoIncrement`, the meter increments by one each time the method is called.

#### ObservableCounter, ObservableGauge and ObservableUpDownCounter

Expand Down Expand Up @@ -71,6 +71,20 @@ Other parameters on the method can be used as tags. This is implicit for non-mea

## Types

### AutoCounterAttribute

Used to create a `Counter<T>` meter, where `T` is an `int`.

| Name | Type | Description |
| -- | -- | -- |
| Name | `string?` | Determines the name of the meter. If this is not provided, the name of the method is used. Also available on construction. Defaults to `null`. |
| Unit | `string?` | Specifies the Unit used during meter generation. Also available on construction. Defaults to `null`. |
| Description | `string?` | Specifies the Description used during meter generation. Also available on construction. Defaults to `null`. |

This is the equivalent of using the `CounterAttribute` and setting `AutoIncrement` to `true`.

When specifying an `[InstrumentMeasurementAttribute]` on a parameter, the `TSG4002` diagnostic is raised.

### CounterAttribute

Used to create a `Counter<T>` meter.
Expand All @@ -82,6 +96,8 @@ Used to create a `Counter<T>` meter.
| Unit | `string?` | Specifies the Unit used during meter generation. Also available on construction. Defaults to `null`. |
| Description | `string?` | Specifies the Description used during meter generation. Also available on construction. Defaults to `null`. |

When `AutoIncrement` is `true` and an `[InstrumentMeasurementAttribute]` is used on a parameter, the `TSG4002` diagnostic is raised.

### HistogramAttribute

Used to create a `Histogram<T>` meter.
Expand Down
22 changes: 15 additions & 7 deletions src/.build-system/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<EmbedUntrackedSources>true</EmbedUntrackedSources>

<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>

<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>

<IsPackable>false</IsPackable>
Expand All @@ -27,7 +28,8 @@
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
<AnalysisLevel>5</AnalysisLevel>

<NoWarn>IDE0011;$(NoWarn)</NoWarn>
<NoWarn>AD0001;$(NoWarn)</NoWarn>
<NoWarn>IDE2001;$(NoWarn)</NoWarn>
<NoWarn>CS1591;$(NoWarn)</NoWarn>
<NoWarn>CA1014;CA1848;CA2007;CA2201;CA2234;CA2225;CA2254;$(NoWarn)</NoWarn>
<NoWarn>RCS1090;RCS1108;$(NoWarn)</NoWarn>
Expand All @@ -44,15 +46,21 @@

</PropertyGroup>

<ItemGroup Label="C# Project Item Groups" Condition="'$(IsCSharpProject)' == 'true'">
<ItemGroup>

<Using Include="$(RootNamespace)" />

</ItemGroup>

<ItemGroup Label="C# Project Item Groups" Condition="'$(IsCSharpProject)' == 'true' AND $(IsTestProject) == 'false'">

<!-- Embedded Resources -->
<None Remove="Resources/**/*" />
<EmbeddedResource Include="Resources/**/*" />

</ItemGroup>

<ItemGroup Label="Dynamic Versioning" Condition="'$(IsCSharpProject)' == 'true'">
<ItemGroup Label="Dynamic Versioning" Condition="'$(IsCSharpProject)' == 'true' AND '$(IsTestProject)' == 'false'">

<Compile Include="$(AutoMSBuildProps)AssemblyInfo_Shared.cs" Link="Properties/SharedAssemblyInfo.cs" />

Expand Down Expand Up @@ -84,10 +92,7 @@
<!-- Test Projects. -->
<PropertyGroup Label="Testing Project Properties" Condition="'$(IsTestProject)' == 'true'">

<NoWarn>CA1701;CA1702;CA1705;CA1707;CA1806;CA2000;$(NoWarn)</NoWarn>
<NoWarn>IDE0001;IDE0007;$(NoWarn)</NoWarn>
<NoWarn>RCS1001;RCS1003;RCS1010;RCS1018;$(NoWarn)</NoWarn>
<NoWarn>VSTHRD200;$(NoWarn)</NoWarn>
<NoWarn>$(NoWarn);CA1707</NoWarn>

<CollectCoverage>true</CollectCoverage>
<CoverletOutput Condition=" '$(OutputPath)' != '' ">$(OutputPath)/</CoverletOutput>
Expand All @@ -99,6 +104,9 @@
<IsPackable>false</IsPackable>
<IsPublishable>false</IsPublishable>

<EnableStaticNativeInstrumentation>False</EnableStaticNativeInstrumentation>
<EnableDynamicNativeInstrumentation>False</EnableDynamicNativeInstrumentation>

</PropertyGroup>

<ItemGroup Label="Test AssemblyInfo and Runner Properties" Condition="'$(IsTestProject)' == 'true'">
Expand Down
4 changes: 2 additions & 2 deletions src/.build-system/msbuild/Properties/AssemblyInfo_Shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]

[assembly: AssemblyCompany("Purview")]
[assembly: AssemblyCopyright("Purview © 2024 | All rights reserved.")]
[assembly: AssemblyCompany("Purview Consultancy")]
[assembly: AssemblyCopyright("KJL Solutions Ltd. © 2024 | All rights reserved.")]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

[assembly: ExcludeFromCodeCoverage]

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0057:Use range operator")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
2 changes: 1 addition & 1 deletion src/.build-system/msbuild/nuget-packable-default.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>

<PropertyGroup Label="NuGet Package Defaults">

<Authors>Kieron Lanning</Authors>
<Company>KJL Solutions Ltd.</Company>
<Copyright>KJL Solutions Ltd., 2024 | All rights reserved.</Copyright>
Expand Down
27 changes: 13 additions & 14 deletions src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ dotnet_remove_unnecessary_suppression_exclusions = none
[*.cs]

# var preferences
csharp_style_var_elsewhere = false:silent
csharp_style_var_for_built_in_types = false:silent
csharp_style_var_when_type_is_apparent = false:silent
csharp_style_var_elsewhere = true
csharp_style_var_for_built_in_types = true
csharp_style_var_when_type_is_apparent = true

# Expression-bodied members
csharp_style_expression_bodied_accessors = true:silent
Expand All @@ -117,7 +117,7 @@ csharp_prefer_static_local_function = true:warning
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:silent

# Code-block preferences
csharp_prefer_braces = true:silent
csharp_prefer_braces = false:suggestion
csharp_prefer_simple_using_statement = true:suggestion

# Expression-level preferences
Expand Down Expand Up @@ -180,6 +180,11 @@ csharp_space_between_square_brackets = false
# Wrapping preferences
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = true
csharp_style_namespace_declarations = file_scoped:silent
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_prefer_primary_constructors = true:suggestion
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true:silent

#### Naming styles ####
[*.{cs,vb}]
Expand Down Expand Up @@ -228,7 +233,7 @@ dotnet_naming_rule.public_fields_should_be_pascalcase.style = pascalcase

dotnet_naming_rule.private_fields_should_be__camelcase.severity = suggestion
dotnet_naming_rule.private_fields_should_be__camelcase.symbols = private_fields
dotnet_naming_rule.private_fields_should_be__camelcase.style = _camelcase
dotnet_naming_rule.private_fields_should_be__camelcase.style = prefix_underscore

dotnet_naming_rule.private_static_fields_should_be_s_camelcase.severity = suggestion
dotnet_naming_rule.private_static_fields_should_be_s_camelcase.symbols = private_static_fields
Expand Down Expand Up @@ -371,13 +376,7 @@ dotnet_naming_style.s_camelcase.required_prefix = s_
dotnet_naming_style.s_camelcase.required_suffix =
dotnet_naming_style.s_camelcase.word_separator =
dotnet_naming_style.s_camelcase.capitalization = camel_case
tab_width = 4
indent_size = 4
end_of_line = crlf

# Verify settings
[*.{received,verified}.{txt,xml,json}]
charset = "utf-8-bom"
end_of_line = lf
indent_size = unset
indent_style = unset
insert_final_newline = false
tab_width = unset
trim_trailing_whitespace = false
1 change: 0 additions & 1 deletion src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.0" />
</ItemGroup>
<ItemGroup Label="Testing">
<PackageVersion Include="CompareNETObjects" Version="4.83.0" />
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageVersion Include="Microsoft.CodeCoverage" Version="17.9.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface ITestActivities {
";

// Act
GenerationResult generationResult = await GenerateAsync(basicActivity);
var generationResult = await GenerateAsync(basicActivity);

// Assert
await TestHelpers.Verify(generationResult);
Expand All @@ -43,7 +43,7 @@ public interface ITestActivities {
";

// Act
GenerationResult generationResult = await GenerateAsync(basicActivity);
var generationResult = await GenerateAsync(basicActivity);

// Assert
await TestHelpers.Verify(generationResult);
Expand All @@ -70,7 +70,7 @@ public interface ITestActivities {
";

// Act
GenerationResult generationResult = await GenerateAsync(basicActivity);
var generationResult = await GenerateAsync(basicActivity);

// Assert
await TestHelpers.Verify(generationResult);
Expand All @@ -97,7 +97,7 @@ public interface ITestActivities {
";

// Act
GenerationResult generationResult = await GenerateAsync(basicActivity);
var generationResult = await GenerateAsync(basicActivity);

// Assert
await TestHelpers.Verify(generationResult);
Expand All @@ -124,7 +124,7 @@ public interface ITestActivities {
";

// Act
GenerationResult generationResult = await GenerateAsync(basicActivity);
var generationResult = await GenerateAsync(basicActivity);

// Assert
await TestHelpers.Verify(generationResult);
Expand All @@ -151,7 +151,7 @@ public interface ITestActivities {
";

// Act
GenerationResult generationResult = await GenerateAsync(basicActivity);
var generationResult = await GenerateAsync(basicActivity);

// Assert
await TestHelpers.Verify(generationResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public interface ITestActivities {
";

// Act
GenerationResult generationResult = await GenerateAsync(basicActivity);
var generationResult = await GenerateAsync(basicActivity);

// Assert
await TestHelpers.Verify(generationResult);
Expand All @@ -44,7 +44,7 @@ public interface ITestActivities {
";

// Act
GenerationResult generationResult = await GenerateAsync(basicActivity);
var generationResult = await GenerateAsync(basicActivity);

// Assert
await TestHelpers.Verify(generationResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public interface ITestActivities {
";

// Act
GenerationResult generationResult = await GenerateAsync(basicActivity);
var generationResult = await GenerateAsync(basicActivity);

// Assert
await TestHelpers.Verify(generationResult);
Expand All @@ -49,7 +49,7 @@ public interface ITestActivities
";

// Act
GenerationResult generationResult = await GenerateAsync(basicActivity);
var generationResult = await GenerateAsync(basicActivity);

// Assert
await TestHelpers.Verify(generationResult);
Expand Down Expand Up @@ -78,7 +78,7 @@ public interface ITestActivities {
";

// Act
GenerationResult generationResult = await GenerateAsync(basicActivity);
var generationResult = await GenerateAsync(basicActivity);

// Assert
await TestHelpers.Verify(generationResult, s => s.ScrubInlineGuids(), validateNonEmptyDiagnostics: true);
Expand All @@ -105,7 +105,7 @@ public interface ITestActivities {
";

// Act
GenerationResult generationResult = await GenerateAsync(basicActivity);
var generationResult = await GenerateAsync(basicActivity);

// Assert
await TestHelpers.Verify(generationResult);
Expand All @@ -132,7 +132,7 @@ public interface ITestActivities {
";

// Act
GenerationResult generationResult = await GenerateAsync(basicActivity);
var generationResult = await GenerateAsync(basicActivity);

// Assert
await TestHelpers.Verify(generationResult);
Expand All @@ -159,7 +159,7 @@ public interface ITestActivities {
";

// Act
GenerationResult generationResult = await GenerateAsync(basicActivity);
var generationResult = await GenerateAsync(basicActivity);

// Assert
await TestHelpers.Verify(generationResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface ITestActivities {
";

// Act
GenerationResult generationResult = await GenerateAsync(basicActivity, disableDependencyInjection: false);
var generationResult = await GenerateAsync(basicActivity, disableDependencyInjection: false);

// Assert
await TestHelpers.Verify(generationResult);
Expand All @@ -51,7 +51,7 @@ public interface ITestActivities {
";

// Act
GenerationResult generationResult = await GenerateAsync(basicActivity, disableDependencyInjection: false);
var generationResult = await GenerateAsync(basicActivity, disableDependencyInjection: false);

// Assert
await TestHelpers.Verify(generationResult);
Expand Down Expand Up @@ -80,7 +80,7 @@ public interface ITestActivities {
";

// Act
GenerationResult generationResult = await GenerateAsync(basicActivity, disableDependencyInjection: false);
var generationResult = await GenerateAsync(basicActivity, disableDependencyInjection: false);

// Assert
await TestHelpers.Verify(generationResult);
Expand Down Expand Up @@ -109,7 +109,7 @@ public interface ITestActivities {
";

// Act
GenerationResult generationResult = await GenerateAsync(basicActivity, disableDependencyInjection: false);
var generationResult = await GenerateAsync(basicActivity, disableDependencyInjection: false);

// Assert
await TestHelpers.Verify(generationResult);
Expand Down
Loading

0 comments on commit 7aff205

Please sign in to comment.