Skip to content

Commit a8bbfb4

Browse files
committed
docs: added generated output docs
1 parent 58bc4e5 commit a8bbfb4

3 files changed

Lines changed: 56 additions & 2 deletions

File tree

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
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

77
* .NET Framework 4.7.2
88
* .NET Framework 4.8
99
* .NET 8
1010
* .NET 9
1111

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

1414
```xml
1515
<PackageReference Include="Purview.Telemetry.SourceGenerator" Version="2.0.0">
@@ -18,6 +18,8 @@ Reference in your .props or csproj file:
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,8 @@ 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, sett the [`Generated Output`](https://github.com/purview-dev/purview-telemetry-sourcegenerator/wiki/Generated-Output) page in the wiki.
74+
7175
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.
7276

7377
> This sample project has `EmitCompilerGeneratedFiles` set to `true`, so you can easily see the generated output.
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)