在 Azure AD B2C 自定义策略中定义 Application Insights 技术配置文件Define an Application Insights technical profile in an Azure AD B2C custom policy

备注

在 Azure Active Directory B2C 中,custom policies 主要用于解决复杂方案。In Azure Active Directory B2C, custom policies are designed primarily to address complex scenarios. 大多数情况下,建议使用内置的用户流For most scenarios, we recommend that you use built-in user flows.

Azure Active Directory B2C (Azure AD B2C) 支持使用提供给 Azure AD B2C 的检测密钥将事件数据直接发送到 Application InsightsAzure Active Directory B2C (Azure AD B2C) supports sending event data directly to Application Insights by using the instrumentation key provided to Azure AD B2C. 使用 Application Insights 技术配置文件,你可以获取用户旅程的详细自定义事件日志,以便执行以下操作:With an Application Insights technical profile, you can get detailed and customized event logs for your user journeys to:

  • 洞察用户行为。Gain insights on user behavior.
  • 排查自己在开发或生产过程中的策略问题。Troubleshoot your own policies in development or in production.
  • 衡量性能。Measure performance.
  • 通过 Application Insights 创建通知。Create notifications from Application Insights.

协议Protocol

“Protocol”元素的“Name”属性必须设置为 ProprietaryThe Name attribute of the Protocol element needs to be set to Proprietary. handler 属性必须包含可供 Azure AD B2C 用于 Application Insights 的协议处理程序程序集的完全限定名称:Web.TPEngine.Providers.AzureApplicationInsightsProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nullThe handler attribute must contain the fully qualified name of the protocol handler assembly that is used by Azure AD B2C for Application Insights: Web.TPEngine.Providers.AzureApplicationInsightsProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

以下示例显示了常见的 Application Insights 技术配置文件。The following example shows the common Application Insights technical profile. 其他 Application Insights 技术配置文件包括 AzureInsights-Common,这是为了利用其配置。Other Application Insights technical profiles include the AzureInsights-Common to leverage its configuration.

<TechnicalProfile Id="AzureInsights-Common">
  <DisplayName>Azure Insights Common</DisplayName>
  <Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.Insights.AzureApplicationInsightsProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</TechnicalProfile>

输入声明Input claims

InputClaims 元素包含要发送到 Application Insights 的声明的列表。The InputClaims element contains a list of claims to send to Application Insights. 你还可以将声明名称映射到你希望在 Application Insights 中显示的名称。You can also map the name of your claim to a name you prefer to appear in Application Insights. 以下示例展示了如何将遥测数据发送到 Application Insights。The following example shows how to send telemetries to Application Insights. 通过语法 {property:NAME} 添加事件的属性,其中的 NAME 是要添加到事件的属性。Properties of an event are added through the syntax {property:NAME}, where NAME is property being added to the event. DefaultValue 可以是静态值,也可以是由受支持的声明解析程序之一解析的值。DefaultValue can be either a static value or a value that's resolved by one of the supported claim resolvers.

<InputClaims>
  <InputClaim ClaimTypeReferenceId="PolicyId" PartnerClaimType="{property:Policy}" DefaultValue="{Policy:PolicyId}" />
  <InputClaim ClaimTypeReferenceId="CorrelationId" PartnerClaimType="{property:JourneyId}" DefaultValue="{Context:CorrelationId}" />
  <InputClaim ClaimTypeReferenceId="Culture" PartnerClaimType="{property:Culture}" DefaultValue="{Culture:RFC5646}" />
  <InputClaim ClaimTypeReferenceId="objectId" PartnerClaimType="{property:objectId}"  />
</InputClaims>

InputClaimsTransformations 元素可以包含用于在将输入声明发送到 Application Insights 之前修改输入声明或者生成新输入声明的 InputClaimsTransformation 元素集合。The InputClaimsTransformations element may contain a collection of InputClaimsTransformation elements that are used to modify the input claims or generate new ones before sending to Application Insights.

保存声明Persist claims

不使用 PersistedClaims 元素。The PersistedClaims element is not used.

输出声明Output claims

不使用 OutputClaims 和 OutputClaimsTransformations 元素。The OutputClaims, and OutputClaimsTransformations elements are not used.

加密密钥Cryptographic keys

不使用 CryptographicKeys 元素。The CryptographicKeys element is not used.

MetadataMetadata

属性Attribute 必须Required 说明Description
InstrumentationKeyInstrumentationKey Yes Application Insights 检测密钥,将用于记录事件。The Application Insights instrumentation key, which will be used for logging the events.
DeveloperModeDeveloperMode No 一个布尔值,指示是否启用开发人员模式。A Boolean that indicates whether developer mode is enabled. 可能的值:truefalse(默认值)。Possible values: true or false (default). 此元数据控制如何缓冲事件。This metadata controls how events are buffered. 在事件量最少的开发环境中,启用开发人员模式会导致系统立即将事件发送到 Application Insights。In a development environment with minimal event volume, enabling developer mode results in events being sent immediately to Application Insights.
DisableTelemetryDisableTelemetry No 一个布尔值,指示是否应启用遥测。A Boolean that indicates whether telemetry should be enabled or not. 可能的值:truefalse(默认值)。Possible values: true or false (default).

后续步骤Next steps