Skip to content

Commit 4d1a54a

Browse files
Merge pull request #56 from purview-dev/updated-sample-app
Updated sample app + docs
2 parents e216600 + 20c1810 commit 4d1a54a

8 files changed

Lines changed: 90 additions & 26 deletions

File tree

.vscode/extensions.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
{
2-
"recommendations": [
3-
"ms-dotnettools.csdevkit",
4-
"github.vscode-github-actions",
5-
"github.vscode-pull-request-github"
6-
]
7-
}
2+
"recommendations": [
3+
"ms-dotnettools.csdevkit",
4+
"github.vscode-github-actions",
5+
"github.vscode-pull-request-github",
6+
"streetsidesoftware.code-spell-checker",
7+
"bierner.github-markdown-preview",
8+
"davidanson.vscode-markdownlint",
9+
"pkief.material-icon-theme",
10+
"esbenp.prettier-vscode"
11+
]
12+
}

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SOLUTION_FILE = $(ROOT_FOLDER)Purview.Telemetry.SourceGenerator.sln
66
TEST_PROJECT = $(ROOT_FOLDER)Purview.Telemetry.SourceGenerator.sln
77
CONFIGURATION = Release
88

9-
PACK_VERSION = 2.0.0
9+
PACK_VERSION := $(shell bun -e 'console.log(require("./package.json").version)')
1010
ARTIFACT_FOLDER = p:/sync-projects/.local-nuget/
1111

1212
# Common variables
@@ -46,8 +46,11 @@ act:
4646

4747
vs: ## Opens the project in Visual Studio.
4848
@echo -e "Opening $(COLOUR_BLUE)$(SOLUTION_FILE)$(COLOUR_RESET) in $(COLOUR_ORANGE)Visual Studio$(COLOUR_RESET)..."
49-
@start $(SOLUTION_FILE)
49+
@start "$(SOLUTION_FILE)"
5050

5151
code: ## Opens the project in Visual Studio Code.
5252
@echo -e "Opening $(COLOUR_BLUE)Visual Studio Code$(COLOUR_RESET)..."
5353
@code .
54+
55+
version: ## Displays the current version of the project.
56+
@echo -e "Current Version: $(COLOUR_GREEN)$(PACK_VERSION)$(COLOUR_RESET)"

README.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@
22

