-
Notifications
You must be signed in to change notification settings - Fork 7
Add api-usage-analytics sample - Track API endpoint usage with ExecutionSummaryPlugin #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e0c15cd
Add api-usage-analytics sample with ExecutionSummaryPlugin and reporters
Copilot a99a657
Add web app and address review feedback
Copilot bca3db2
Update sample dates to 2026-01-10
Copilot e7c9179
Update screenshot to show web app UI
Copilot 5340cd3
Move config to .devproxy folder and remove default values
Copilot 62c4c8e
Update screenshot and remove browser proxy instruction
Copilot e816c55
Fix validation issues: change PRESET to No, update dates
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| { | ||
| "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.0.0/rc.schema.json", | ||
| "plugins": [ | ||
| { | ||
| "name": "ExecutionSummaryPlugin", | ||
| "enabled": true, | ||
| "pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll" | ||
| }, | ||
| { | ||
| "name": "PlainTextReporter", | ||
| "enabled": true, | ||
| "pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll" | ||
| }, | ||
| { | ||
| "name": "JsonReporter", | ||
| "enabled": true, | ||
| "pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll" | ||
| }, | ||
| { | ||
| "name": "MarkdownReporter", | ||
| "enabled": true, | ||
| "pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll" | ||
| } | ||
| ], | ||
| "urlsToWatch": [ | ||
| "https://jsonplaceholder.typicode.com/*" | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| # Track API usage analytics | ||
|
|
||
| ## Summary | ||
|
|
||
| This sample demonstrates how to use Dev Proxy to track and analyze API usage patterns. Using the ExecutionSummaryPlugin combined with multiple reporter plugins, you can generate detailed summaries showing which endpoints are used most frequently, response status codes, and timing information across different output formats. | ||
|
|
||
| The sample includes a web app that makes API requests to the JSONPlaceholder API, allowing you to interactively generate traffic and see how Dev Proxy tracks usage patterns. | ||
|
|
||
|  | ||
|
|
||
| ## Compatibility | ||
|
|
||
|  | ||
|
|
||
| ## Contributors | ||
|
|
||
| * [Waldek Mastykarz](https://github.com/waldekmastykarz) | ||
|
|
||
| ## Version history | ||
|
|
||
| Version|Date|Comments | ||
| -------|----|-------- | ||
| 1.0|January 18, 2026|Initial release | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - [Dev Proxy](https://aka.ms/devproxy) | ||
| - [Node.js LTS](https://nodejs.org) (for http-server) | ||
|
|
||
| ## Minimal path to awesome | ||
|
|
||
| - Clone this repository (or [download this solution as a .ZIP file](https://pnp.github.io/download-partial/?url=https://github.com/pnp/proxy-samples/tree/main/samples/api-usage-analytics) then unzip it) | ||
| - Navigate to the sample folder: `cd samples/api-usage-analytics` | ||
| - Run `npm install` to install dependencies | ||
| - Run `npm start` to start Dev Proxy and the web server | ||
| - Open http://localhost:3000 in your browser | ||
| - Click the API buttons to make requests and see the usage tracked in real-time | ||
| - Use "Simulate User Session" to generate a realistic browsing pattern | ||
| - Use "Burst 10 Requests" to test rapid request tracking | ||
| - Stop Dev Proxy (<kbd>Ctrl</kbd>+<kbd>C</kbd>) to generate the execution summary reports | ||
|
|
||
| ### Generated Reports | ||
|
|
||
| After stopping Dev Proxy, check the generated reports in the current directory: | ||
| - `ExecutionSummaryPlugin_PlainTextReporter.txt` - Plain text format | ||
| - `ExecutionSummaryPlugin_JsonReporter.json` - JSON format | ||
| - `ExecutionSummaryPlugin_MarkdownReporter.md` - Markdown format | ||
|
|
||
| ## Features | ||
|
|
||
| This sample uses Dev Proxy's ExecutionSummaryPlugin to track API usage and generates reports in multiple formats: | ||
|
|
||
| **Web App Features:** | ||
| * Interactive buttons to call different API endpoints | ||
| * Real-time request log showing method, URL, status, and duration | ||
| * Live statistics: total requests, success count, errors, and unique endpoints | ||
| * "Simulate User Session" - generates realistic browsing patterns | ||
| * "Burst 10 Requests" - tests rapid request handling | ||
|
|
||
| **Summary Information:** | ||
| * Request counts per endpoint | ||
| * Response status codes distribution | ||
| * Request grouping by URL or message type | ||
|
|
||
| **Output Formats:** | ||
| * **Plain Text** - Simple, human-readable format for quick review | ||
| * **JSON** - Structured data for programmatic analysis and integration | ||
| * **Markdown** - Formatted output for documentation and reports | ||
|
|
||
| Using this sample you can use Dev Proxy to: | ||
|
|
||
| * **Understand API usage patterns** - See which endpoints are called most frequently | ||
| * **Identify hotspots** - Find endpoints that might need optimization | ||
| * **Track response status codes** - Monitor error rates and success rates | ||
| * **Generate multiple report formats** - Choose the format that best fits your workflow | ||
| * **Analyze request distribution** - Understand how traffic is distributed across endpoints | ||
|
|
||
| ## Configuration Options | ||
|
|
||
| The sample is configured to group requests by URL (the default). You can change this to group by message type by modifying the `groupBy` property in the `.devproxy/devproxyrc.json` config file: | ||
|
|
||
| ```json | ||
| "executionSummaryPlugin": { | ||
| "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.0.0/executionsummaryplugin.schema.json", | ||
| "groupBy": "messageType" | ||
| } | ||
| ``` | ||
|
|
||
| Don't forget to add a `configSection` reference to the ExecutionSummaryPlugin when adding custom configuration. | ||
|
|
||
| You can also use the command line option: `devproxy --summary-group-by messageType` | ||
|
|
||
| To monitor different APIs, update the `urlsToWatch` property: | ||
|
|
||
| ```json | ||
| "urlsToWatch": [ | ||
| "https://api.example.com/*", | ||
| "https://graph.microsoft.com/v1.0/*" | ||
| ] | ||
| ``` | ||
|
|
||
| ## Help | ||
|
|
||
| We do not support samples, but this community is always willing to help, and we want to improve these samples. We use GitHub to track issues, which makes it easy for community members to volunteer their time and help resolve issues. | ||
|
|
||
| You can try looking at [issues related to this sample](https://github.com/pnp/proxy-samples/issues?q=label%3A%22sample%3A%20api-usage-analytics%22) to see if anybody else is having the same issues. | ||
|
|
||
| If you encounter any issues using this sample, [create a new issue](https://github.com/pnp/proxy-samples/issues/new). | ||
|
|
||
| Finally, if you have an idea for improvement, [make a suggestion](https://github.com/pnp/proxy-samples/issues/new). | ||
|
|
||
| ## Disclaimer | ||
|
|
||
| **THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.** | ||
|
|
||
|  |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| [ | ||
| { | ||
| "name": "pnp-devproxy-api-usage-analytics", | ||
| "source": "pnp", | ||
| "title": "Track API usage analytics", | ||
| "shortDescription": "Demonstrates how to use Dev Proxy to track and analyze API usage patterns, showing which endpoints are used most frequently with reports in plain text, JSON, and Markdown formats.", | ||
| "url": "https://github.com/pnp/proxy-samples/tree/main/samples/api-usage-analytics", | ||
| "downloadUrl": "https://pnp.github.io/download-partial/?url=https://github.com/pnp/proxy-samples/tree/main/samples/api-usage-analytics", | ||
| "longDescription": [ | ||
| "Demonstrates how to use Dev Proxy to track and analyze API usage patterns, showing which endpoints are used most frequently with reports in plain text, JSON, and Markdown formats." | ||
| ], | ||
| "creationDateTime": "2026-01-18", | ||
| "updateDateTime": "2026-01-18", | ||
| "products": [ | ||
| "Dev Proxy" | ||
| ], | ||
| "metadata": [ | ||
| { | ||
| "key": "SAMPLE ID", | ||
| "value": "api-usage-analytics" | ||
| }, | ||
| { | ||
| "key": "PRESET", | ||
| "value": "No" | ||
| }, | ||
| { | ||
| "key": "MOCKS", | ||
| "value": "No" | ||
| }, | ||
| { | ||
| "key": "PLUGIN", | ||
| "value": "No" | ||
| }, | ||
| { | ||
| "key": "PROXY VERSION", | ||
| "value": "v2.0.0" | ||
| } | ||
| ], | ||
| "thumbnails": [ | ||
| { | ||
| "type": "image", | ||
| "order": 100, | ||
| "url": "https://github.com/pnp/proxy-samples/raw/main/samples/api-usage-analytics/assets/screenshot.png", | ||
| "alt": "Dev Proxy tracking API usage analytics" | ||
| } | ||
| ], | ||
| "authors": [ | ||
| { | ||
| "gitHubAccount": "waldekmastykarz", | ||
| "pictureUrl": "https://github.com/waldekmastykarz.png", | ||
| "name": "Waldek Mastykarz" | ||
| } | ||
| ], | ||
| "references": [ | ||
| { | ||
| "name": "Get started with the Dev Proxy", | ||
| "description": "The tutorial will introduce you to the Dev Proxy and show you how to use its features.", | ||
| "url": "https://learn.microsoft.com/microsoft-cloud/dev/dev-proxy/get-started" | ||
| }, | ||
| { | ||
| "name": "Use preset configurations", | ||
| "description": "Instructions on how to configure the Dev Proxy to use a different configuration file.", | ||
| "url": "https://learn.microsoft.com/microsoft-cloud/dev/dev-proxy/how-to/use-preset-configurations" | ||
| }, | ||
| { | ||
| "name": "ExecutionSummaryPlugin documentation", | ||
| "description": "The documentation of the ExecutionSummaryPlugin for the Dev Proxy.", | ||
| "url": "https://learn.microsoft.com/microsoft-cloud/dev/dev-proxy/technical-reference/executionsummaryplugin" | ||
| }, | ||
| { | ||
| "name": "Record and export proxy activity", | ||
| "description": "Learn how to record and export proxy activity using Dev Proxy.", | ||
| "url": "https://learn.microsoft.com/microsoft-cloud/dev/dev-proxy/how-to/record-and-export-proxy-activity" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot update screenshot based on the latest version of index.html
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated in 2bd7fa5. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

Uh oh!
There was an error while loading. Please reload this page.