Skip to content

Commit e9fa402

Browse files
authored
Merge pull request #248777 from AaronMaxwell/aaronmax-functions-availability-sample
Adding basic code sample
2 parents 1cd58f9 + b922863 commit e9fa402

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

articles/azure-monitor/app/availability-azure-functions.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ This article explains how to review [TrackAvailability()](/dotnet/api/microsoft.
1313

1414
> [!div class="checklist"]
1515
> - [Workspace-based Application Insights resource](create-workspace-resource.md)
16-
> - Access to the source code of a [function app](../../azure-functions/functions-how-to-use-azure-function-app-settings.md) in Azure Functions.
17-
> - Developer expertise capable of authoring custom code for [TrackAvailability()](/dotnet/api/microsoft.applicationinsights.telemetryclient.trackavailability), tailored to your specific business needs
16+
> - Access to the source code of a [function app](../../azure-functions/functions-how-to-use-azure-function-app-settings.md) in Azure Functions
17+
> - Developer expertise capable of authoring [custom code](#basic-code-sample) for [TrackAvailability()](/dotnet/api/microsoft.applicationinsights.telemetryclient.trackavailability), tailored to your specific business needs
1818
1919
> [!NOTE]
20-
> - TrackAvailability() requires that you have made a developer investment in custom code.
21-
> - [Standard tests](availability-standard-tests.md) should always be used if possible as they require little investment and have few prerequisites.
20+
> - [TrackAvailability()](/dotnet/api/microsoft.applicationinsights.telemetryclient.trackavailability) requires that you make a developer investment in custom code.
21+
> - [Standard tests](availability-standard-tests.md) **should always be used if possible** as they require little investment, no maintenance, and have few prerequisites.
2222
2323
## Check availability
2424

@@ -43,6 +43,25 @@ You can use Log Analytics to view your availability results, dependencies, and m
4343

4444
:::image type="content" source="media/availability-azure-functions/dependencies.png" alt-text="Screenshot that shows the New Query tab with dependencies limited to 50." lightbox="media/availability-azure-functions/dependencies.png":::
4545

46+
## Basic code sample
47+
48+
The following example demonstrates a web availability test that requires a simple URL ping using the `getStringAsync()` method.
49+
50+
```csharp
51+
using System.Net.Http;
52+
53+
public async static Task RunAvailabilityTestAsync(ILogger log)
54+
{
55+
using (var httpClient = new HttpClient())
56+
{
57+
// TODO: Replace with your business logic
58+
await httpClient.GetStringAsync("https://www.bing.com/");
59+
}
60+
}
61+
```
62+
63+
For advanced scenarios where the business logic must be adjusted to access the URL, such as obtaining tokens, setting parameters, and other test cases, custom code is necessary.
64+
4665
## Next steps
4766

4867
* [Standard tests](availability-standard-tests.md)

0 commit comments

Comments
 (0)