Skip to content

Commit

Permalink
Merge pull request #56 from purview-dev/updated-sample-app
Browse files Browse the repository at this point in the history
Updated sample app + docs
  • Loading branch information
kieronlanning authored Feb 2, 2025
2 parents e216600 + 20c1810 commit 4d1a54a
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 26 deletions.
17 changes: 11 additions & 6 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
"recommendations": [
"ms-dotnettools.csdevkit",
"github.vscode-github-actions",
"github.vscode-pull-request-github"
]
}
"recommendations": [
"ms-dotnettools.csdevkit",
"github.vscode-github-actions",
"github.vscode-pull-request-github",
"streetsidesoftware.code-spell-checker",
"bierner.github-markdown-preview",
"davidanson.vscode-markdownlint",
"pkief.material-icon-theme",
"esbenp.prettier-vscode"
]
}
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SOLUTION_FILE = $(ROOT_FOLDER)Purview.Telemetry.SourceGenerator.sln
TEST_PROJECT = $(ROOT_FOLDER)Purview.Telemetry.SourceGenerator.sln
CONFIGURATION = Release

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

# Common variables
Expand Down Expand Up @@ -46,8 +46,11 @@ act:

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

code: ## Opens the project in Visual Studio Code.
@echo -e "Opening $(COLOUR_BLUE)Visual Studio Code$(COLOUR_RESET)..."
@code .

version: ## Displays the current version of the project.
@echo -e "Current Version: $(COLOUR_GREEN)$(PACK_VERSION)$(COLOUR_RESET)"
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@

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.

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

* .NET Framework 4.7.2
* .NET Framework 4.8
* .NET 8
* .NET 9
- .NET Framework 4.7.2
- .NET Framework 4.8
- .NET 8
- .NET 9

Reference in your .props or csproj file:
Reference in your `Directory.Build.props` or `.csproj` file:

```xml
<PackageReference Include="Purview.Telemetry.SourceGenerator" Version="2.0.0">
<PackageReference Include="Purview.Telemetry.SourceGenerator" Version="2.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
```

Example of a multi-target telemetry interface:

