-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExampleUsage_Complex_MainRun.ps1
75 lines (58 loc) · 2.58 KB
/
ExampleUsage_Complex_MainRun.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
Get-ChildItem -Path "examples" -Filter *.psm1 -Recurse | ForEach-Object {
Import-Module $_.FullName
}
###############
## Set Application Insights Variables
###############
Write-Host "Load Application Insights Modules"
$currentFunctionName = "ExampleUsage_Simple_MainRun.ps1"
$ENV:APPLICATIONINSIGHTS_CONNECTION_STRING = "InstrumentationKey=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;IngestionEndpoint=https://example-0.in.applicationinsights.azure.com/;LiveEndpoint=https://example.livediagnostics.monitor.azure.com/;ApplicationId=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
###############
## Load Application Insights Modules
###############
Write-Host "Load Application Insights Modules"
Get-ChildItem -Path "modules" -Filter *.psm1 -Recurse | ForEach-Object {
Import-Module $_.FullName
}
###############
## Initialize Application Insights Request Activity
###############
Write-Host "Initialize Application Insights Request Activity"
$AppInsRootRequestActivity = New-EEAppInsActivity -CloudRoleName $currentFunctionName -AppInsParentActivity $null -CloudRoleInstance $env:computername
###############
## Verifying if dependencies services are available.
###############
Write-EELog "Verifying if dependencies services are available." -delimiterSize "large" -AppInsRequestActivity $AppInsRootRequestActivity
$dependentServices = @(
"https://login.microsoftonline.com/common/oauth2/token",
"https://login.microsoftonline.com/common/oauth2/v2.0/token",
"https://graph.microsoft.com/v1.0"
)
foreach ($service in $dependentServices) {
if (!(Confirm-EEDependencyEndpoint -Endpoint $service -AppInsParentActivity $AppInsRootRequestActivity)) {
Write-EELog "Service $service is not available. Exiting script." -AppInsRequestActivity $AppInsRootRequestActivity
exit 1
}
Write-EELog "Service $service is available. Continuing processing." -AppInsRequestActivity $AppInsRootRequestActivity
}
###############
##
## Call
##
###############
$Uri = "https://prices.azure.com/api/retail/prices?`$filter=serviceName eq 'Virtual Machines'"
$Method = "GET"
$Headers = @{}
Invoke-EERestMethod -Uri $Uri -Method $Method -Body $Body -Headers $Headers -AppInsParentActivity $AppInsRootRequestActivity
###############
##
## Subroutine Call
##
###############
Write-EELog "Call a Subroutine" -delimiterSize "large" -AppInsRequestActivity $AppInsRootRequestActivity
New-ComplexSubRoutineCall -maxDepth 2 `
-AppInsParentActivity $AppInsRootRequestActivity
###############
## Application Insights Telemetry
###############
Send-EEAppInsRequestLog -AppInsRequestActivity $AppInsRootRequestActivity