你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。

Microsoft.ApiManagement 服务/诊断 2024-05-01

Bicep 资源定义

可以使用目标操作部署服务/诊断资源类型:

有关每个 API 版本中已更改属性的列表,请参阅 更改日志。

用法示例

Bicep 示例

部署 API 管理服务诊断的基本示例。

param location string = 'westeurope'
param resourceName string = 'acctest0001'

resource component 'Microsoft.Insights/components@2020-02-02' = {
  name: resourceName
  location: location
  kind: 'web'
  properties: {
    Application_Type: 'web'
    DisableIpMasking: false
    DisableLocalAuth: false
    ForceCustomerStorageForProfiler: false
    RetentionInDays: 90
    SamplingPercentage: 100
    publicNetworkAccessForIngestion: 'Enabled'
    publicNetworkAccessForQuery: 'Enabled'
  }
}

resource service 'Microsoft.ApiManagement/service@2021-08-01' = {
  name: resourceName
  location: location
  sku: {
    capacity: 0
    name: 'Consumption'
  }
  properties: {
    certificates: []
    customProperties: {
      'Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Ssl30': 'false'
      'Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls10': 'false'
      'Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls11': 'false'
      'Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls10': 'false'
      'Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls11': 'false'
    }
    disableGateway: false
    publicNetworkAccess: 'Enabled'
    publisherEmail: 'pub1@email.com'
    publisherName: 'pub1'
    virtualNetworkType: 'None'
  }
}

resource diagnostic 'Microsoft.ApiManagement/service/diagnostics@2021-08-01' = {
  name: 'applicationinsights'
  parent: service
  properties: {
    loggerId: logger.id
    operationNameFormat: 'Name'
  }
}

resource logger 'Microsoft.ApiManagement/service/loggers@2021-08-01' = {
  name: resourceName
  parent: service
  properties: {
    credentials: {
      instrumentationKey: component.properties.InstrumentationKey
    }
    description: ''
    isBuffered: true
    loggerType: 'applicationInsights'
  }
}

Azure 验证模块

以下 Azure 验证模块 可用于部署此资源类型。

模块 描述
API 管理服务 - 诊断 API 管理服务的 AVM 子模块 - 诊断

Azure 快速入门示例

以下 Azure 快速入门模板 包含用于部署此资源类型的 Bicep 示例。

Bicep 文件 描述
使用内部 API 管理和 Web 应用 应用程序网关 应用程序网关将 Internet 流量路由到虚拟网络(内部模式)API 管理实例,该实例服务 Azure Web 应用中托管的 Web API。
使用应用网关在内部 VNet 中创建 API 管理 此模板演示如何在受 Azure 应用程序网关保护的专用网络上创建 Azure API 管理的实例。

资源格式

若要创建 Microsoft.ApiManagement/service/diagnostics 资源,请将以下 Bicep 添加到模板。

resource symbolicname 'Microsoft.ApiManagement/service/diagnostics@2024-05-01' = {
  parent: resourceSymbolicName
  name: 'string'
  properties: {
    alwaysLog: 'string'
    backend: {
      request: {
        body: {
          bytes: int
        }
        dataMasking: {
          headers: [
            {
              mode: 'string'
              value: 'string'
            }
          ]
          queryParams: [
            {
              mode: 'string'
              value: 'string'
            }
          ]
        }
        headers: [
          'string'
        ]
      }
      response: {
        body: {
          bytes: int
        }
        dataMasking: {
          headers: [
            {
              mode: 'string'
              value: 'string'
            }
          ]
          queryParams: [
            {
              mode: 'string'
              value: 'string'
            }
          ]
        }
        headers: [
          'string'
        ]
      }
    }
    frontend: {
      request: {
        body: {
          bytes: int
        }
        dataMasking: {
          headers: [
            {
              mode: 'string'
              value: 'string'
            }
          ]
          queryParams: [
            {
              mode: 'string'
              value: 'string'
            }
          ]
        }
        headers: [
          'string'
        ]
      }
      response: {
        body: {
          bytes: int
        }
        dataMasking: {
          headers: [
            {
              mode: 'string'
              value: 'string'
            }
          ]
          queryParams: [
            {
              mode: 'string'
              value: 'string'
            }
          ]
        }
        headers: [
          'string'
        ]
      }
    }
    httpCorrelationProtocol: 'string'
    logClientIp: bool
    loggerId: 'string'
    metrics: bool
    operationNameFormat: 'string'
    sampling: {
      percentage: int
      samplingType: 'string'
    }
    verbosity: 'string'
  }
}