```csharp
using Purview.Telemetry.Activities;
using Purview.Telemetry.Logging;
Expand Down Expand Up @@ -68,6 +70,10 @@ interface IEntityStoreTelemetry

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

> 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.
## Example Project

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.

> This sample project has `EmitCompilerGeneratedFiles` set to `true`, so you can easily see the generated output.
10 changes: 5 additions & 5 deletions bun.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

"@babel/helper-validator-identifier": ["@babel/[email protected]", "", {}, "sha512-Ed61U6XJc3CVRfkERJWDz4dJwKe7iLmmJsbOGu9wSloNSFttHV0I8g6UAgb7qnK5ly5bGLPd4oXZlxCdANBOWQ=="],

"@commitlint/cli": ["@commitlint/cli@19.6.1", "", { "dependencies": { "@commitlint/format": "^19.5.0", "@commitlint/lint": "^19.6.0", "@commitlint/load": "^19.6.1", "@commitlint/read": "^19.5.0", "@commitlint/types": "^19.5.0", "tinyexec": "^0.3.0", "yargs": "^17.0.0" }, "bin": { "commitlint": "cli.js" } }, "sha512-8hcyA6ZoHwWXC76BoC8qVOSr8xHy00LZhZpauiD0iO0VYbVhMnED0da85lTfIULxl7Lj4c6vZgF0Wu/ed1+jlQ=="],
"@commitlint/cli": ["@commitlint/cli@19.7.1", "", { "dependencies": { "@commitlint/format": "^19.5.0", "@commitlint/lint": "^19.7.1", "@commitlint/load": "^19.6.1", "@commitlint/read": "^19.5.0", "@commitlint/types": "^19.5.0", "tinyexec": "^0.3.0", "yargs": "^17.0.0" }, "bin": { "commitlint": "cli.js" } }, "sha512-iObGjR1tE/PfDtDTEfd+tnRkB3/HJzpQqRTyofS2MPPkDn1mp3DBC8SoPDayokfAy+xKhF8+bwRCJO25Nea0YQ=="],

"@commitlint/config-conventional": ["@commitlint/config-conventional@19.6.0", "", { "dependencies": { "@commitlint/types": "^19.5.0", "conventional-changelog-conventionalcommits": "^7.0.2" } }, "sha512-DJT40iMnTYtBtUfw9ApbsLZFke1zKh6llITVJ+x9mtpHD08gsNXaIRqHTmwTZL3dNX5+WoyK7pCN/5zswvkBCQ=="],
"@commitlint/config-conventional": ["@commitlint/config-conventional@19.7.1", "", { "dependencies": { "@commitlint/types": "^19.5.0", "conventional-changelog-conventionalcommits": "^7.0.2" } }, "sha512-fsEIF8zgiI/FIWSnykdQNj/0JE4av08MudLTyYHm4FlLWemKoQvPNUYU2M/3tktWcCEyq7aOkDDgtjrmgWFbvg=="],

"@commitlint/config-validator": ["@commitlint/[email protected]", "", { "dependencies": { "@commitlint/types": "^19.5.0", "ajv": "^8.11.0" } }, "sha512-CHtj92H5rdhKt17RmgALhfQt95VayrUo2tSqY9g2w+laAXyk7K/Ef6uPm9tn5qSIwSmrLjKaXK9eiNuxmQrDBw=="],

Expand All @@ -31,9 +31,9 @@

"@commitlint/format": ["@commitlint/[email protected]", "", { "dependencies": { "@commitlint/types": "^19.5.0", "chalk": "^5.3.0" } }, "sha512-yNy088miE52stCI3dhG/vvxFo9e4jFkU1Mj3xECfzp/bIS/JUay4491huAlVcffOoMK1cd296q0W92NlER6r3A=="],

"@commitlint/is-ignored": ["@commitlint/is-ignored@19.6.0", "", { "dependencies": { "@commitlint/types": "^19.5.0", "semver": "^7.6.0" } }, "sha512-Ov6iBgxJQFR9koOupDPHvcHU9keFupDgtB3lObdEZDroiG4jj1rzky60fbQozFKVYRTUdrBGICHG0YVmRuAJmw=="],
"@commitlint/is-ignored": ["@commitlint/is-ignored@19.7.1", "", { "dependencies": { "@commitlint/types": "^19.5.0", "semver": "^7.6.0" } }, "sha512-3IaOc6HVg2hAoGleRK3r9vL9zZ3XY0rf1RsUf6jdQLuaD46ZHnXBiOPTyQ004C4IvYjSWqJwlh0/u2P73aIE3g=="],

"@commitlint/lint": ["@commitlint/lint@19.6.0", "", { "dependencies": { "@commitlint/is-ignored": "^19.6.0", "@commitlint/parse": "^19.5.0", "@commitlint/rules": "^19.6.0", "@commitlint/types": "^19.5.0" } }, "sha512-LRo7zDkXtcIrpco9RnfhOKeg8PAnE3oDDoalnrVU/EVaKHYBWYL1DlRR7+3AWn0JiBqD8yKOfetVxJGdEtZ0tg=="],
"@commitlint/lint": ["@commitlint/lint@19.7.1", "", { "dependencies": { "@commitlint/is-ignored": "^19.7.1", "@commitlint/parse": "^19.5.0", "@commitlint/rules": "^19.6.0", "@commitlint/types": "^19.5.0" } }, "sha512-LhcPfVjcOcOZA7LEuBBeO00o3MeZa+tWrX9Xyl1r9PMd5FWsEoZI9IgnGqTKZ0lZt5pO3ZlstgnRyY1CJJc9Xg=="],

"@commitlint/load": ["@commitlint/[email protected]", "", { "dependencies": { "@commitlint/config-validator": "^19.5.0", "@commitlint/execute-rule": "^19.5.0", "@commitlint/resolve-extends": "^19.5.0", "@commitlint/types": "^19.5.0", "chalk": "^5.3.0", "cosmiconfig": "^9.0.0", "cosmiconfig-typescript-loader": "^6.1.0", "lodash.isplainobject": "^4.0.6", "lodash.merge": "^4.6.2", "lodash.uniq": "^4.5.0" } }, "sha512-kE4mRKWWNju2QpsCWt428XBvUH55OET2N4QKQ0bF85qS/XbsRGG1MiTByDNlEVpEPceMkDr46LNH95DtRwcsfA=="],

Expand Down Expand Up @@ -117,7 +117,7 @@

"commit-and-tag-version": ["[email protected]", "", { "dependencies": { "chalk": "^2.4.2", "conventional-changelog": "4.0.0", "conventional-changelog-config-spec": "2.1.0", "conventional-changelog-conventionalcommits": "6.1.0", "conventional-recommended-bump": "7.0.1", "detect-indent": "^6.0.0", "detect-newline": "^3.1.0", "dotgitignore": "^2.1.0", "figures": "^3.1.0", "find-up": "^5.0.0", "git-semver-tags": "^5.0.0", "jsdom": "^25.0.0", "semver": "^7.6.3", "w3c-xmlserializer": "^5.0.0", "yaml": "^2.4.1", "yargs": "^17.7.2" }, "bin": { "commit-and-tag-version": "bin/cli.js" } }, "sha512-Ll7rkKntH20iEFOPUT4e503Jf3J0J8jSN+aSeHuvNdtv4xmv9kSLSBg2CWsMVihwF3J2WvMHBEUSCKuDNesiTA=="],

"commitlint": ["commitlint@19.6.1", "", { "dependencies": { "@commitlint/cli": "^19.6.1", "@commitlint/types": "^19.5.0" }, "bin": { "commitlint": "cli.js" } }, "sha512-tU4or+Y2fDXepCZ44o8guEB9uwrRp4if4VupGH1CR+bsVS2zX6Gia4dndA7UPx8cWWw1tvRRJu5keA7RqfXf3w=="],
"commitlint": ["commitlint@19.7.1", "", { "dependencies": { "@commitlint/cli": "^19.7.1", "@commitlint/types": "^19.5.0" }, "bin": { "commitlint": "cli.js" } }, "sha512-iNWqXl/A1WN8qd9JehqUpzbOxczNBE1nzBiYE33TkHeTptq7Cvg5U4j8PpvO92Nxganv6o/20IO3omP5N5M7/A=="],

"compare-func": ["[email protected]", "", { "dependencies": { "array-ify": "^1.0.0", "dot-prop": "^5.1.0" } }, "sha512-zHig5N+tPWARooBnb0Zx1MFcdfpyJrfTJ3Y5L+IFvUm8rM74hHz66z0gw0x4tijh5CorKkKUCnW82R2vmpeCRA=="],

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "purview-telemetry-sourcegenerator",
"version": "1.0.0",
"version": "2.0.1",
"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.",
"main": "index.js",
"scripts": {
Expand All @@ -18,10 +18,10 @@
},
"homepage": "https://github.com/purview-dev/purview-telemetry-sourcegenerator#readme",
"devDependencies": {
"@commitlint/cli": "^19.6.1",
"@commitlint/config-conventional": "^19.6.0",
"@commitlint/cli": "^19.7.1",
"@commitlint/config-conventional": "^19.7.1",
"commit-and-tag-version": "^12.5.0",
"commitlint": "^19.6.1",
"commitlint": "^19.7.1",
"husky": "^9.1.7"
},
"commitlint": {
Expand Down
4 changes: 2 additions & 2 deletions samples/SampleApp/SampleApp.Host/SampleApp.Host.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<ImplicitUsings>enable</ImplicitUsings>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);CS1591;</NoWarn>
<NoWarn>$(NoWarn);CS1591</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Purview.Telemetry.SourceGenerator" Version="2.0.0">
<PackageReference Include="Purview.Telemetry.SourceGenerator" Version="2.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
48 changes: 48 additions & 0 deletions samples/SampleApp/SampleApp.Host/Services/IEntityStoreTelemetry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.Diagnostics;
using Purview.Telemetry.Activities;
using Purview.Telemetry.Logging;
using Purview.Telemetry.Metrics;

namespace SampleApp.Host.Services;

[ActivitySource]
[Logger]
[Meter]
interface IEntityStoreTelemetry
{
/// <summary>
/// Creates and starts an Activity and adds the parameters as Tags and Baggage.
/// </summary>
[Activity]
Activity? GettingEntityFromStore(int entityId, [Baggage] string serviceUrl);

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

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

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

/// <summary>
/// Generates a structured log message using an ILogger, specifically defined as Informational.
/// </summary>
[Info]
void ProcessingAnotherEntity(int entityId, string updateState);

/// <summary>
/// Adds 1 to a Counter{T} with the entityId as a Tag.
/// </summary>
[AutoCounter]
void RetrievingEntity(int entityId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<Title>Purview Telemetry Source Generator</Title>
<Description>.NET Source Generator for interface-based telemetry building activities, activity events, logs and metrics.</Description>
<PackageIcon>purview-logo.png</PackageIcon>
<DevelopmentDependency>true</DevelopmentDependency>
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>

<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
<IsRoslynComponent>true</IsRoslynComponent>
Expand Down

0 comments on commit 4d1a54a

Please sign in to comment.