Api Diagnostic - Create Or Update
为 API 创建新的诊断或更新现有诊断。
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apis/{apiId}/diagnostics/{diagnosticId}?api-version=2024-05-01
URI 参数
| 名称 | 在 | 必需 | 类型 | 说明 |
|---|---|---|---|---|
|
api
|
path | True |
string minLength: 1maxLength: 80 |
API 标识符。 当前 API 管理服务实例中必须是唯一的。 |
|
diagnostic
|
path | True |
string minLength: 1maxLength: 80 pattern: ^[^*#&+:<>?]+$ |
诊断标识符。 当前 API 管理服务实例中必须是唯一的。 |
|
resource
|
path | True |
string minLength: 1maxLength: 90 |
资源组的名称。 名称不区分大小写。 |
|
service
|
path | True |
string minLength: 1maxLength: 50 pattern: ^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$ |
API 管理服务的名称。 |
|
subscription
|
path | True |
string (uuid) |
目标订阅的 ID。 该值必须是 UUID。 |
|
api-version
|
query | True |
string minLength: 1 |
用于此作的 API 版本。 |
请求头
| 名称 | 必需 | 类型 | 说明 |
|---|---|---|---|
| If-Match |
string |
实体的 ETag。 创建实体时不需要,但在更新实体时是必需的。 |
请求正文
| 名称 | 必需 | 类型 | 说明 |
|---|---|---|---|
| properties.loggerId | True |
string |
目标记录器的资源 ID。 |
| properties.alwaysLog |
指定不应应用哪种类型的消息采样设置。 |
||
| properties.backend |
传入/传出 HTTP 消息到后端的诊断设置 |
||
| properties.frontend |
传入/传出 HTTP 消息到网关的诊断设置。 |
||
| properties.httpCorrelationProtocol |
设置要用于 Application Insights 诊断的相关协议。 |
||
| properties.logClientIp |
boolean |
记录 ClientIP。 默认值为 false。 |
|
| properties.metrics |
boolean |
通过发出指标策略发出自定义指标。 仅适用于 Application Insights 诊断设置。 |
|
| properties.operationNameFormat |
Application Insights 遥测的作名称的格式。 默认值为 Name。 |
||
| properties.sampling |
诊断的采样设置。 |
||
| properties.verbosity |
应用于跟踪策略发出的跟踪的详细级别。 |
响应
| 名称 | 类型 | 说明 |
|---|---|---|
| 200 OK |
诊断已成功更新。 标头 ETag: string |
|
| 201 Created |
已成功创建诊断。 标头 ETag: string |
|
| Other Status Codes |
描述作失败的原因的错误响应。 |
安全性
azure_auth
Azure Active Directory OAuth2 Flow。
类型:
oauth2
流向:
implicit
授权 URL:
https://login.microsoftonline.com/common/oauth2/authorize
作用域
| 名称 | 说明 |
|---|---|
| user_impersonation | 模拟用户帐户 |
示例
ApiManagementCreateApiDiagnostic
示例请求
PUT https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1/providers/Microsoft.ApiManagement/service/apimService1/apis/57d1f7558aa04f15146d9d8a/diagnostics/applicationinsights?api-version=2024-05-01
{
"properties": {
"alwaysLog": "allErrors",
"loggerId": "/loggers/applicationinsights",
"sampling": {
"samplingType": "fixed",
"percentage": 50
},
"frontend": {
"request": {
"headers": [
"Content-type"
],
"body": {
"bytes": 512
}
},
"response": {
"headers": [
"Content-type"
],
"body": {
"bytes": 512
}
}
},
"backend": {
"request": {
"headers": [
"Content-type"
],
"body": {
"bytes": 512
}
},
"response": {
"headers": [
"Content-type"
],
"body": {
"bytes": 512
}
}
}
}
}
示例响应
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1/providers/Microsoft.ApiManagement/service/apimService1/apis/57d1f7558aa04f15146d9d8a/diagnostics/applicationinsights",
"type": "Microsoft.ApiManagement/service/apis/diagnostics",
"name": "applicationinsights",
"properties": {
"alwaysLog": "allErrors",
"loggerId": "/loggers/applicationinsights",
"sampling": {
"samplingType": "fixed",
"percentage": 50
},
"frontend": {
"request": {
"headers": [
"Content-type"
],
"body": {
"bytes": 512
}
},
"response": {
"headers": [
"Content-type"
],
"body": {
"bytes": 512
}
}
},
"backend": {
"request": {
"headers": [
"Content-type"
],
"body": {
"bytes": 512
}
},
"response": {
"headers": [
"Content-type"
],
"body": {
"bytes": 512
}
}
}
}
}
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1/providers/Microsoft.ApiManagement/service/apimService1/apis/57d1f7558aa04f15146d9d8a/diagnostics/applicationinsights",
"type": "Microsoft.ApiManagement/service/apis/diagnostics",
"name": "applicationinsights",
"properties": {
"alwaysLog": "allErrors",
"loggerId": "/loggers/applicationinsights",
"sampling": {
"samplingType": "fixed",
"percentage": 50
},
"frontend": {
"request": {
"headers": [
"Content-type"
],
"body": {
"bytes": 512
}
},
"response": {
"headers": [
"Content-type"
],
"body": {
"bytes": 512
}
}
},
"backend": {
"request": {
"headers": [
"Content-type"
],
"body": {
"bytes": 512
}
},
"response": {
"headers": [
"Content-type"
],
"body": {
"bytes": 512
}
}
}
}
}
定义
| 名称 | 说明 |
|---|---|
|
Always |
指定不应应用哪种类型的消息采样设置。 |
|
Body |
正文日志记录设置。 |
|
Data |
|
|
Data |
|
|
Data |
数据掩码模式。 |
|
Diagnostic |
诊断详细信息。 |
|
Error |
资源管理错误附加信息。 |
|
Error |
错误详细信息。 |
|
Error |
错误响应 |
|
Http |
设置要用于 Application Insights 诊断的相关协议。 |
|
Http |
Http 消息诊断设置。 |
|
Operation |
Application Insights 遥测的作名称的格式。 默认值为 Name。 |
|
Pipeline |
传入/传出 HTTP 消息到网关的诊断设置。 |
|
Sampling |
诊断的采样设置。 |
|
Sampling |
采样类型。 |
| Verbosity |
应用于跟踪策略发出的跟踪的详细级别。 |
AlwaysLog
指定不应应用哪种类型的消息采样设置。
| 值 | 说明 |
|---|---|
| allErrors |
无论采样设置如何,始终记录所有错误请求。 |
BodyDiagnosticSettings
正文日志记录设置。
| 名称 | 类型 | 说明 |
|---|---|---|
| bytes |
integer (int32) maximum: 8192 |
要记录的请求正文字节数。 |
DataMasking
| 名称 | 类型 | 说明 |
|---|---|---|
| headers |
标头的掩码设置 |
|
| queryParams |
Url 查询参数的掩码设置 |
DataMaskingEntity
| 名称 | 类型 | 说明 |
|---|---|---|
| mode |
数据掩码模式。 |
|
| value |
string |
要屏蔽的实体的名称(例如标头或查询参数的名称)。 |
DataMaskingMode
数据掩码模式。
| 值 | 说明 |
|---|---|
| Mask |
屏蔽实体的值。 |
| Hide |
隐藏实体的存在。 |
DiagnosticContract
诊断详细信息。
| 名称 | 类型 | 说明 |
|---|---|---|
| id |
string |
资源的完全限定资源 ID。 示例 - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} |
| name |
string |
资源的名称 |
| properties.alwaysLog |
指定不应应用哪种类型的消息采样设置。 |
|
| properties.backend |
传入/传出 HTTP 消息到后端的诊断设置 |
|
| properties.frontend |
传入/传出 HTTP 消息到网关的诊断设置。 |
|
| properties.httpCorrelationProtocol |
设置要用于 Application Insights 诊断的相关协议。 |
|
| properties.logClientIp |
boolean |
记录 ClientIP。 默认值为 false。 |
| properties.loggerId |
string |
目标记录器的资源 ID。 |
| properties.metrics |
boolean |
通过发出指标策略发出自定义指标。 仅适用于 Application Insights 诊断设置。 |
| properties.operationNameFormat |
Application Insights 遥测的作名称的格式。 默认值为 Name。 |
|
| properties.sampling |
诊断的采样设置。 |
|
| properties.verbosity |
应用于跟踪策略发出的跟踪的详细级别。 |
|
| type |
string |
资源的类型。 例如“Microsoft.Compute/virtualMachines”或“Microsoft.Storage/storageAccounts” |
ErrorAdditionalInfo
资源管理错误附加信息。
| 名称 | 类型 | 说明 |
|---|---|---|
| info |
object |
其他信息。 |
| type |
string |
其他信息类型。 |
ErrorDetail
错误详细信息。
| 名称 | 类型 | 说明 |
|---|---|---|
| additionalInfo |
错误附加信息。 |
|
| code |
string |
错误代码。 |
| details |
错误详细信息。 |
|
| message |
string |
错误消息。 |
| target |
string |
错误目标。 |
ErrorResponse
错误响应
| 名称 | 类型 | 说明 |
|---|---|---|
| error |
错误对象。 |
HttpCorrelationProtocol
设置要用于 Application Insights 诊断的相关协议。
| 值 | 说明 |
|---|---|
| None |
不要读取和注入相关标头。 |
| Legacy |
使用请求关联数据注入 Request-Id 和 Request-Context 标头。 请参阅 https://github.com/dotnet/corefx/blob/master/src/System.Diagnostics.DiagnosticSource/src/HttpCorrelationProtocol.md。 |
| W3C |
注入跟踪上下文标头。 请参阅 https://w3c.github.io/trace-context。 |
HttpMessageDiagnostic
Http 消息诊断设置。
| 名称 | 类型 | 说明 |
|---|---|---|
| body |
正文日志记录设置。 |
|
| dataMasking |
数据掩码设置。 |
|
| headers |
string[] |
要记录的 HTTP 标头数组。 |
OperationNameFormat
Application Insights 遥测的作名称的格式。 默认值为 Name。
| 值 | 说明 |
|---|---|
| Name |
API_NAME;rev=API_REVISION - OPERATION_NAME |
| Url |
HTTP_VERB网址 |
PipelineDiagnosticSettings
传入/传出 HTTP 消息到网关的诊断设置。
| 名称 | 类型 | 说明 |
|---|---|---|
| request |
请求的诊断设置。 |
|
| response |
响应的诊断设置。 |
SamplingSettings
诊断的采样设置。
| 名称 | 类型 | 说明 |
|---|---|---|
| percentage |
number (double) minimum: 0maximum: 100 |
固定速率采样的采样率。 |
| samplingType |
采样类型。 |
SamplingType
采样类型。
| 值 | 说明 |
|---|---|
| fixed |
固定速率采样。 |
Verbosity
应用于跟踪策略发出的跟踪的详细级别。
| 值 | 说明 |
|---|---|
| verbose |
跟踪策略发出的所有跟踪都将发送到附加到此诊断实例的记录器。 |
| information |
将“严重性”设置为“信息”和“错误”的跟踪将发送到附加到此诊断实例的记录器。 |
| error |
只有“严重性”设置为“error”的跟踪才会发送到附加到此诊断实例的记录器。 |