属性值

Microsoft.ApiManagement/service/diagnostics

名字 描述 价值
名字 资源名称 字符串

约束:
最小长度 = 1
最大长度 = 80
模式 = ^[^*#&+:<>?]+$ (必需)
父级 在 Bicep 中,可以为子资源指定父资源。 仅当子资源在父资源外部声明时,才需要添加此属性。

有关详细信息,请参阅 父资源外部的子资源。
类型资源的符号名称:服务
性能 诊断实体协定属性。 DiagnosticContractProperties

BodyDiagnosticSettings (身体诊断设置)

名字 描述 价值
字节 要记录的请求正文字节数。 int

约束:
最大值 = 8192

数据掩码

名字 描述 价值
头 标头的掩码设置 DataMaskingEntity[]
queryParams 查询参数 Url 查询参数的掩码设置 DataMaskingEntity[]

DataMaskingEntity 数据掩码实体

名字 描述 价值
模式 数据掩码模式。 “隐藏”
“Mask”
价值 要屏蔽的实体的名称(例如标头或查询参数的名称)。 字符串

DiagnosticContractProperties

名字 描述 价值
alwaysLog 指定不应应用哪种类型的消息采样设置。 “allErrors”
后端 传入/传出 HTTP 消息到后端的诊断设置 PipelineDiagnosticSettings
前端 传入/传出 HTTP 消息到网关的诊断设置。 PipelineDiagnosticSettings
httpCorrelationProtocol 协议 设置要用于 Application Insights 诊断的相关协议。 “Legacy”
“None”
“W3C”
日志客户端 Ip 记录 ClientIP。 默认值为 false。 布尔
loggerId (记录器标识) 目标记录器的资源 ID。 string (必需)
指标 通过发出指标策略发出自定义指标。 仅适用于 Application Insights 诊断设置。 布尔
operationNameFormat Application Insights 遥测的操作名称的格式。 默认值为 Name。 “Name”
“Url”
抽样 诊断的采样设置。 采样设置
详细程度 应用于跟踪策略发出的跟踪的详细级别。 “error”
“information”
“verbose”

HttpMessageDiagnostic

名字 描述 价值
身体 正文日志记录设置。 BodyDiagnosticSettings (身体诊断设置)
数据掩码 数据掩码设置。 数据掩码
头 要记录的 HTTP 标头数组。 字符串[]

PipelineDiagnosticSettings

名字 描述 价值
申请 请求的诊断设置。 HttpMessageDiagnostic
响应 响应的诊断设置。 HttpMessageDiagnostic

采样设置

名字 描述 价值
百分比 固定速率采样的采样率。 int

约束:
最小值 = 0
最大值 = 100
采样类型 采样类型。 “fixed”

ARM 模板资源定义

可以使用目标操作部署服务/诊断资源类型:

用法示例

Azure 快速入门模板

以下 Azure 快速入门模板 部署此资源类型。

模板 描述
使用内部 API 管理和 Web 应用 应用程序网关

部署到 Azure
应用程序网关将 Internet 流量路由到虚拟网络(内部模式)API 管理实例,该实例服务 Azure Web 应用中托管的 Web API。
使用应用网关在内部 VNet 中创建 API 管理

部署到 Azure
此模板演示如何在受 Azure 应用程序网关保护的专用网络上创建 Azure API 管理的实例。

资源格式

若要创建 Microsoft.ApiManagement/service/diagnostics 资源,请将以下 JSON 添加到模板。

{
  "type": "Microsoft.ApiManagement/service/diagnostics",
  "apiVersion": "2024-05-01",
  "name": "string",
  "properties": {
    "alwaysLog": "string",
    "backend": {
      "request": {
        "body": {
          "bytes": "int"
        },
        "dataMasking": {
          "headers": [
            {
              "mode": "string",
              "value": "string"
            }
          ],
          "queryParams": [
            {
              "mode": "string",
              "value": "string"
            }
          ]
        },
        "headers": [ "string" ]
      },
      "response": {
        "body": {
          "bytes": "int"
        },
        "dataMasking": {
          "headers": [
            {
              "mode": "string",
              "value": "string"
            }
          ],
          "queryParams": [
            {
              "mode": "string",
              "value": "string"
            }
          ]
        },
        "headers": [ "string" ]
      }
    },
    "frontend": {
      "request": {
        "body": {
          "bytes": "int"
        },
        "dataMasking": {
          "headers": [
            {
              "mode": "string",
              "value": "string"
            }
          ],
          "queryParams": [
            {
              "mode": "string",
              "value": "string"
            }
          ]
        },
        "headers": [ "string" ]
      },
      "response": {
        "body": {
          "bytes": "int"
        },
        "dataMasking": {
          "headers": [
            {
              "mode": "string",
              "value": "string"
            }
          ],
          "queryParams": [
            {
              "mode": "string",
              "value": "string"
            }
          ]
        },
        "headers": [ "string" ]
      }
    },
    "httpCorrelationProtocol": "string",
    "logClientIp": "bool",
    "loggerId": "string",
    "metrics": "bool",
    "operationNameFormat": "string",
    "sampling": {
      "percentage": "int",
      "samplingType": "string"
    },
    "verbosity": "string"
  }
}

属性值

Microsoft.ApiManagement/service/diagnostics

名字 描述 价值
apiVersion API 版本 '2024-05-01'
名字 资源名称 字符串

约束:
最小长度 = 1
最大长度 = 80
模式 = ^[^*#&+:<>?]+$ (必需)
性能 诊断实体协定属性。 DiagnosticContractProperties
类型 资源类型 “Microsoft.ApiManagement/service/diagnostics”

BodyDiagnosticSettings (身体诊断设置)

名字 描述 价值
字节 要记录的请求正文字节数。 int

约束:
最大值 = 8192

数据掩码

名字 描述 价值
头 标头的掩码设置 DataMaskingEntity[]
queryParams 查询参数 Url 查询参数的掩码设置 DataMaskingEntity[]

DataMaskingEntity 数据掩码实体

名字 描述 价值
模式 数据掩码模式。 “隐藏”
“Mask”
价值 要屏蔽的实体的名称(例如标头或查询参数的名称)。 字符串

DiagnosticContractProperties

名字 描述 价值
alwaysLog 指定不应应用哪种类型的消息采样设置。 “allErrors”
后端 传入/传出 HTTP 消息到后端的诊断设置 PipelineDiagnosticSettings
前端 传入/传出 HTTP 消息到网关的诊断设置。 PipelineDiagnosticSettings
httpCorrelationProtocol 协议 设置要用于 Application Insights 诊断的相关协议。 “Legacy”
“None”
“W3C”
日志客户端 Ip 记录 ClientIP。 默认值为 false。 布尔
loggerId (记录器标识) 目标记录器的资源 ID。 string (必需)
指标 通过发出指标策略发出自定义指标。 仅适用于 Application Insights 诊断设置。 布尔
operationNameFormat Application Insights 遥测的操作名称的格式。 默认值为 Name。 “Name”
“Url”
抽样 诊断的采样设置。 采样设置
详细程度 应用于跟踪策略发出的跟踪的详细级别。 “error”
“information”
“verbose”

HttpMessageDiagnostic

名字 描述 价值
身体 正文日志记录设置。 BodyDiagnosticSettings (身体诊断设置)
数据掩码 数据掩码设置。 数据掩码
头 要记录的 HTTP 标头数组。 字符串[]

PipelineDiagnosticSettings

名字 描述 价值
申请 请求的诊断设置。 HttpMessageDiagnostic
响应 响应的诊断设置。 HttpMessageDiagnostic

采样设置

名字 描述 价值
百分比 固定速率采样的采样率。 int

约束:
最小值 = 0
最大值 = 100
采样类型 采样类型。 “fixed”

Terraform (AzAPI 提供程序)资源定义

可以使用目标操作部署服务/诊断资源类型:

  • 资源组 关于每个API版本中变更属性的列表,请参见 更改日志。

用法示例

Terraform 示例

部署 API 管理服务诊断的基本示例。

terraform {
  required_providers {
    azapi = {
      source = "Azure/azapi"
    }
  }
}

provider "azapi" {
  skip_provider_registration = false
}

variable "resource_name" {
  type    = string
  default = "acctest0001"
}

variable "location" {
  type    = string
  default = "westeurope"
}

resource "azapi_resource" "resourceGroup" {
  type     = "Microsoft.Resources/resourceGroups@2020-06-01"
  name     = var.resource_name
  location = var.location
}

resource "azapi_resource" "component" {
  type      = "Microsoft.Insights/components@2020-02-02"
  parent_id = azapi_resource.resourceGroup.id
  name      = var.resource_name
  location  = var.location
  body = {
    kind = "web"
    properties = {
      Application_Type                = "web"
      DisableIpMasking                = false
      DisableLocalAuth                = false
      ForceCustomerStorageForProfiler = false
      RetentionInDays                 = 90
      SamplingPercentage              = 100
      publicNetworkAccessForIngestion = "Enabled"
      publicNetworkAccessForQuery     = "Enabled"
    }
  }
  schema_validation_enabled = false
  response_export_values    = ["*"]
}

resource "azapi_resource" "service" {
  type      = "Microsoft.ApiManagement/service@2021-08-01"
  parent_id = azapi_resource.resourceGroup.id
  name      = var.resource_name
  location  = var.location
  body = {
    properties = {
      certificates = [
      ]
      customProperties = {
        "Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Ssl30" = "false"
        "Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls10" = "false"
        "Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls11" = "false"
        "Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls10"         = "false"
        "Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls11"         = "false"
      }
      disableGateway      = false
      publicNetworkAccess = "Enabled"
      publisherEmail      = "pub1@email.com"
      publisherName       = "pub1"
      virtualNetworkType  = "None"
    }
    sku = {
      capacity = 0
      name     = "Consumption"
    }
  }
  schema_validation_enabled = false
  response_export_values    = ["*"]
}

resource "azapi_resource" "logger" {
  type      = "Microsoft.ApiManagement/service/loggers@2021-08-01"
  parent_id = azapi_resource.service.id
  name      = var.resource_name
  body = {
    properties = {
      credentials = {
        instrumentationKey = azapi_resource.component.output.properties.InstrumentationKey
      }
      description = ""
      isBuffered  = true
      loggerType  = "applicationInsights"
    }
  }
  schema_validation_enabled = false
  response_export_values    = ["*"]
  lifecycle {
    ignore_changes = [body.properties.credentials.instrumentationKey]
  }
}

resource "azapi_resource" "diagnostic" {
  type      = "Microsoft.ApiManagement/service/diagnostics@2021-08-01"
  parent_id = azapi_resource.service.id
  name      = "applicationinsights"
  body = {
    properties = {
      loggerId            = azapi_resource.logger.id
      operationNameFormat = "Name"
    }
  }
  schema_validation_enabled = false
  response_export_values    = ["*"]
}

资源格式

若要创建 Microsoft.ApiManagement/service/diagnostics 资源,请将以下 Terraform 添加到模板。

resource "azapi_resource" "symbolicname" {
  type = "Microsoft.ApiManagement/service/diagnostics@2024-05-01"
  name = "string"
  parent_id = "string"
  body = {
    properties = {
      alwaysLog = "string"
      backend = {
        request = {
          body = {
            bytes = int
          }
          dataMasking = {
            headers = [
              {
                mode = "string"
                value = "string"
              }
            ]
            queryParams = [
              {
                mode = "string"
                value = "string"
              }
            ]
          }
          headers = [
            "string"
          ]
        }
        response = {
          body = {
            bytes = int
          }
          dataMasking = {
            headers = [
              {
                mode = "string"
                value = "string"
              }
            ]
            queryParams = [
              {
                mode = "string"
                value = "string"
              }
            ]
          }
          headers = [
            "string"
          ]
        }
      }
      frontend = {
        request = {
          body = {
            bytes = int
          }
          dataMasking = {
            headers = [
              {
                mode = "string"
                value = "string"
              }
            ]
            queryParams = [
              {
                mode = "string"
                value = "string"
              }
            ]
          }
          headers = [
            "string"
          ]
        }
        response = {
          body = {
            bytes = int
          }
          dataMasking = {
            headers = [
              {
                mode = "string"
                value = "string"
              }
            ]
            queryParams = [
              {
                mode = "string"
                value = "string"
              }
            ]
          }
          headers = [
            "string"
          ]
        }
      }
      httpCorrelationProtocol = "string"
      logClientIp = bool
      loggerId = "string"
      metrics = bool
      operationNameFormat = "string"
      sampling = {
        percentage = int
        samplingType = "string"
      }
      verbosity = "string"
    }
  }
}

属性值

Microsoft.ApiManagement/service/diagnostics

名字 描述 价值
名字 资源名称 字符串

约束:
最小长度 = 1
最大长度 = 80
模式 = ^[^*#&+:<>?]+$ (必需)
parent_id 此资源的父资源的 ID。 类型资源的 ID:服务
性能 诊断实体协定属性。 DiagnosticContractProperties
类型 资源类型 “Microsoft.ApiManagement/service/diagnostics@2024-05-01”

BodyDiagnosticSettings (身体诊断设置)

名字 描述 价值
字节 要记录的请求正文字节数。 int

约束:
最大值 = 8192

数据掩码

名字 描述 价值
头 标头的掩码设置 DataMaskingEntity[]
queryParams 查询参数 Url 查询参数的掩码设置 DataMaskingEntity[]

DataMaskingEntity 数据掩码实体

名字 描述 价值
模式 数据掩码模式。 “隐藏”
“Mask”
价值 要屏蔽的实体的名称(例如标头或查询参数的名称)。 字符串

DiagnosticContractProperties

名字 描述 价值
alwaysLog 指定不应应用哪种类型的消息采样设置。 “allErrors”
后端 传入/传出 HTTP 消息到后端的诊断设置 PipelineDiagnosticSettings
前端 传入/传出 HTTP 消息到网关的诊断设置。 PipelineDiagnosticSettings
httpCorrelationProtocol 协议 设置要用于 Application Insights 诊断的相关协议。 “Legacy”
“None”
“W3C”
日志客户端 Ip 记录 ClientIP。 默认值为 false。 布尔
loggerId (记录器标识) 目标记录器的资源 ID。 string (必需)
指标 通过发出指标策略发出自定义指标。 仅适用于 Application Insights 诊断设置。 布尔
operationNameFormat Application Insights 遥测的操作名称的格式。 默认值为 Name。 “Name”
“Url”
抽样 诊断的采样设置。 采样设置
详细程度 应用于跟踪策略发出的跟踪的详细级别。 “error”
“information”
“verbose”

HttpMessageDiagnostic

名字 描述 价值
身体 正文日志记录设置。 BodyDiagnosticSettings (身体诊断设置)
数据掩码 数据掩码设置。 数据掩码
头 要记录的 HTTP 标头数组。 字符串[]

PipelineDiagnosticSettings

名字 描述 价值
申请 请求的诊断设置。 HttpMessageDiagnostic
响应 响应的诊断设置。 HttpMessageDiagnostic

采样设置

名字 描述 价值
百分比 固定速率采样的采样率。 int

约束:
最小值 = 0
最大值 = 100
采样类型 采样类型。 “fixed”