Bemærk
Adgang til denne side kræver godkendelse. Du kan prøve at logge på eller ændre mapper.
Adgang til denne side kræver godkendelse. Du kan prøve at ændre mapper.
At a glance
Goal: Record and export Dev Proxy activity to a report file
Time: 10 minutes
Plugins: ExecutionSummaryPlugin, MarkdownReporter
Prerequisites: Set up Dev Proxy
To record and export proxy activity, use the ExecutionSummaryPlugin and a reporter plugin in your configuration file.
The following example shows how to configure the Dev Proxy to record and export proxy activity using the ExecutionSummaryPlugin and the MarkdownReporter plugin.
File: devproxyrc.json
{
"plugins": [
{
"name": "ExecutionSummaryPlugin",
"enabled": true,
"pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll"
},
{
"name": "MarkdownReporter",
"enabled": true,
"pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll"
}
],
"urlsToWatch": [
"https://jsonplaceholder.typicode.com/*"
]
}
Tip
Instead of building the configuration yourself, you can download the ready-made api-inventory preset, which records the URLs your app calls and a summary of its activity:
devproxy config get api-inventory
devproxy --config-file "~dataFolder/configs/api-inventory/.devproxy/devproxyrc.json" --urls-to-watch "https://api.contoso.com/*"
For more information, see Use preset configurations.
Note
To export the activity, the reporter plugin must be enabled in the configuration file and placed after the ExecutionSummaryPlugin in the plugins list. It is recommended to place a reporter plugin at the end of the plugins list.
To record activity, Dev Proxy must be placed in record mode.
There are two ways to start recording:
- Record immediately. Start proxy with
--recordoption, for example,devproxy --record. - Record adhoc. Press R while proxy is running.
When recording is enabled, ◉ Recording... is shown in the proxy output.
To generate a report from the recorded activity, stop recording.
There are two ways to stop recording:
- Stop proxy. Press Ctrl + C.
- Stop adhoc. Press S.
By default, activities grouped by URL. To group activity by message type, use the --summary-group-by option.
devproxy --record --summary-group-by messageType
Where reports are written
When you stop recording, each enabled reporter writes one file for each report produced by a reporting plugin. Dev Proxy writes the files to the current working directory, which is the folder from which you started Dev Proxy. When you start Dev Proxy in the background, for example in a CI pipeline, make sure that you start it from the folder where you want the reports to be stored.
Report files use the following naming pattern:
<ReportingPlugin>_<Reporter>.<ext>
For example, the configuration in this article produces a file named ExecutionSummaryPlugin_MarkdownReporter.md.
If a file with that name already exists, Dev Proxy doesn't overwrite it. Instead, it appends a timestamp in the yyyyMMddHHmmss format to the file name, for example ExecutionSummaryPlugin_MarkdownReporter_20261105103000.md. Dev Proxy logs the name of each report file that it writes, for example:
Writing report ExecutionSummaryPlugin to ExecutionSummaryPlugin_MarkdownReporter.md...
The following table lists the extensions that each reporter uses.
| Reporter | Extension |
|---|---|
| JsonReporter | .json (some reports use a different extension, for example .jsonc for UrlDiscoveryPlugin) |
| MarkdownReporter | .md |
| PlainTextReporter | .txt |
Note
All recording is local. No data is sent to Microsoft.
Record from scripts and CI
In scripts and CI/CD pipelines, you can't press keys to start and stop recording. Instead, run Dev Proxy in the background and control recording using the Dev Proxy API. All API requests require a bearer token. To know the token upfront, set the DEV_PROXY_API_TOKEN environment variable to a value of at least 32 characters before you start Dev Proxy.
The minimal sequence is:
- Set
DEV_PROXY_API_TOKENto a random value of at least 32 characters. - Start Dev Proxy in the background:
devproxy --detach --as-system-proxy false -c devproxyrc.json. - Wait until
GET /proxysucceeds. - Start recording:
POST /proxywith{"recording": true}. - Run your workload with the
HTTP_PROXYandHTTPS_PROXYenvironment variables pointing to Dev Proxy. - Stop recording:
POST /proxywith{"recording": false}. The request returns after the reporters finish, so the reports are ready when it completes. - Shut down Dev Proxy:
POST /proxy/stopProxy.
Dev Proxy writes the reports to the folder from which you started it.
#!/usr/bin/env bash
set -euo pipefail
# 1. use a known API token (at least 32 characters)
export DEV_PROXY_API_TOKEN=$(openssl rand -hex 32)
api=http://127.0.0.1:8897
auth="Authorization: Bearer $DEV_PROXY_API_TOKEN"
# 2. start Dev Proxy in the background
devproxy --detach --as-system-proxy false -c devproxyrc.json
# 3. wait for the API
until curl -sf -H "$auth" "$api/proxy" > /dev/null; do sleep 1; done
# 4. start recording
curl -sf -X POST "$api/proxy" -H "$auth" -H "Content-Type: application/json" -d '{"recording": true}'
# 5. run the workload through Dev Proxy
HTTP_PROXY=http://127.0.0.1:8000 HTTPS_PROXY=http://127.0.0.1:8000 npm test
# 6. stop recording and wait for the reports
curl -sf -X POST "$api/proxy" -H "$auth" -H "Content-Type: application/json" -d '{"recording": false}'
# 7. shut down Dev Proxy
curl -sf -X POST "$api/proxy/stopProxy" -H "$auth"
The examples use the default proxy port 8000 and API port 8897. Set the proxy environment variables only for the workload, so that the API calls don't go through Dev Proxy. To intercept HTTPS traffic, the workload must trust the Dev Proxy root certificate. For more information about running Dev Proxy in pipelines, including trusting the certificate, see Use Dev Proxy in CI/CD scenarios.
See also
- ExecutionSummaryPlugin - Full reference
- MarkdownReporter - Report format
- Proxy API - Control Dev Proxy programmatically
- Use Dev Proxy in CI/CD scenarios - Run Dev Proxy in pipelines
- Glossary - Dev Proxy terminology
- Use Dev Proxy in CI/CD scenarios - Record API calls in a pipeline
- Use preset configurations - Ready-made configurations
Dev Proxy