{"id":21730113,"url":"https://github.com/nventive/aspnetcorerequesttracing","last_synced_at":"2025-10-07T12:31:16.992Z","repository":{"id":46859001,"uuid":"195068768","full_name":"nventive/AspNetCoreRequestTracing","owner":"nventive","description":"Full Request/Response Tracing for ASP.NET Core","archived":false,"fork":false,"pushed_at":"2023-02-27T23:54:14.000Z","size":35,"stargazers_count":2,"open_issues_count":3,"forks_count":1,"subscribers_count":28,"default_branch":"master","last_synced_at":"2025-01-22T17:09:24.264Z","etag":null,"topics":["aspnet-core","aspnetcore","csharp"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nventive.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-03T14:18:30.000Z","updated_at":"2023-04-22T16:36:44.000Z","dependencies_parsed_at":"2022-09-19T14:32:08.419Z","dependency_job_id":null,"html_url":"https://github.com/nventive/AspNetCoreRequestTracing","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nventive%2FAspNetCoreRequestTracing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nventive%2FAspNetCoreRequestTracing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nventive%2FAspNetCoreRequestTracing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nventive%2FAspNetCoreRequestTracing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nventive","download_url":"https://codeload.github.com/nventive/AspNetCoreRequestTracing/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235628177,"owners_count":19020540,"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":["aspnet-core","aspnetcore","csharp"],"created_at":"2024-11-26T04:12:29.168Z","updated_at":"2025-10-07T12:31:11.690Z","avatar_url":"https://github.com/nventive.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AspNetCoreRequestTracing\n\nFull Request/Response Tracing for ASP.NET Core\n\nThis projects provides an ASP.NET Core middleware to allow complete tracing of\nrequests and responses (including the body) going in/out of an ASP.NET Core app.\n\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)\n[![Build Status](https://dev.azure.com/nventive-public/nventive/_apis/build/status/nventive.AspNetCoreRequestTracing?branchName=master)](https://dev.azure.com/nventive-public/nventive/_build/latest?definitionId=1\u0026branchName=master)\n![Nuget](https://img.shields.io/nuget/v/AspNetCoreRequestTracing.svg)\n\n## Getting Started\n\nInstall the package:\n\n```\nInstall-Package AspNetCoreRequestTracing\n```\n\nThen in the `Startup` class adds the configuration and the request middleware:\n\n```csharp\n\nusing AspNetCoreRequestTracing;\n\npublic class Startup\n{\n    // This method gets called by the runtime. Use this method to add services to the container.\n    // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940\n    public void ConfigureServices(IServiceCollection services)\n    {\n        // ...\n\n        // Configure the RequestTracingMiddlewareOptions. This is one way of doing it.\n        services.Configure\u003cRequestTracingMiddlewareOptions\u003e(options =\u003e\n        {\n            // List of regular expressions used to match the incoming requests path\n            // for which tracing is enabled.\n            // If the request path is not matched, no tracing will happen and the middleware\n            // is a no-op.\n            options.EnableFor = new[] { \"/info\", \"/api/.*\" };\n        });\n        \n        // Alternatively, options can be loaded from a configuration section.\n        services.Configure\u003cRequestTracingMiddlewareOptions\u003e(\n          _configuration.GetSection(nameof(RequestTracingMiddlewareOptions)));\n    }\n\n    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.\n    public void Configure(IApplicationBuilder app, IHostingEnvironment env)\n    {\n        // Make sure this is sufficiently early in the request pipeline.\n        app.UseRequestTracing();\n        // ...\n        app.UseMvc();\n    }\n}\n\n```\n\n## Features\n\n### Request selection\n\nOnly requests that match a path configured in `RequestTracingMiddlewareOptions.EnabledFor` will be traced;\nThis is done because enabling tracing may have an impact on performance, as the request and the response needs buffering.\n\nIn order to trace _all requests_, just use a catch-all regular expression: `\".*\"`.\n\n### Logger settings\n\nThe logger category is `AspNetCoreRequestTracing.RequestTracingMiddleware`.\nThe `LogLevel` used for request is always `LogLevel.Trace`.\n\nFor the responses, it depends on the `StatusCode`:\n- Any status code below 400 is logged using `LogLevel.Trace`\n- Any status code above 400 and below 500 is logged using `LogLevel.Warning`\n- Any status code above 500 is logged using `LogLevel.Error`\n\nEvent ids used for the various messages:\n\n| Event id | Event Name      | Description                        |\n|----------|-----------------|------------------------------------|\n| 300      | RequestTrace    | Incoming request                   |\n| 310      | ResponseTrace   | Successful response                |\n| 311      | ResponseWarning | Response with a client error (4xx) |\n| 312      | ResponseError   | Response with a server error (5xx) |\n\nTo enable the logger, please consult the documentation regarding [Logging in ASP.NET Core](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-2.2#configuration).\n\nOne way of configuring it is through the `appsettings.json` file:\n\n```json\n{\n  \"Logging\": {\n    \"LogLevel\": {\n      \"Default\": \"Warning\",\n      \"AspNetCoreRequestTracing.RequestTracingMiddleware\": \"Trace\"\n    }\n  }\n}\n```\n\n### Usage with Application Insights\n\nWhen adding [Application Insights](https://docs.microsoft.com/en-us/azure/azure-monitor/app/asp-net-core), by default all `Warning` and `Error` trace are captured,\nwhich means that:\n- no request information will be captured in Application Insights\n- only responses with either a client error (4xx) or a server error (5xx) will be captured\n\nTo enable the capture for the requests and successful responses, [please configure the\n`ApplicationInsightsLoggerProvider` to keep the `Trace` level](https://docs.microsoft.com/en-us/azure/azure-monitor/app/ilogger). This can be achieved through\nthe `appsettings.json` file as well:\n\n```json\n{\n  \"Logging\": {\n    \"ApplicationInsights\": {\n      \"LogLevel\": {\n        \"AspNetCoreRequestTracing.RequestTracingMiddleware\": \"Trace\"\n      }\n    },\n    \"LogLevel\": {\n      \"Default\": \"Warning\",\n      \"AspNetCoreRequestTracing.RequestTracingMiddleware\": \"Trace\"\n    }\n  }\n}\n```\n\n### Performance impacts\n\nAdding the middleware with no matching requests should have a negligible impact\non the performance of the app.\nHowever, when a request path is matched, then several things need to happen to \nbe able to fully trace the request and the response:\n\n- `EnableRewind()` is called on the `Request`; this enables buffering for the requests\n- a secondary buffer for the `Response` is created to capture the writes in parallel to\nsending them back to the host server; this incurs additional processing and memory overhead; secondary buffered are pooled to minimize [LOH](https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/large-object-heap) allocations.\n\n## Changelog\n\nPlease consult the [CHANGELOG](CHANGELOG.md) for more information about version\nhistory.\n\n## License\n\nThis project is licensed under the Apache 2.0 license - see the\n[LICENSE](LICENSE) file for details.\n\n## Contributing\n\nPlease read [CONTRIBUTING.md](CONTRIBUTING.md) for details on the process for\ncontributing to this project.\n\nBe mindful of our [Code of Conduct](CODE_OF_CONDUCT.md).\n\n## Acknowledgments\n\nIn order to mitigate the effect of allocating large buffers continuously, this\npackage uses pooled memory streams provided by the `Microsoft.IO.RecyclableMemoryStream` package.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnventive%2Faspnetcorerequesttracing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnventive%2Faspnetcorerequesttracing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnventive%2Faspnetcorerequesttracing/lists"}