You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Save all files, switch from Debug to Release, and select F6 to rebuild. In Solution Explorer, right-click **Voting** and select **Publish**. Select the connection endpoint of the cluster created in [Deploy an application to a cluster](service-fabric-tutorial-deploy-app-to-party-cluster.md), or select another cluster. Select **Publish** to publish the application to the remote cluster.
433
+
Save all files, switch from Debug to Release, and select F6 to rebuild. In Solution Explorer, right-click **Voting** and select **Publish**. Select the connection endpoint of the cluster created in [Deploy an application to a cluster](service-fabric-tutorial-deploy-app.md), or select another cluster. Select **Publish** to publish the application to the remote cluster.
434
434
435
435
When the application deploys, open a web browser and go to `https://mycluster.region.cloudapp.azure.com:443` (update the URL with the connection endpoint for your cluster). If you're using a self-signed certificate, you see a warning that your PC doesn't trust this website's security. Continue to the webpage.
Copy file name to clipboardExpand all lines: articles/service-fabric/service-fabric-tutorial-monitoring-aspnet.md
+38-38Lines changed: 38 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ ms.date: 05/17/2024
11
11
12
12
# Tutorial: Monitor and diagnose an ASP.NET Core application on Service Fabric by using Application Insights
13
13
14
-
This tutorial is *part five* in a series. It walks through the steps to configure monitoring and diagnostics for an ASP.NET Core application running on an Azure Service Fabric cluster by using Application Insights. You collect telemetry from the application that's developed in [part one of the tutorial](service-fabric-tutorial-create-dotnet-app.md).
14
+
This tutorial is *part five* in a series. It walks through the steps to configure monitoring and diagnostics for an ASP.NET Core application running on an Azure Service Fabric cluster by using Application Insights. You collect telemetry from the application that's developed in [part one of the tutorial series](service-fabric-tutorial-create-dotnet-app.md).
15
15
16
16
In this tutorial, you learn how to:
17
17
@@ -25,10 +25,10 @@ In this tutorial, you learn how to:
25
25
The tutorial series shows you how to:
26
26
27
27
*[Build a .NET Service Fabric application](service-fabric-tutorial-create-dotnet-app.md)
28
-
*[Deploy the application to a remote cluster](service-fabric-tutorial-deploy-app-to-party-cluster.md)
28
+
*[Deploy the application to a remote cluster](service-fabric-tutorial-deploy-app.md)
29
29
*[Add an HTTPS endpoint to an ASP.NET Core front-end service](service-fabric-tutorial-dotnet-app-enable-https-endpoint.md)
30
30
*[Configure CI/CD by using Azure Pipelines](service-fabric-tutorial-deploy-app-with-cicd-vsts.md)
31
-
* Set up monitoring and diagnostics for the application
31
+
* Set up monitoring and diagnostics for the application (*this tutorial*)
Application Insights is the Azure application performance management platform. We recommend that you use Application Insights for application monitoring and diagnostics in Service Fabric.
52
52
53
-
To create an Application Insights resource, go to the [Azure portal](https://portal.azure.com). Select **+ Create a resource**. On the portal menu, select **Monitoring + Diagnostics**. In the **Popular Azure services** column, under **Application Insights**, select **Create**.
53
+
To create an Application Insights resource, go to the [Azure portal](https://portal.azure.com). Select **Create a resource**. On the portal menu, select **Monitoring + Diagnostics**. In the **Popular Azure services** column, under **Application Insights**, select **Create**.
54
54
55
55
:::image type="content" source="media/service-fabric-tutorial-monitoring-aspnet/new-ai-resource.png" alt-text="Screenshot that shows you how to create a new Application Insights resource.":::
56
56
57
-
Enter or select values for **Subscription**, **Resource group**, and **Name**. For **Region**, choose where you will deploy your Service Fabric cluster in the future. In this tutorial, we deploy the app to a local cluster, so the Azure region is irrelevant. For **Application type**, leave as **ASP.NET web application**.
57
+
Enter or select values for **Subscription**, **Resource group**, and **Name**. For **Region**, choose where to deploy your Service Fabric cluster in the future. In this tutorial, we deploy the app to a local cluster, so the Azure region is irrelevant. For **Application type**, leave as **ASP.NET web application**.
58
58
59
59
:::image type="content" source="media/service-fabric-tutorial-monitoring-aspnet/new-ai-resource-attrib.png" alt-text="Screenshot that shows Application Insights resource attributes.":::
60
60
@@ -70,25 +70,25 @@ To configure Application Insights for the VotingWeb and VotingData services:
70
70
71
71
1. Right-click the name of the service, and select **Add** > **Connected Services** > **Monitoring with Application Insights**.
72
72
73
-
:::image type="content" source="media/service-fabric-tutorial-monitoring-aspnet/configure-ai.png" alt-text="Screenshot that shows configuring Application Insights services.":::
73
+
:::image type="content" source="media/service-fabric-tutorial-monitoring-aspnet/configure-ai.png" alt-text="Screenshot that shows configuring Application Insights services.":::
74
74
75
-
> [!NOTE]
75
+
> [!NOTE]
76
76
> Depending on the project type, when you right-click the name of the service, you might need to select **Add** and then select **Application Insights Telemetry**.
77
77
78
78
1. Select **Get started**.
79
-
1. Sign in to the account that you use for your Azure subscription and select the subscription where you created the Application Insights resource. To find the resource, under the **Resource** dropdown, go to **Existing Application Insights resource**. Select **Register** to add Application Insights to your service.
79
+
1. Sign in to the account that you use for your Azure subscription and select the subscription where you created the Application Insights resource. To find the resource, in **Resource**, go to **Existing Application Insights resource**. Select **Register** to add Application Insights to your service.
80
80
81
81
:::image type="content" source="media/service-fabric-tutorial-monitoring-aspnet/register-ai.png" alt-text="Screenshot that shows how to register Application Insights.":::
82
82
83
-
1.When the dialog that completes the action pops up, select**Finish**.
83
+
1.Select**Finish**.
84
84
85
85
> [!NOTE]
86
86
> Make sure to do these steps for *both* of the services in the application to finish configuring Application Insights for the application.
87
87
> The same Application Insights resource is used for both of the services in order to see incoming and outgoing requests and communication between the services.
88
88
89
89
## Add the Microsoft.ApplicationInsights.ServiceFabric.Native NuGet to the services
90
90
91
-
Application Insights has two Service Fabric-specific NuGet packages that you can use depending on the scenario. One is used with Service Fabric native services, and the other with containers and guest executables. In this case, we're using the Microsoft.ApplicationInsights.ServiceFabric.Native NuGet package to use the understanding of service context that it brings. To read more about the Application Insights SDK and the Service Fabric-specific NuGet packages, see [Microsoft Application Insights for Service Fabric](https://github.com/Microsoft/ApplicationInsights-ServiceFabric/blob/master/README.md).
91
+
Application Insights has two Service Fabric-specific NuGet packages that you can use depending on the scenario. One is used with Service Fabric native services, and the other with containers and guest executables. In this case, we use the Microsoft.ApplicationInsights.ServiceFabric.Native NuGet package to learn about service context. For more information about the Application Insights SDK and the Service Fabric-specific NuGet packages, see [Microsoft Application Insights for Service Fabric](https://github.com/Microsoft/ApplicationInsights-ServiceFabric/blob/master/README.md).
92
92
93
93
To set up the NuGet package:
94
94
@@ -98,27 +98,27 @@ To set up the NuGet package:
98
98
> [!NOTE]
99
99
> You might need to install the Microsoft.ServiceFabric.Diagnostics.Internal package in the same way if it wasn't preinstalled before you installed the Application Insights package.
100
100
101
-
1. Search for **Microsoft.ApplicationInsights.ServiceFabric.Native**, and then select the appropriate NuGet package.
102
-
1.In the right pane, select the **VotingWeb** checkbox and the **VotingData** checkbox. Select **Install**.
101
+
1. Search for **Microsoft.ApplicationInsights.ServiceFabric.Native**, and then select the NuGet package.
102
+
1.On the right pane, select the **VotingWeb** checkbox and the **VotingData** checkbox. Select **Install**.
103
103
104
104
:::image type="content" source="media/service-fabric-tutorial-monitoring-aspnet/ai-sdk-nuget-new.png" alt-text="Screenshot that shows the Application Insights SDK in NuGet.":::
105
105
1. In the **Preview Changes** dialog, select **OK** to accept the license. The NuGet packages are added to the services.
106
106
1. Next, set up the telemetry initializer in the two services. Open *VotingWeb.cs* and *VotingData.cs*. Complete the following steps in both code files:
107
107
108
108
1. Add these two `using` statements at the top of each file, after the existing `using` statements:
109
109
110
-
```csharp
111
-
usingMicrosoft.ApplicationInsights.Extensibility;
112
-
usingMicrosoft.ApplicationInsights.ServiceFabric;
113
-
```
110
+
```csharp
111
+
usingMicrosoft.ApplicationInsights.Extensibility;
112
+
usingMicrosoft.ApplicationInsights.ServiceFabric;
113
+
```
114
114
115
115
1. Inbothfiles, inthenested `return` statementof `CreateServiceInstanceListeners()` or `CreateServiceReplicaListeners()`, under `ConfigureServices` > `services`, withtheothersingletonservicesdeclared, add:
>ThissampleappusesHTTPfor the services to communicate. If you develop an app by using Service Remoting V2, you also add the following lines in the same location in the code:
161
+
>ThissampleappusesHTTPfor the services to communicate. If you develop an app by using Service Fabric Service Remoting V2, also add the following lines in the same location in the code:
At this point, you're ready to deploy the application. Select **Start**at the top (or select F5). Visual Studio builds and packages the application, sets up your local cluster, and deploys the application to the cluster.
171
+
At this point, you're ready to deploy the application. Select **Start** (or select F5). Visual Studio builds and packages the application, sets up your local cluster, and deploys the application to the cluster.
172
172
173
173
> [!NOTE]
174
174
> You might get a build error if you don't have an up-to-date version of the .NET Core SDK installed.
175
175
176
-
When the application is deployed, go to `localhost:8080`, where you should be able to see the Voting Sample single-page application. Vote for a few different items of your choice to create some sample data and telemetry. For example, desserts!
176
+
When the application is deployed, go to `localhost:8080`, where the Voting Sample single-page application is running. Vote for a few different items of your choice to create some sample data and telemetry. For example, desserts!
177
177
178
178
:::image type="content" source="media/service-fabric-tutorial-monitoring-aspnet/vote-sample.png" alt-text="Screenshot that shows an example of voting for types of dessert.":::
179
179
@@ -203,9 +203,9 @@ Application Map can help you understand your application topology better, especi
203
203
204
204
## Add custom instrumentation to your application
205
205
206
-
Although Application Insights provides telemetry out of the box, you might want to add more custom instrumentation. Maybe you might have business needs for custom instrumentation or you want to improve diagnostics when things go wrong in your application. You can ingest custom events and metrics with the [Application Insights API](../azure-monitor/app/api-custom-events-metrics.md).
206
+
Although Application Insights provides telemetry out of the box, you might want to add custom instrumentation. Maybe you have business needs for custom instrumentation or you want to improve diagnostics when things go wrong in your application. You can ingest custom events and metrics by using the [Application Insights API](../azure-monitor/app/api-custom-events-metrics.md).
207
207
208
-
Next, add some custom events to *VoteDataController.cs* (under **VotingData** > **Controllers**) to track when votes are being added and deleted from the underlying *votesDictionary*:
208
+
Next, add some custom events to *VoteDataController.cs* (in `VotingData` > `Controllers`) to track when votes are being added and deleted from the underlying `votesDictionary`:
209
209
210
210
1. Add `using Microsoft.ApplicationInsights;` at the end of the other `using` statements.
211
211
1. Declare a new value for `TelemetryClient` at the start of the class, under the creation of `IReliableStateManager`: `private TelemetryClient telemetry = new TelemetryClient();`.
@@ -260,7 +260,7 @@ public async Task<IActionResult> Delete(string name)
260
260
}
261
261
```
262
262
263
-
When you finish making these changes, select **Start** in the application so that it builds and deploys the latest version. When the application is finished deploying, go to `localhost:8080`, and add and delete some voting options. Then, go back to your Application Insights resource to see the traces for the latest run (as before, traces can take from 1 to 2 minutes to appear in Application Insights). For all the votes that you added and deleted, you should now see an entry for **Custom Event** with all the response telemetry.
263
+
When you finish making these changes, select **Start** in the application so that it builds and deploys the latest version. When the application is finished deploying, go to `localhost:8080`. Add and delete some voting options. Then, go back to your Application Insights resource to see the traces for the latest run (traces take from 1 to 2 minutes to appear in Application Insights). For all the votes that you added and deleted, you should now see an entry for **Custom Event** with associated response telemetry.
264
264
265
265
:::image type="content" source="media/service-fabric-tutorial-monitoring-aspnet/custom-events.png" alt-text="Screenshot that shows custom events.":::
0 commit comments