{"id":15137816,"url":"https://github.com/purview-dev/purview-telemetry-sourcegenerator","last_synced_at":"2025-04-06T06:44:34.992Z","repository":{"id":231797804,"uuid":"767120025","full_name":"purview-dev/purview-telemetry-sourcegenerator","owner":"purview-dev","description":".NET Source Generator for interface-based telemetry building activities, activity events, logs and metrics.","archived":false,"fork":false,"pushed_at":"2024-04-13T20:44:14.000Z","size":1745,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-04-14T10:58:28.807Z","etag":null,"topics":["activity","distributed-tracing","dotnet","events","logging","metrics","open-telemetry","open-telemetry-csharp","source-generator","spans"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/purview-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-03-04T18:31:56.000Z","updated_at":"2024-06-09T08:40:46.683Z","dependencies_parsed_at":"2024-04-13T21:37:50.262Z","dependency_job_id":null,"html_url":"https://github.com/purview-dev/purview-telemetry-sourcegenerator","commit_stats":null,"previous_names":["purview-dev/purview-telemetry-sourcegenerator"],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purview-dev%2Fpurview-telemetry-sourcegenerator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purview-dev%2Fpurview-telemetry-sourcegenerator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purview-dev%2Fpurview-telemetry-sourcegenerator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/purview-dev%2Fpurview-telemetry-sourcegenerator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/purview-dev","download_url":"https://codeload.github.com/purview-dev/purview-telemetry-sourcegenerator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247445652,"owners_count":20939953,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["activity","distributed-tracing","dotnet","events","logging","metrics","open-telemetry","open-telemetry-csharp","source-generator","spans"],"created_at":"2024-09-26T07:02:14.833Z","updated_at":"2025-04-06T06:44:34.984Z","avatar_url":"https://github.com/purview-dev.png","language":"C#","readme":"# Purview Telemetry Source Generator\n\nGenerates [`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 telemetry from methods you define on an interface.\n\n[![CI](https://github.com/purview-dev/purview-telemetry-sourcegenerator/actions/workflows/ci.yml/badge.svg)](https://github.com/purview-dev/purview-telemetry-sourcegenerator/actions/workflows/ci.yml)\n\nThis approach allows for:\n\n- Faster iteration cycles - simply create the method on your interface and the implementation will be automatically generated\n- Easy mocking/ substitution for testing - a full sample project, including tests can be found [here](https://github.com/purview-dev/purview-telemetry-sourcegenerator/tree/main/samples/SampleApp)\n- Built-in dependency injection helper generation\n\nUse the latest version available on [NuGet](https://www.nuget.org/packages/Purview.Telemetry.SourceGenerator/), which supports the following frameworks:\n\n- .NET Framework 4.7.2, or higher\n- .NET 8 or higher\n\nReference in your `Directory.Build.props` or `.csproj` file:\n\n```xml\n\u003cPackageReference Include=\"Purview.Telemetry.SourceGenerator\" Version=\"3.0.0\"\u003e\n  \u003cPrivateAssets\u003eall\u003c/PrivateAssets\u003e\n  \u003cIncludeAssets\u003eruntime; build; native; contentfiles; analyzers\u003c/IncludeAssets\u003e\n\u003c/PackageReference\u003e\n```\n\nFor more information see the [wiki](https://github.com/purview-dev/purview-telemetry-sourcegenerator/wiki).\n\n## Example Interface\n\nThis is called a **multi-target interface** because it generates more than one output type: **Activities, Logging, and Metrics**.\n\n\u003e [!TIP]\n\u003e When generating a single target, the generator will automatically infer the necessary attributes. More information about multi-targeting can be found in [here](https://github.com/purview-dev/purview-telemetry-sourcegenerator/wiki/Multi-Targeting).\n\n```csharp\nusing Purview.Telemetry.Activities;\nusing Purview.Telemetry.Logging;\nusing Purview.Telemetry.Metrics;\n\n/// \u003csummary\u003e\n/// Generates an implementation of the methods for each generation type (Activity, Logging, or Metrics)\n/// and an extension method to enable easy registration with the IServiceCollection.\n/// \u003c/summary\u003e\n[ActivitySource]\n[Logger]\n[Meter]\ninterface IEntityStoreTelemetry\n{\n    /// \u003csummary\u003e\n    /// Creates and starts an Activity and adds the parameters as Tags and Baggage.\n    /// \u003c/summary\u003e\n    [Activity]\n    Activity? GettingEntityFromStore(int entityId, [Baggage]string serviceUrl);\n\n    /// \u003csummary\u003e\n    /// Adds an ActivityEvent to the Activity with the parameters as Tags.\n    /// \u003c/summary\u003e\n    [Event]\n    void GetDuration(Activity? activity, int durationInMS);\n\n    /// \u003csummary\u003e\n    /// Adds the parameters as Baggage to the Activity.\n    /// \u003c/summary\u003e\n    [Context]\n    void RetrievedEntity(Activity? activity, float totalValue, int lastUpdatedByUserId);\n\n    /// \u003csummary\u003e\n    /// Generates a structured log message using an ILogger - defaults to Informational.\n    /// \u003c/summary\u003e\n    [Log]\n    void ProcessingEntity(int entityId, string updateState);\n\n    /// \u003csummary\u003e\n    /// Generates a structured log message using an ILogger, specifically defined as Informational.\n    /// \u003c/summary\u003e\n    [Info]\n    void ProcessingAnotherEntity(int entityId, string updateState);\n\n    /// \u003csummary\u003e\n    /// Adds 1 to a Counter\u003cT\u003e with the entityId as a Tag.\n    /// \u003c/summary\u003e\n    [AutoCounter]\n    void RetrievingEntity(int entityId);\n}\n```\n\nTo see the code generated for the `IEntityStoreTelemetry` interface, see the [`Generated Output`](https://github.com/purview-dev/purview-telemetry-sourcegenerator/wiki/Generated-Output) page in the wiki.\n\n## Example Project\n\nThe [.NET Aspire Sample](https://github.com/purview-dev/purview-telemetry-sourcegenerator/tree/main/samples/SampleApp) demos the Activities, Logs, and Metrics generation working together with the Aspire Dashboard.\n\nCheck the page in the the [wiki](https://github.com/purview-dev/purview-telemetry-sourcegenerator/wiki/Sample-Application) for information.\n\n\u003e [!TIP]\n\u003e This sample project has [`EmitCompilerGeneratedFiles`](https://learn.microsoft.com/en-us/dotnet/core/extensions/configuration-generator#enable-the-configuration-source-generator) set to `true`, so you can easily see the generated output.\n\n## Notes on Logging Generation\n\nThere are two types of logging generation based on:\n\n1. **Microsoft Logging Extension Packages** – Determined by the NuGet packages referenced in your project.\n2. **Attribute-based Configuration** – Controlled using attributes in your code.\n\nFor more details, see the [Logging](https://github.com/purview-dev/purview-telemetry-sourcegenerator/wiki/Logging) page in the wiki.  \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpurview-dev%2Fpurview-telemetry-sourcegenerator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpurview-dev%2Fpurview-telemetry-sourcegenerator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpurview-dev%2Fpurview-telemetry-sourcegenerator/lists"}