|
1 | 1 | ---
|
2 |
| -title: Application Insights to troubleshoot Custom Policies in Azure Active Directory B2C | Microsoft Docs |
3 |
| -description: how to setup Application Insights to trace the execution of custom policies. |
| 2 | +title: Troubleshoot custom policies with Application Insights - Azure Active Directory B2C |
| 3 | +description: How to set up Application Insights to trace the execution of your custom policies. |
4 | 4 | services: active-directory-b2c
|
5 | 5 | author: mmacy
|
6 | 6 | manager: celestedg
|
7 | 7 |
|
8 | 8 | ms.service: active-directory
|
9 | 9 | ms.workload: identity
|
10 | 10 | ms.topic: conceptual
|
11 |
| -ms.date: 08/04/2017 |
| 11 | +ms.date: 11/04/2019 |
12 | 12 | ms.author: marsma
|
13 | 13 | ms.subservice: B2C
|
14 | 14 | ---
|
15 | 15 |
|
16 |
| -# Azure Active Directory B2C: Collecting Logs |
| 16 | +# Collect Azure Active Directory B2C logs with Application Insights |
17 | 17 |
|
18 |
| -This article provides steps for collecting logs from Azure AD B2C so that you can diagnose problems with your custom policies. |
| 18 | +This article provides steps for collecting logs from Active Directory B2C (Azure AD B2C) so that you can diagnose problems with your custom policies. Application Insights provides a way to diagnose exceptions and visualize application performance issues. Azure AD B2C includes a feature for sending data to Application Insights. |
19 | 19 |
|
20 |
| ->[!NOTE] |
21 |
| ->Currently, the detailed activity logs described here are designed **ONLY** to aid in development of custom policies. Do not use development mode in production. Logs collect all claims sent to and from the identity providers during development. If used in production, the developer assumes responsibility for PII (Privately Identifiable Information) collected in the App Insights log that they own. These detailed logs are only collected when the policy is placed on **DEVELOPMENT MODE**. |
| 20 | +The detailed activity logs described here should be enabled **ONLY** during the development of your custom policies. |
22 | 21 |
|
| 22 | +> [!WARNING] |
| 23 | +> Do not enable development mode in production. Logs collect all claims sent to and from identity providers. You as the developer assume responsibility for any personal data collected in your Application Insights logs. These detailed logs are collected only when the policy is placed in **DEVELOPER MODE**. |
23 | 24 |
|
24 |
| -## Use Application Insights |
| 25 | +## Set up Application Insights |
25 | 26 |
|
26 |
| -Azure AD B2C supports a feature for sending data to Application Insights. Application Insights provides a way to diagnose exceptions and visualize application performance issues. |
| 27 | +If you don't already have one, create an instance of Application Insights in your subscription. |
27 | 28 |
|
28 |
| -### Setup Application Insights |
| 29 | +1. Sign in to the [Azure portal](https://portal.azure.com). |
| 30 | +1. Select the **Directory + subscription** filter in the top menu, and then select the directory that contains your Azure subscription (not your Azure AD B2C directory). |
| 31 | +1. Select **Create a resource** in the left-hand navigation menu. |
| 32 | +1. Search for and select **Application Insights**, then select **Create**. |
| 33 | +1. Complete the form, select **Review + create**, and then select **Create**. |
| 34 | +1. Once the deployment has been completed, select **Go to resource**. |
| 35 | +1. Under **Configure** in Application Insights menu, select **Properties**. |
| 36 | +1. Record the **INSTRUMENTATION KEY** for use in a later step. |
29 | 37 |
|
30 |
| -1. Go to the [Azure portal](https://portal.azure.com). Ensure you are in the tenant with your Azure subscription (not your Azure AD B2C tenant). |
31 |
| -1. Click **+ New** in the left-hand navigation menu. |
32 |
| -1. Search for and select **Application Insights**, then click **Create**. |
33 |
| -1. Complete the form and click **Create**. Select **General** for the **Application Type**. |
34 |
| -1. Once the resource has been created, open the Application Insights resource. |
35 |
| -1. Find **Properties** in the left-menu, and click on it. |
36 |
| -1. Copy the **Instrumentation Key** and save it for the next section. |
| 38 | +## Configure the custom policy |
37 | 39 |
|
38 |
| -### Set up the custom policy |
39 |
| - |
40 |
| -1. Open the RP file (for example, SignUpOrSignin.xml). |
| 40 | +1. Open the relying party (RP) file, for example *SignUpOrSignin.xml*. |
41 | 41 | 1. Add the following attributes to the `<TrustFrameworkPolicy>` element:
|
42 | 42 |
|
43 | 43 | ```XML
|
44 | 44 | DeploymentMode="Development"
|
45 | 45 | UserJourneyRecorderEndpoint="urn:journeyrecorder:applicationinsights"
|
46 | 46 | ```
|
47 | 47 |
|
48 |
| -1. If it doesn't exist already, add a child node `<UserJourneyBehaviors>` to the `<RelyingParty>` node. It must be located immediately after the `<DefaultUserJourney ReferenceId="UserJourney Id from your extensions policy, or equivalent (for example:SignUpOrSigninWithAAD" />` |
49 |
| -2. Add the following node as a child of the `<UserJourneyBehaviors>` element. Make sure to replace `{Your Application Insights Key}` with the **Instrumentation Key** that you obtained from Application Insights in the previous section. |
| 48 | +1. If it doesn't already exist, add a `<UserJourneyBehaviors>` child node to the `<RelyingParty>` node. It must be located immediately after `<DefaultUserJourney ReferenceId="UserJourney Id" from your extensions policy, or equivalent (for example:SignUpOrSigninWithAAD" />`. |
| 49 | +1. Add the following node as a child of the `<UserJourneyBehaviors>` element. Make sure to replace `{Your Application Insights Key}` with the Application Insights **Instrumentation Key** that you recorded earlier. |
50 | 50 |
|
51 |
| - ```XML |
52 |
| - <JourneyInsights TelemetryEngine="ApplicationInsights" InstrumentationKey="{Your Application Insights Key}" DeveloperMode="true" ClientEnabled="false" ServerEnabled="true" TelemetryVersion="1.0.0" /> |
53 |
| - ``` |
| 51 | + ```XML |
| 52 | + <JourneyInsights TelemetryEngine="ApplicationInsights" InstrumentationKey="{Your Application Insights Key}" DeveloperMode="true" ClientEnabled="false" ServerEnabled="true" TelemetryVersion="1.0.0" /> |
| 53 | + ``` |
54 | 54 |
|
55 |
| - * `DeveloperMode="true"` tells ApplicationInsights to expedite the telemetry through the processing pipeline, good for development, but constrained at high volumes. |
56 |
| - * `ClientEnabled="true"` sends the ApplicationInsights client-side script for tracking page view and client-side errors (not needed). |
57 |
| - * `ServerEnabled="true"` sends the existing UserJourneyRecorder JSON as a custom event to Application Insights. |
58 |
| - Sample: |
| 55 | + * `DeveloperMode="true"` tells ApplicationInsights to expedite the telemetry through the processing pipeline. Good for development, but constrained at high volumes. |
| 56 | + * `ClientEnabled="true"` sends the ApplicationInsights client-side script for tracking page view and client-side errors. You can view these in the **browserTimings** table in the Application Insights portal. By setting `ClientEnabled= "true"`, you add Application Insights to your page script and you get timings of page loads and AJAX calls, counts, details of browser exceptions and AJAX failures, and user and session counts. This field is **optional**, and is set to `false` by default. |
| 57 | + * `ServerEnabled="true"` sends the existing UserJourneyRecorder JSON as a custom event to Application Insights. |
59 | 58 |
|
60 |
| - ```XML |
61 |
| - <TrustFrameworkPolicy |
62 |
| - ... |
63 |
| - TenantId="fabrikamb2c.onmicrosoft.com" |
64 |
| - PolicyId="SignUpOrSignInWithAAD" |
65 |
| - DeploymentMode="Development" |
66 |
| - UserJourneyRecorderEndpoint="urn:journeyrecorder:applicationinsights" |
67 |
| - > |
| 59 | + For example: |
| 60 | + |
| 61 | + ```XML |
| 62 | + <TrustFrameworkPolicy |
| 63 | + ... |
| 64 | + TenantId="fabrikamb2c.onmicrosoft.com" |
| 65 | + PolicyId="SignUpOrSignInWithAAD" |
| 66 | + DeploymentMode="Development" |
| 67 | + UserJourneyRecorderEndpoint="urn:journeyrecorder:applicationinsights" |
| 68 | + > |
68 | 69 | ...
|
69 | 70 | <RelyingParty>
|
70 | 71 | <DefaultUserJourney ReferenceId="UserJourney ID from your extensions policy, or equivalent (for example: SignUpOrSigninWithAzureAD)" />
|
71 | 72 | <UserJourneyBehaviors>
|
72 | 73 | <JourneyInsights TelemetryEngine="ApplicationInsights" InstrumentationKey="{Your Application Insights Key}" DeveloperMode="true" ClientEnabled="false" ServerEnabled="true" TelemetryVersion="1.0.0" />
|
73 | 74 | </UserJourneyBehaviors>
|
74 | 75 | ...
|
75 |
| - </TrustFrameworkPolicy> |
76 |
| - ``` |
| 76 | + </TrustFrameworkPolicy> |
| 77 | + ``` |
77 | 78 |
|
78 |
| -3. Upload the policy. |
| 79 | +1. Upload the policy. |
79 | 80 |
|
80 |
| -### See the logs in Application Insights |
| 81 | +## See the logs in Application Insights |
81 | 82 |
|
82 |
| ->[!NOTE] |
83 |
| -> There is a short delay (less than five minutes) before you can see new logs in Application Insights. |
| 83 | +There is a short delay, typically less than five minutes, before you can see new logs in Application Insights. |
84 | 84 |
|
85 | 85 | 1. Open the Application Insights resource that you created in the [Azure portal](https://portal.azure.com).
|
86 |
| -1. In the **Overview** menu, click on **Analytics**. |
| 86 | +1. In the **Overview** menu, select **Analytics**. |
87 | 87 | 1. Open a new tab in Application Insights.
|
88 |
| -1. Here is a list of queries you can use to see the logs |
| 88 | + |
| 89 | +Here is a list of queries you can use to see the logs: |
89 | 90 |
|
90 | 91 | | Query | Description |
|
91 | 92 | |---------------------|--------------------|
|
92 |
| -traces | See all of the logs generated by Azure AD B2C | |
93 |
| -traces \| where timestamp > ago(1d) | See all of the logs generated by Azure AD B2C for the last day |
94 |
| - |
95 |
| -The entries may be long. Export to CSV for a closer look. |
96 |
| - |
97 |
| -You can learn more about the Analytics tool [here](https://docs.microsoft.com/azure/application-insights/app-insights-analytics). |
98 |
| - |
99 |
| ->[!NOTE] |
100 |
| ->The community has developed a user journey viewer to help identity developers. It is not supported by Microsoft and made available strictly as-is. It reads from your Application Insights instance and provides a well-structured view of the user journey events. You obtain the source code and deploy it in your own solution. |
| 93 | +`traces` | See all of the logs generated by Azure AD B2C | |
| 94 | +`traces | where timestamp > ago(1d)` | See all of the logs generated by Azure AD B2C for the last day |
101 | 95 |
|
102 |
| -The version of the viewer that reads events from Application Insights is located [here](https://github.com/Azure-Samples/active-directory-b2c-advanced-policies/tree/master/wingtipgamesb2c/src/WingTipUserJourneyPlayerWebApplication) |
| 96 | +The entries may be long. Export to CSV for a closer look. |
103 | 97 |
|
104 |
| ->[!NOTE] |
105 |
| ->Currently, the detailed activity logs described here are designed **ONLY** to aid in development of custom policies. Do not use development mode in production. Logs collect all claims sent to and from the identity providers during development. If used in production, the developer assumes responsibility for PII (Privately Identifiable Information) collected in the App Insights log that they own. These detailed logs are only collected when the policy is placed on **DEVELOPMENT MODE**. |
| 98 | +For more information about querying, see [Overview of log queries in Azure Monitor](../azure-monitor/log-query/log-query-overview.md). |
106 | 99 |
|
107 |
| -[GitHub Repository for Unsupported Custom Policy Samples and Related tools](https://github.com/Azure-Samples/active-directory-b2c-advanced-policies) |
| 100 | +## Next steps |
108 | 101 |
|
| 102 | +The community has developed a user journey viewer to help identity developers. It reads from your Application Insights instance and provides a well-structured view of the user journey events. You obtain the source code and deploy it in your own solution. |
109 | 103 |
|
| 104 | +The user journey player is not supported by Microsoft, and is made available strictly as-is. |
110 | 105 |
|
111 |
| -## Next Steps |
| 106 | +You can find the version of the viewer that reads events from Application Insights on GitHub, here: |
112 | 107 |
|
113 |
| -Explore the data in Application Insights to help you understand how the Identity Experience Framework underlying B2C works to deliver your own identity experiences. |
| 108 | +[Azure-Samples/active-directory-b2c-advanced-policies](https://github.com/Azure-Samples/active-directory-b2c-advanced-policies/tree/master/wingtipgamesb2c/src/WingTipUserJourneyPlayerWebApplication) |
0 commit comments