33
Generates [ActivitySource](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.activitysource), [High-performance logging](https://learn.microsoft.com/en-us/dotnet/core/extensions/high-performance-logging) and [Metrics](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.metrics) based on methods on an interface, enabling fast iteration cycles, dependency injection and substitutes for testing.
44

5-
The latest version is available on [NuGet](https://www.nuget.org/packages/Purview.Telemetry.SourceGenerator/), and supports generating for the following frameworks:
5+
The latest version is available on [NuGet](https://www.nuget.org/packages/Purview.Telemetry.SourceGenerator/), and supports generation for the following frameworks:
66

7-
* .NET Framework 4.7.2
8-
* .NET Framework 4.8
9-
* .NET 8
10-
* .NET 9
7+
- .NET Framework 4.7.2
8+
- .NET Framework 4.8
9+
- .NET 8
10+
- .NET 9
1111

12-
Reference in your .props or csproj file:
12+
Reference in your `Directory.Build.props` or `.csproj` file:
1313

1414
```xml
15-
<PackageReference Include="Purview.Telemetry.SourceGenerator" Version="2.0.0">
15+
<PackageReference Include="Purview.Telemetry.SourceGenerator" Version="2.0.1">
1616
<PrivateAssets>all</PrivateAssets>
1717
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
1818
</PackageReference>
1919
```
2020

21+
Example of a multi-target telemetry interface:
22+
2123
```csharp
2224
using Purview.Telemetry.Activities;
2325
using Purview.Telemetry.Logging;
@@ -68,6 +70,10 @@ interface IEntityStoreTelemetry
6870

6971
For more information see the [wiki](https://github.com/purview-dev/purview-telemetry-sourcegenerator/wiki).
7072

73+
> To see the generated output for the above, see the [`Generated Output`](https://github.com/purview-dev/purview-telemetry-sourcegenerator/wiki/Generated-Output) page in the wiki.
74+
75+
## Example Project
76+
7177
Checkout the [.NET Aspire Sample](https://github.com/purview-dev/purview-telemetry-sourcegenerator/tree/main/samples/SampleApp) Project to see the Activities, Logging, and Metrics working with the Aspire Dashboard.
7278

7379
> This sample project has `EmitCompilerGeneratedFiles` set to `true`, so you can easily see the generated output.

bun.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "purview-telemetry-sourcegenerator",
3-
"version": "1.0.0",
3+
"version": "2.0.1",
44
"description": "Generates [ActivitySource](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.activitysource), [High-performance logging](https://learn.microsoft.com/en-us/dotnet/core/extensions/high-performance-logging) and [Metrics](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.metrics) based on methods on an interface, enabling fast iteration cycles, dependency injection and substitutes for testing.",
55
"main": "index.js",
66
"scripts": {
@@ -18,10 +18,10 @@
1818
},
1919
"homepage": "https://github.com/purview-dev/purview-telemetry-sourcegenerator#readme",
2020
"devDependencies": {
21-
"@commitlint/cli": "^19.6.1",
22-
"@commitlint/config-conventional": "^19.6.0",
21+
"@commitlint/cli": "^19.7.1",
22+
"@commitlint/config-conventional": "^19.7.1",
2323
"commit-and-tag-version": "^12.5.0",
24-
"commitlint": "^19.6.1",
24+
"commitlint": "^19.7.1",
2525
"husky": "^9.1.7"
2626
},
2727
"commitlint": {

samples/SampleApp/SampleApp.Host/SampleApp.Host.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
88
<GenerateDocumentationFile>true</GenerateDocumentationFile>
9-
<NoWarn>$(NoWarn);CS1591;</NoWarn>
9+
<NoWarn>$(NoWarn);CS1591</NoWarn>
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="Purview.Telemetry.SourceGenerator" Version="2.0.0">
13+
<PackageReference Include="Purview.Telemetry.SourceGenerator" Version="2.0.1">
1414
<PrivateAssets>all</PrivateAssets>
1515
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
1616
</PackageReference>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System.Diagnostics;
2+
using Purview.Telemetry.Activities;
3+
using Purview.Telemetry.Logging;
4+
using Purview.Telemetry.Metrics;
5+
6+
namespace SampleApp.Host.Services;
7+
8+
[ActivitySource]
9+
[Logger]
10+
[Meter]
11+
interface IEntityStoreTelemetry
12+
{
13+
/// <summary>
14+
/// Creates and starts an Activity and adds the parameters as Tags and Baggage.
15+
/// </summary>
16+
[Activity]
17+
Activity? GettingEntityFromStore(int entityId, [Baggage] string serviceUrl);
18+
19+
/// <summary>
20+
/// Adds an ActivityEvent to the Activity with the parameters as Tags.
21+
/// </summary>
22+
[Event]
23+
void GetDuration(Activity? activity, int durationInMS);
24+
25+
/// <summary>
26+
/// Adds the parameters as Baggage to the Activity.
27+
/// </summary>
28+
[Context]
29+
void RetrievedEntity(Activity? activity, float totalValue, int lastUpdatedByUserId);
30+
31+
/// <summary>
32+
/// Generates a structured log message using an ILogger - defaults to Informational.
33+
/// </summary>
34+
[Log]
35+
void ProcessingEntity(int entityId, string updateState);
36+
37+
/// <summary>
38+
/// Generates a structured log message using an ILogger, specifically defined as Informational.
39+
/// </summary>
40+
[Info]
41+
void ProcessingAnotherEntity(int entityId, string updateState);
42+
43+
/// <summary>
44+
/// Adds 1 to a Counter{T} with the entityId as a Tag.
45+
/// </summary>
46+
[AutoCounter]
47+
void RetrievingEntity(int entityId);
48+
}

src/Purview.Telemetry.SourceGenerator/Purview.Telemetry.SourceGenerator.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
<Title>Purview Telemetry Source Generator</Title>
1515
<Description>.NET Source Generator for interface-based telemetry building activities, activity events, logs and metrics.</Description>
1616
<PackageIcon>purview-logo.png</PackageIcon>
17+
<DevelopmentDependency>true</DevelopmentDependency>
18+
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
1719

1820
<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
1921
<IsRoslynComponent>true</IsRoslynComponent>

0 commit comments

Comments
 (0)