From f5a203751019d8cd1b4c922fc53a7176b7dcaf1d Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 23 May 2024 06:55:26 +0200 Subject: [PATCH 01/86] chore: deploy test resourcs w/ bicep --- build/deploy-test-resources.yml | 42 +++++++++++++++++++++ build/templates/deploy-test-resources.bicep | 34 +++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 build/deploy-test-resources.yml create mode 100644 build/templates/deploy-test-resources.bicep diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml new file mode 100644 index 00000000..6099a97d --- /dev/null +++ b/build/deploy-test-resources.yml @@ -0,0 +1,42 @@ +name: Deploy test resources + +trigger: none +pr: none + +parameters: + - name: azureServiceConnection + type: string + - name: resourceGroupName + value: 'codit-arcus-observability-rg' + - name: appInsightsName + value: 'arcus-observability-dev-we-app-insights' + +variables: + - template: ./variables/build.yml + +stages: + - stage: Deploy + jobs: + - job: Deploy Bicep + pool: + vmImage: '$(Vm.Image)' + steps: + - task: AzureCLI@2 + inputs: + azureSubscription: '${{ parameters.azureServiceConnection }}' + scriptType: 'bash' + scriptLocation: 'inlineScript' + inlineScript: | + Set-PSRepository -Name PSGallery -InstallationPolicy Trusted + Install-Module -Name Arcus.Scripting.DevOps -AllowClobber + + $appInsightsOutput = az deployment sub create ` + --template-file ./build/templates/test-resources.json ` + --parameters '{ \"location\": \"westeurope\", \"appInsightsName\": \"$(appInsightsName)" }' ` + | Convert-FromJson + + $apiKeyOutput = New-AzApplicationInsightsApiKey -ResourceGroupName $(resourceGroupName) -Name $(appInsightsName) -Description 'Asserting tracked telemetry' -Permissions @('ReadTelemetry') + $appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value $apiKeyOutput.ApiKey + + $env:ArmOutputs = $appInsightsOutput + Set-AzDevOpsArmOutputsToVariableGroup -VariableGroupName 'Arcus Observability - Integration Testing' \ No newline at end of file diff --git a/build/templates/deploy-test-resources.bicep b/build/templates/deploy-test-resources.bicep new file mode 100644 index 00000000..935417ef --- /dev/null +++ b/build/templates/deploy-test-resources.bicep @@ -0,0 +1,34 @@ +// Define the location for the deployment of the components. +param location string + +// Define the name of the Application Insights component. +param appInsightsName string + +targetScope='subscription' + +resource resourceGroup 'Microsoft.Resources/resourceGroups@2022-09-01' = { + name: 'arcus-observability-dev-we-rg' + location: location +} + +module workspace 'br/public:avm/res/operational-insights/workspace:0.3.4' = { + name: 'workspaceDeployment' + scope: resourceGroup + params: { + name: 'arcus-observability-dev-we-workspace' + location: location + } +} + +module component 'br/public:avm/res/insights/component:0.3.0' = { + name: 'componentDeployment' + scope: resourceGroup + params: { + name: appInsightsName + workspaceResourceId: workspace.outputs.resourceId + location: location + } +} + +output ApplicationInsights_ApplicationId string = component.outputs.applicationId +output ApplicationInsights_ConnectionString string = component.outputs.connectionString From 63bf571d7426252ed7638cfcf2b6409be4a4cefb Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 23 May 2024 06:59:40 +0200 Subject: [PATCH 02/86] pr-fix: use correct parameter default value --- build/deploy-test-resources.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 6099a97d..dfc3ee50 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -7,9 +7,9 @@ parameters: - name: azureServiceConnection type: string - name: resourceGroupName - value: 'codit-arcus-observability-rg' + default: 'codit-arcus-observability-rg' - name: appInsightsName - value: 'arcus-observability-dev-we-app-insights' + default: 'arcus-observability-dev-we-app-insights' variables: - template: ./variables/build.yml From 3747e1032c1cee3d8b552c966017d999e066676c Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 23 May 2024 07:06:28 +0200 Subject: [PATCH 03/86] pr-fix: remove invalid blank space in job name --- build/deploy-test-resources.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index dfc3ee50..c91d326d 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -17,7 +17,8 @@ variables: stages: - stage: Deploy jobs: - - job: Deploy Bicep + - job: DeployBicep + displayName: 'Deploy test resources' pool: vmImage: '$(Vm.Image)' steps: From 304d8884690abdbdfe49d1e40dcf2e54da964424 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 23 May 2024 07:10:32 +0200 Subject: [PATCH 04/86] pr-fix: use script type 'pscore' --- build/deploy-test-resources.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index c91d326d..91072b59 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -25,7 +25,7 @@ stages: - task: AzureCLI@2 inputs: azureSubscription: '${{ parameters.azureServiceConnection }}' - scriptType: 'bash' + scriptType: 'pscore' scriptLocation: 'inlineScript' inlineScript: | Set-PSRepository -Name PSGallery -InstallationPolicy Trusted From bbd019b8c99c3b2d599398a95b0f822d38d429b7 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 23 May 2024 07:12:21 +0200 Subject: [PATCH 05/86] pr-fix: convert from json syntax error --- build/deploy-test-resources.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 91072b59..7ab8575e 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -34,7 +34,7 @@ stages: $appInsightsOutput = az deployment sub create ` --template-file ./build/templates/test-resources.json ` --parameters '{ \"location\": \"westeurope\", \"appInsightsName\": \"$(appInsightsName)" }' ` - | Convert-FromJson + | ConvertFrom-Json $apiKeyOutput = New-AzApplicationInsightsApiKey -ResourceGroupName $(resourceGroupName) -Name $(appInsightsName) -Description 'Asserting tracked telemetry' -Permissions @('ReadTelemetry') $appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value $apiKeyOutput.ApiKey From 6b5272aa89ebe3e40f75fed43c3282c98108762c Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 23 May 2024 07:33:57 +0200 Subject: [PATCH 06/86] pr-fix: correctly use env vars --- build/deploy-test-resources.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 7ab8575e..c2fee1e5 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -10,6 +10,8 @@ parameters: default: 'codit-arcus-observability-rg' - name: appInsightsName default: 'arcus-observability-dev-we-app-insights' + - name: variableGroupName + default: 'Arcus Observability - Integration Testing' variables: - template: ./variables/build.yml @@ -33,11 +35,11 @@ stages: $appInsightsOutput = az deployment sub create ` --template-file ./build/templates/test-resources.json ` - --parameters '{ \"location\": \"westeurope\", \"appInsightsName\": \"$(appInsightsName)" }' ` + --parameters '{ \"location\": \"westeurope\", \"appInsightsName\": \"$(env:appInsightsName)" }' ` | ConvertFrom-Json - $apiKeyOutput = New-AzApplicationInsightsApiKey -ResourceGroupName $(resourceGroupName) -Name $(appInsightsName) -Description 'Asserting tracked telemetry' -Permissions @('ReadTelemetry') + $apiKeyOutput = New-AzApplicationInsightsApiKey -ResourceGroupName $(env:resourceGroupName) -Name $(env:appInsightsName) -Description 'Asserting tracked telemetry' -Permissions @('ReadTelemetry') $appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value $apiKeyOutput.ApiKey $env:ArmOutputs = $appInsightsOutput - Set-AzDevOpsArmOutputsToVariableGroup -VariableGroupName 'Arcus Observability - Integration Testing' \ No newline at end of file + Set-AzDevOpsArmOutputsToVariableGroup -VariableGroupName $(env:variableGroupName) \ No newline at end of file From f949e31f140d733c7781797b054be58d2531ad47 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 23 May 2024 07:36:02 +0200 Subject: [PATCH 07/86] pr-fix: correctly use env vars --- build/deploy-test-resources.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index c2fee1e5..82b93fe8 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -5,12 +5,20 @@ pr: none parameters: - name: azureServiceConnection + displayName: 'Azure service connection' + description: 'The Azure service connection to deploy the resources with' type: string - name: resourceGroupName + displayName: 'Resource group name' + description: 'The name of the resource group to create the resources in' default: 'codit-arcus-observability-rg' - name: appInsightsName + displayName: 'Application Insights name' + description: 'The name of the Application Insights instance to create' default: 'arcus-observability-dev-we-app-insights' - name: variableGroupName + displayName: 'Variable group name' + description: 'The name of the variable group to store the outputs in' default: 'Arcus Observability - Integration Testing' variables: @@ -35,11 +43,11 @@ stages: $appInsightsOutput = az deployment sub create ` --template-file ./build/templates/test-resources.json ` - --parameters '{ \"location\": \"westeurope\", \"appInsightsName\": \"$(env:appInsightsName)" }' ` + --parameters '{ \"location\": \"westeurope\", \"appInsightsName\": \"$($env:appInsightsName)" }' ` | ConvertFrom-Json - $apiKeyOutput = New-AzApplicationInsightsApiKey -ResourceGroupName $(env:resourceGroupName) -Name $(env:appInsightsName) -Description 'Asserting tracked telemetry' -Permissions @('ReadTelemetry') + $apiKeyOutput = New-AzApplicationInsightsApiKey -ResourceGroupName $env:resourceGroupName -Name $env:appInsightsName -Description 'Asserting tracked telemetry' -Permissions @('ReadTelemetry') $appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value $apiKeyOutput.ApiKey $env:ArmOutputs = $appInsightsOutput - Set-AzDevOpsArmOutputsToVariableGroup -VariableGroupName $(env:variableGroupName) \ No newline at end of file + Set-AzDevOpsArmOutputsToVariableGroup -VariableGroupName $env:variableGroupName \ No newline at end of file From 2790056f9190c9d0a910606aa952f70eb1f280b1 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 23 May 2024 07:37:12 +0200 Subject: [PATCH 08/86] pr-fix: remove invalid params descriptions --- build/deploy-test-resources.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 82b93fe8..2adcfaaf 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -6,19 +6,15 @@ pr: none parameters: - name: azureServiceConnection displayName: 'Azure service connection' - description: 'The Azure service connection to deploy the resources with' type: string - name: resourceGroupName displayName: 'Resource group name' - description: 'The name of the resource group to create the resources in' default: 'codit-arcus-observability-rg' - name: appInsightsName displayName: 'Application Insights name' - description: 'The name of the Application Insights instance to create' default: 'arcus-observability-dev-we-app-insights' - name: variableGroupName displayName: 'Variable group name' - description: 'The name of the variable group to store the outputs in' default: 'Arcus Observability - Integration Testing' variables: From 8fec876aa3a33a9ddd3a253afe4ce3a732c75040 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 23 May 2024 07:39:42 +0200 Subject: [PATCH 09/86] pr-fix: add required location & import app insights module --- build/deploy-test-resources.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 2adcfaaf..5903378c 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -36,8 +36,10 @@ stages: inlineScript: | Set-PSRepository -Name PSGallery -InstallationPolicy Trusted Install-Module -Name Arcus.Scripting.DevOps -AllowClobber + Import-Module Az.ApplicationInsights $appInsightsOutput = az deployment sub create ` + --location westeurope ` --template-file ./build/templates/test-resources.json ` --parameters '{ \"location\": \"westeurope\", \"appInsightsName\": \"$($env:appInsightsName)" }' ` | ConvertFrom-Json From 3cb56bbfc89cdecd40f3746a372cf75d194475fe Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 23 May 2024 07:41:47 +0200 Subject: [PATCH 10/86] pr-fix: install az app insights module --- build/deploy-test-resources.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 5903378c..c7eeaa75 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -36,6 +36,7 @@ stages: inlineScript: | Set-PSRepository -Name PSGallery -InstallationPolicy Trusted Install-Module -Name Arcus.Scripting.DevOps -AllowClobber + Install-Module Az.ApplicationInsights Import-Module Az.ApplicationInsights $appInsightsOutput = az deployment sub create ` From 4878de1758871857d9ffc48b5bd0cb547d6a1bc0 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 23 May 2024 07:47:03 +0200 Subject: [PATCH 11/86] pr-fix: correct usage of parameters --- build/deploy-test-resources.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index c7eeaa75..1e8fd0e5 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -42,11 +42,11 @@ stages: $appInsightsOutput = az deployment sub create ` --location westeurope ` --template-file ./build/templates/test-resources.json ` - --parameters '{ \"location\": \"westeurope\", \"appInsightsName\": \"$($env:appInsightsName)" }' ` + --parameters '{ \"location\": \"westeurope\", \"appInsightsName\": \"${{ parameters.appInsightsName }}" }' ` | ConvertFrom-Json - $apiKeyOutput = New-AzApplicationInsightsApiKey -ResourceGroupName $env:resourceGroupName -Name $env:appInsightsName -Description 'Asserting tracked telemetry' -Permissions @('ReadTelemetry') + $apiKeyOutput = New-AzApplicationInsightsApiKey -ResourceGroupName ${{ parameters.resourceGroupName }} -Name ${{ parameters.appInsightsName }} -Description 'Asserting tracked telemetry' -Permissions @('ReadTelemetry') $appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value $apiKeyOutput.ApiKey $env:ArmOutputs = $appInsightsOutput - Set-AzDevOpsArmOutputsToVariableGroup -VariableGroupName $env:variableGroupName \ No newline at end of file + Set-AzDevOpsArmOutputsToVariableGroup -VariableGroupName ${{ parameters.variableGroupName }} \ No newline at end of file From 23ab8b06347b830b0a5cdea97b808f277b2428ab Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 23 May 2024 07:51:41 +0200 Subject: [PATCH 12/86] pr-fix: pass subscription id --- build/deploy-test-resources.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 1e8fd0e5..38eacfe0 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -41,11 +41,12 @@ stages: $appInsightsOutput = az deployment sub create ` --location westeurope ` - --template-file ./build/templates/test-resources.json ` + --template-file ./build/templates/deploy-test-resources.bicep ` --parameters '{ \"location\": \"westeurope\", \"appInsightsName\": \"${{ parameters.appInsightsName }}" }' ` | ConvertFrom-Json - $apiKeyOutput = New-AzApplicationInsightsApiKey -ResourceGroupName ${{ parameters.resourceGroupName }} -Name ${{ parameters.appInsightsName }} -Description 'Asserting tracked telemetry' -Permissions @('ReadTelemetry') + $subscriptionId = (az account show --query id -o tsv) + $apiKeyOutput = New-AzApplicationInsightsApiKey -SubscriptionId $subscriptionId -ResourceGroupName ${{ parameters.resourceGroupName }} -Name ${{ parameters.appInsightsName }} -Description 'Asserting tracked telemetry' -Permissions @('ReadTelemetry') $appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value $apiKeyOutput.ApiKey $env:ArmOutputs = $appInsightsOutput From e5ba23aae507912fbd963be13e7dc3db34b3982e Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 23 May 2024 07:56:21 +0200 Subject: [PATCH 13/86] pr-fix: login before creating api key --- build/deploy-test-resources.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 38eacfe0..ff666ab7 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -45,8 +45,17 @@ stages: --parameters '{ \"location\": \"westeurope\", \"appInsightsName\": \"${{ parameters.appInsightsName }}" }' ` | ConvertFrom-Json - $subscriptionId = (az account show --query id -o tsv) - $apiKeyOutput = New-AzApplicationInsightsApiKey -SubscriptionId $subscriptionId -ResourceGroupName ${{ parameters.resourceGroupName }} -Name ${{ parameters.appInsightsName }} -Description 'Asserting tracked telemetry' -Permissions @('ReadTelemetry') + # Get the current service principal details + $servicePrincipalConnection = (Get-VstsServiceEndpoint -Context $distributedTaskContext -Id $env:ENDPOINT_AUTH_PARAMETER_SYSTEMVSSCONNECTION_SERVICEENDPOINTID).Auth.Parameters + $spn = @{ + "tenantId" = $servicePrincipalConnection.TenantId + "applicationId" = $servicePrincipalConnection.ServicePrincipalId + "certificateThumbprint" = $servicePrincipalConnection.ServicePrincipalKey + } + + Connect-AzAccount -ServicePrincipal @spn + + $apiKeyOutput = New-AzApplicationInsightsApiKey -ResourceGroupName ${{ parameters.resourceGroupName }} -Name ${{ parameters.appInsightsName }} -Description 'Asserting tracked telemetry' -Permissions @('ReadTelemetry') $appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value $apiKeyOutput.ApiKey $env:ArmOutputs = $appInsightsOutput From f8fefd4669d5768cc11f99b729123c3c0853ab4a Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 23 May 2024 07:58:46 +0200 Subject: [PATCH 14/86] pr-fix: login before creating api key --- build/deploy-test-resources.yml | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index ff666ab7..b1a068cb 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -45,15 +45,10 @@ stages: --parameters '{ \"location\": \"westeurope\", \"appInsightsName\": \"${{ parameters.appInsightsName }}" }' ` | ConvertFrom-Json - # Get the current service principal details - $servicePrincipalConnection = (Get-VstsServiceEndpoint -Context $distributedTaskContext -Id $env:ENDPOINT_AUTH_PARAMETER_SYSTEMVSSCONNECTION_SERVICEENDPOINTID).Auth.Parameters - $spn = @{ - "tenantId" = $servicePrincipalConnection.TenantId - "applicationId" = $servicePrincipalConnection.ServicePrincipalId - "certificateThumbprint" = $servicePrincipalConnection.ServicePrincipalKey - } - - Connect-AzAccount -ServicePrincipal @spn + $context = az account show | ConvertFrom-Json + $securePassword = ConvertTo-SecureString $context.user.password -AsPlainText -Force + $credential = New-Object System.Management.Automation.PSCredential ($context.user.name, $securePassword) + Connect-AzAccount -ServicePrincipal -Credential $credential -Tenant $context.tenantId $apiKeyOutput = New-AzApplicationInsightsApiKey -ResourceGroupName ${{ parameters.resourceGroupName }} -Name ${{ parameters.appInsightsName }} -Description 'Asserting tracked telemetry' -Permissions @('ReadTelemetry') $appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value $apiKeyOutput.ApiKey From 47cf55b7918e9db1720e37baea08224be6057e64 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 23 May 2024 08:02:17 +0200 Subject: [PATCH 15/86] pr-fix: correct multiple params --- build/deploy-test-resources.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index b1a068cb..649396b6 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -39,10 +39,13 @@ stages: Install-Module Az.ApplicationInsights Import-Module Az.ApplicationInsights + $parameters = @{ + "location" = "westeurope" + "appInsightsName" = "${{ parameters.appInsightsName }" } | ConvertTo-Json $appInsightsOutput = az deployment sub create ` --location westeurope ` --template-file ./build/templates/deploy-test-resources.bicep ` - --parameters '{ \"location\": \"westeurope\", \"appInsightsName\": \"${{ parameters.appInsightsName }}" }' ` + --parameters $parameters ` | ConvertFrom-Json $context = az account show | ConvertFrom-Json From ae159ea1124d0ed7e2a4583ae585d29eee5d9d99 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 23 May 2024 08:02:38 +0200 Subject: [PATCH 16/86] pr-fix: correct multiple params --- build/deploy-test-resources.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 649396b6..52fc41a7 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -41,7 +41,7 @@ stages: $parameters = @{ "location" = "westeurope" - "appInsightsName" = "${{ parameters.appInsightsName }" } | ConvertTo-Json + "appInsightsName" = "${{ parameters.appInsightsName }}" } | ConvertTo-Json $appInsightsOutput = az deployment sub create ` --location westeurope ` --template-file ./build/templates/deploy-test-resources.bicep ` From 7197500f80afa91ed223b4af3c15215b647871bd Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 23 May 2024 08:42:43 +0200 Subject: [PATCH 17/86] pr-fix: remove unn login --- build/deploy-test-resources.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 52fc41a7..68297fd9 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -48,11 +48,6 @@ stages: --parameters $parameters ` | ConvertFrom-Json - $context = az account show | ConvertFrom-Json - $securePassword = ConvertTo-SecureString $context.user.password -AsPlainText -Force - $credential = New-Object System.Management.Automation.PSCredential ($context.user.name, $securePassword) - Connect-AzAccount -ServicePrincipal -Credential $credential -Tenant $context.tenantId - $apiKeyOutput = New-AzApplicationInsightsApiKey -ResourceGroupName ${{ parameters.resourceGroupName }} -Name ${{ parameters.appInsightsName }} -Description 'Asserting tracked telemetry' -Permissions @('ReadTelemetry') $appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value $apiKeyOutput.ApiKey From c49969e89d3dc942baa4b25e307edbd69d1668fc Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 23 May 2024 08:53:26 +0200 Subject: [PATCH 18/86] pr-fix: fix json deserialization + sub id set --- build/deploy-test-resources.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 68297fd9..71b700c1 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -41,14 +41,15 @@ stages: $parameters = @{ "location" = "westeurope" - "appInsightsName" = "${{ parameters.appInsightsName }}" } | ConvertTo-Json + "appInsightsName" = ${{ parameters.appInsightsName }} } | ConvertTo-Json $appInsightsOutput = az deployment sub create ` --location westeurope ` --template-file ./build/templates/deploy-test-resources.bicep ` --parameters $parameters ` | ConvertFrom-Json - $apiKeyOutput = New-AzApplicationInsightsApiKey -ResourceGroupName ${{ parameters.resourceGroupName }} -Name ${{ parameters.appInsightsName }} -Description 'Asserting tracked telemetry' -Permissions @('ReadTelemetry') + $subscriptionId = (az account show | ConvertFrom-Json).id + $apiKeyOutput = New-AzApplicationInsightsApiKey -SubscriptionId $subscriptionId -ResourceGroupName ${{ parameters.resourceGroupName }} -Name ${{ parameters.appInsightsName }} -Description 'Asserting tracked telemetry' -Permissions @('ReadTelemetry') $appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value $apiKeyOutput.ApiKey $env:ArmOutputs = $appInsightsOutput From fc55b386c7f09b95cbda62f2e1d63c07f2e531e8 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 23 May 2024 08:57:07 +0200 Subject: [PATCH 19/86] pr-fix: correct multiple param pass --- build/deploy-test-resources.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 71b700c1..5aac3486 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -39,13 +39,11 @@ stages: Install-Module Az.ApplicationInsights Import-Module Az.ApplicationInsights - $parameters = @{ - "location" = "westeurope" - "appInsightsName" = ${{ parameters.appInsightsName }} } | ConvertTo-Json $appInsightsOutput = az deployment sub create ` --location westeurope ` --template-file ./build/templates/deploy-test-resources.bicep ` - --parameters $parameters ` + --parameters location=westeurope ` + --parameters appInsightsName=${{ parameters.appInsightsName }}` | ConvertFrom-Json $subscriptionId = (az account show | ConvertFrom-Json).id From 64c21c6698edced90e1978fb69b959e33d0fbc04 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 23 May 2024 09:03:34 +0200 Subject: [PATCH 20/86] pr-fix: remove single quotes from var names --- build/deploy-test-resources.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 5aac3486..f2da0d45 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -1,4 +1,4 @@ -name: Deploy test resources +name: Arcus Observability - Deploy test resources trigger: none pr: none @@ -9,13 +9,13 @@ parameters: type: string - name: resourceGroupName displayName: 'Resource group name' - default: 'codit-arcus-observability-rg' + default: codit-arcus-observability-rg - name: appInsightsName displayName: 'Application Insights name' - default: 'arcus-observability-dev-we-app-insights' + default: arcus-observability-dev-we-app-insights - name: variableGroupName displayName: 'Variable group name' - default: 'Arcus Observability - Integration Testing' + default: Arcus Observability - Integration Testing variables: - template: ./variables/build.yml From 82e680e5e7a782d32e6af234faad00347d162d82 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 23 May 2024 09:13:14 +0200 Subject: [PATCH 21/86] pr-fix: correct var names --- build/deploy-test-resources.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index f2da0d45..660d7674 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -7,6 +7,7 @@ parameters: - name: azureServiceConnection displayName: 'Azure service connection' type: string + default: 'Azure Codit-Arcus Service Principal' - name: resourceGroupName displayName: 'Resource group name' default: codit-arcus-observability-rg From e31ffc76485146859be9986e2e73cf094c02eea7 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 23 May 2024 09:14:05 +0200 Subject: [PATCH 22/86] pr-fix: correct var names --- build/deploy-test-resources.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 660d7674..bf2bb708 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -44,7 +44,7 @@ stages: --location westeurope ` --template-file ./build/templates/deploy-test-resources.bicep ` --parameters location=westeurope ` - --parameters appInsightsName=${{ parameters.appInsightsName }}` + --parameters appInsightsName=${{ parameters.appInsightsName }} ` | ConvertFrom-Json $subscriptionId = (az account show | ConvertFrom-Json).id From 20acf7cd3274668cc7369149b5e9927259b82d47 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 23 May 2024 09:27:12 +0200 Subject: [PATCH 23/86] pr-fix: explicitly set az context --- build/deploy-test-resources.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index bf2bb708..653cba4a 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -47,8 +47,10 @@ stages: --parameters appInsightsName=${{ parameters.appInsightsName }} ` | ConvertFrom-Json - $subscriptionId = (az account show | ConvertFrom-Json).id - $apiKeyOutput = New-AzApplicationInsightsApiKey -SubscriptionId $subscriptionId -ResourceGroupName ${{ parameters.resourceGroupName }} -Name ${{ parameters.appInsightsName }} -Description 'Asserting tracked telemetry' -Permissions @('ReadTelemetry') + $context = az account show | ConvertFrom-Json + Set-AzContext -SubscriptionId $context.id -TenantId $context.tenantId + + $apiKeyOutput = New-AzApplicationInsightsApiKey -SubscriptionId $context.id -ResourceGroupName ${{ parameters.resourceGroupName }} -Name ${{ parameters.appInsightsName }} -Description 'Asserting tracked telemetry' -Permissions @('ReadTelemetry') $appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value $apiKeyOutput.ApiKey $env:ArmOutputs = $appInsightsOutput From 08a9134e4a0b9c7ba1c04676fa2bada3983f3aa2 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 23 May 2024 09:42:04 +0200 Subject: [PATCH 24/86] pr-fix: use az cli alternative --- build/deploy-test-resources.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 653cba4a..6c4001ea 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -47,10 +47,7 @@ stages: --parameters appInsightsName=${{ parameters.appInsightsName }} ` | ConvertFrom-Json - $context = az account show | ConvertFrom-Json - Set-AzContext -SubscriptionId $context.id -TenantId $context.tenantId - - $apiKeyOutput = New-AzApplicationInsightsApiKey -SubscriptionId $context.id -ResourceGroupName ${{ parameters.resourceGroupName }} -Name ${{ parameters.appInsightsName }} -Description 'Asserting tracked telemetry' -Permissions @('ReadTelemetry') + $apiKeyOutput = az monitor app-insights api-key create --api-key 'Arcus Observability Integration Tests API Key' --app ${{ parameters.appInsightsName }} --resource-group ${{ parameters.resourceGroupName }} --permissions ReadTelemetry | ConvertFrom-Json $appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value $apiKeyOutput.ApiKey $env:ArmOutputs = $appInsightsOutput From de1e60a92996d48d7c52f6089367facbd444c1f3 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 23 May 2024 10:31:26 +0200 Subject: [PATCH 25/86] pr-fix: install app insights extension --- build/deploy-test-resources.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 6c4001ea..98d4c562 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -37,8 +37,7 @@ stages: inlineScript: | Set-PSRepository -Name PSGallery -InstallationPolicy Trusted Install-Module -Name Arcus.Scripting.DevOps -AllowClobber - Install-Module Az.ApplicationInsights - Import-Module Az.ApplicationInsights + az extension add --name application-insights $appInsightsOutput = az deployment sub create ` --location westeurope ` @@ -47,6 +46,7 @@ stages: --parameters appInsightsName=${{ parameters.appInsightsName }} ` | ConvertFrom-Json + $apiKeyOutput = az monitor app-insights api-key create --api-key 'Arcus Observability Integration Tests API Key' --app ${{ parameters.appInsightsName }} --resource-group ${{ parameters.resourceGroupName }} --permissions ReadTelemetry | ConvertFrom-Json $appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value $apiKeyOutput.ApiKey From 781579808c5554d3138e90ff7d3aedf6cf00997b Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 23 May 2024 10:32:18 +0200 Subject: [PATCH 26/86] pr-fix: correct variable group name pass in --- build/deploy-test-resources.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 98d4c562..4a3a3a61 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -51,4 +51,4 @@ stages: $appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value $apiKeyOutput.ApiKey $env:ArmOutputs = $appInsightsOutput - Set-AzDevOpsArmOutputsToVariableGroup -VariableGroupName ${{ parameters.variableGroupName }} \ No newline at end of file + Set-AzDevOpsArmOutputsToVariableGroup -VariableGroupName '${{ parameters.variableGroupName }}' \ No newline at end of file From bfa81bedf140eaea63dd42242074f5583967e0c1 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 28 May 2024 07:40:12 +0200 Subject: [PATCH 27/86] pr-fix: correct read permissions in command --- build/deploy-test-resources.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 4a3a3a61..6f71b0e3 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -46,8 +46,7 @@ stages: --parameters appInsightsName=${{ parameters.appInsightsName }} ` | ConvertFrom-Json - - $apiKeyOutput = az monitor app-insights api-key create --api-key 'Arcus Observability Integration Tests API Key' --app ${{ parameters.appInsightsName }} --resource-group ${{ parameters.resourceGroupName }} --permissions ReadTelemetry | ConvertFrom-Json + $apiKeyOutput = az monitor app-insights api-key create --api-key 'Arcus Observability Integration Tests API Key' --app ${{ parameters.appInsightsName }} --resource-group ${{ parameters.resourceGroupName }} --read-properties ReadTelemetry | ConvertFrom-Json $appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value $apiKeyOutput.ApiKey $env:ArmOutputs = $appInsightsOutput From c8b920a9e4c241a261aa60b37b9756988f03e570 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 28 May 2024 07:50:47 +0200 Subject: [PATCH 28/86] pr-fix: use correct resource group --- build/deploy-test-resources.yml | 3 ++- build/templates/deploy-test-resources.bicep | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 6f71b0e3..b9973059 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -10,7 +10,7 @@ parameters: default: 'Azure Codit-Arcus Service Principal' - name: resourceGroupName displayName: 'Resource group name' - default: codit-arcus-observability-rg + default: arcus-observability-dev-we-rg - name: appInsightsName displayName: 'Application Insights name' default: arcus-observability-dev-we-app-insights @@ -43,6 +43,7 @@ stages: --location westeurope ` --template-file ./build/templates/deploy-test-resources.bicep ` --parameters location=westeurope ` + --parameters resourceGroupName=${{ parameters.resourceGroupName }} ` --parameters appInsightsName=${{ parameters.appInsightsName }} ` | ConvertFrom-Json diff --git a/build/templates/deploy-test-resources.bicep b/build/templates/deploy-test-resources.bicep index 935417ef..7ac9e392 100644 --- a/build/templates/deploy-test-resources.bicep +++ b/build/templates/deploy-test-resources.bicep @@ -1,13 +1,16 @@ // Define the location for the deployment of the components. param location string +// Define the name of the resource group where the components will be deployed. +param resourceGroupName string + // Define the name of the Application Insights component. param appInsightsName string targetScope='subscription' resource resourceGroup 'Microsoft.Resources/resourceGroups@2022-09-01' = { - name: 'arcus-observability-dev-we-rg' + name: resourceGroupName location: location } From 75ae2730d1ec2efc8f804cd94917e461fadc9e30 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 28 May 2024 07:55:54 +0200 Subject: [PATCH 29/86] pr-temp: write output --- build/deploy-test-resources.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index b9973059..a03bd3e1 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -47,7 +47,9 @@ stages: --parameters appInsightsName=${{ parameters.appInsightsName }} ` | ConvertFrom-Json - $apiKeyOutput = az monitor app-insights api-key create --api-key 'Arcus Observability Integration Tests API Key' --app ${{ parameters.appInsightsName }} --resource-group ${{ parameters.resourceGroupName }} --read-properties ReadTelemetry | ConvertFrom-Json + $json = az monitor app-insights api-key create --api-key 'Arcus Observability Integration Tests API Key' --app ${{ parameters.appInsightsName }} --resource-group ${{ parameters.resourceGroupName }} --read-properties ReadTelemetry + Write-Host $json + $apiKeyOutput = $json | ConvertFrom-Json $appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value $apiKeyOutput.ApiKey $env:ArmOutputs = $appInsightsOutput From bcfe2f4b12f0435c00c45caa96c50a7b0e7f530b Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 28 May 2024 08:27:29 +0200 Subject: [PATCH 30/86] pr-fix: use ps for api key --- build/deploy-test-resources.yml | 6 ++---- build/templates/deploy-test-resources.bicep | 1 + .../Arcus.Observability.Tests.Integration.csproj | 2 ++ 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index a03bd3e1..c0e43d96 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -36,8 +36,8 @@ stages: scriptLocation: 'inlineScript' inlineScript: | Set-PSRepository -Name PSGallery -InstallationPolicy Trusted + Install-Module -Name Az.ApplicationInsights -Force -AllowClobber Install-Module -Name Arcus.Scripting.DevOps -AllowClobber - az extension add --name application-insights $appInsightsOutput = az deployment sub create ` --location westeurope ` @@ -47,9 +47,7 @@ stages: --parameters appInsightsName=${{ parameters.appInsightsName }} ` | ConvertFrom-Json - $json = az monitor app-insights api-key create --api-key 'Arcus Observability Integration Tests API Key' --app ${{ parameters.appInsightsName }} --resource-group ${{ parameters.resourceGroupName }} --read-properties ReadTelemetry - Write-Host $json - $apiKeyOutput = $json | ConvertFrom-Json + $apiKeyOutput = New-AzApplicationInsightsApiKey -ResourceGroupName ${{ parameters.resourceGroupName }} -Name ${{ parameters.appInsightsName }} -ApiKeyDescription "Arcus Observability Integration tests API Key" -ReadTelemetry $appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value $apiKeyOutput.ApiKey $env:ArmOutputs = $appInsightsOutput diff --git a/build/templates/deploy-test-resources.bicep b/build/templates/deploy-test-resources.bicep index 7ac9e392..9ef1d408 100644 --- a/build/templates/deploy-test-resources.bicep +++ b/build/templates/deploy-test-resources.bicep @@ -33,5 +33,6 @@ module component 'br/public:avm/res/insights/component:0.3.0' = { } } +output ApplicationInsights_WorkspaceId string = workspace.outputs.resourceId output ApplicationInsights_ApplicationId string = component.outputs.applicationId output ApplicationInsights_ConnectionString string = component.outputs.connectionString diff --git a/src/Arcus.Observability.Tests.Integration/Arcus.Observability.Tests.Integration.csproj b/src/Arcus.Observability.Tests.Integration/Arcus.Observability.Tests.Integration.csproj index 94e8bc08..086183ed 100644 --- a/src/Arcus.Observability.Tests.Integration/Arcus.Observability.Tests.Integration.csproj +++ b/src/Arcus.Observability.Tests.Integration/Arcus.Observability.Tests.Integration.csproj @@ -11,6 +11,8 @@ + + From 8688e950c3689725ff7a1f0b885aa1edde8ae88f Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 28 May 2024 08:31:41 +0200 Subject: [PATCH 31/86] pr-fix: api key description --- build/deploy-test-resources.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index c0e43d96..0b0833a9 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -47,7 +47,7 @@ stages: --parameters appInsightsName=${{ parameters.appInsightsName }} ` | ConvertFrom-Json - $apiKeyOutput = New-AzApplicationInsightsApiKey -ResourceGroupName ${{ parameters.resourceGroupName }} -Name ${{ parameters.appInsightsName }} -ApiKeyDescription "Arcus Observability Integration tests API Key" -ReadTelemetry + $apiKeyOutput = New-AzApplicationInsightsApiKey -ResourceGroupName ${{ parameters.resourceGroupName }} -Name ${{ parameters.appInsightsName }} -Description "Arcus Observability Integration tests API Key" -ReadTelemetry $appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value $apiKeyOutput.ApiKey $env:ArmOutputs = $appInsightsOutput From 965626708583ebbe91ad1b1a329487d42f2a7f09 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 28 May 2024 08:35:51 +0200 Subject: [PATCH 32/86] pr-fix: api permissions --- build/deploy-test-resources.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 0b0833a9..5610bbb5 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -47,7 +47,7 @@ stages: --parameters appInsightsName=${{ parameters.appInsightsName }} ` | ConvertFrom-Json - $apiKeyOutput = New-AzApplicationInsightsApiKey -ResourceGroupName ${{ parameters.resourceGroupName }} -Name ${{ parameters.appInsightsName }} -Description "Arcus Observability Integration tests API Key" -ReadTelemetry + $apiKeyOutput = New-AzApplicationInsightsApiKey -ResourceGroupName ${{ parameters.resourceGroupName }} -Name ${{ parameters.appInsightsName }} -Description "Arcus Observability Integration tests API Key" -Permissions @("ReadTelemetry") $appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value $apiKeyOutput.ApiKey $env:ArmOutputs = $appInsightsOutput From dafac7afb5c5f8b87ed602acefbff152e5e25c29 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 28 May 2024 08:40:27 +0200 Subject: [PATCH 33/86] pr-fix: subscription ID --- build/deploy-test-resources.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 5610bbb5..495e4572 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -47,7 +47,8 @@ stages: --parameters appInsightsName=${{ parameters.appInsightsName }} ` | ConvertFrom-Json - $apiKeyOutput = New-AzApplicationInsightsApiKey -ResourceGroupName ${{ parameters.resourceGroupName }} -Name ${{ parameters.appInsightsName }} -Description "Arcus Observability Integration tests API Key" -Permissions @("ReadTelemetry") + $subscriptionId = $(az account show | ConvertFrom-Json).id + $apiKeyOutput = New-AzApplicationInsightsApiKey -SubscriptionId $subscriptionId -ResourceGroupName ${{ parameters.resourceGroupName }} -Name ${{ parameters.appInsightsName }} -Description "Arcus Observability Integration tests API Key" -Permissions @("ReadTelemetry") $appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value $apiKeyOutput.ApiKey $env:ArmOutputs = $appInsightsOutput From 77ff5311a7798c6a31e8aa0d506cf9f90d6f04ee Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 28 May 2024 08:47:27 +0200 Subject: [PATCH 34/86] pr-fix: subscription ID --- build/deploy-test-resources.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 495e4572..b8325dd1 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -36,8 +36,8 @@ stages: scriptLocation: 'inlineScript' inlineScript: | Set-PSRepository -Name PSGallery -InstallationPolicy Trusted - Install-Module -Name Az.ApplicationInsights -Force -AllowClobber Install-Module -Name Arcus.Scripting.DevOps -AllowClobber + az extension add --name application-insights $appInsightsOutput = az deployment sub create ` --location westeurope ` @@ -47,9 +47,9 @@ stages: --parameters appInsightsName=${{ parameters.appInsightsName }} ` | ConvertFrom-Json - $subscriptionId = $(az account show | ConvertFrom-Json).id - $apiKeyOutput = New-AzApplicationInsightsApiKey -SubscriptionId $subscriptionId -ResourceGroupName ${{ parameters.resourceGroupName }} -Name ${{ parameters.appInsightsName }} -Description "Arcus Observability Integration tests API Key" -Permissions @("ReadTelemetry") - $appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value $apiKeyOutput.ApiKey + az monitor app-insights api-key create --api-key 'Arcus Observability Integration Tests API Key' --app ${{ parameters.appInsightsName }} --resource-group ${{ parameters.resourceGroupName }} --read-properties ReadTelemetry + + #$appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value $apiKeyOutput.ApiKey $env:ArmOutputs = $appInsightsOutput Set-AzDevOpsArmOutputsToVariableGroup -VariableGroupName '${{ parameters.variableGroupName }}' \ No newline at end of file From 8d85b7f4f746323116bd5b589d6919e3e5d7d651 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 28 May 2024 08:52:59 +0200 Subject: [PATCH 35/86] pr-fix: correct json serialization --- build/deploy-test-resources.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index b8325dd1..588de287 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -47,9 +47,8 @@ stages: --parameters appInsightsName=${{ parameters.appInsightsName }} ` | ConvertFrom-Json - az monitor app-insights api-key create --api-key 'Arcus Observability Integration Tests API Key' --app ${{ parameters.appInsightsName }} --resource-group ${{ parameters.resourceGroupName }} --read-properties ReadTelemetry - - #$appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value $apiKeyOutput.ApiKey + $apiKeyOutput = az monitor app-insights api-key create --api-key 'Arcus Observability Integration Tests API Key' --app ${{ parameters.appInsightsName }} --resource-group ${{ parameters.resourceGroupName }} --read-properties ReadTelemetry + $appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value (ConvertFrom-Json $apiKeyOutput).ApiKey - $env:ArmOutputs = $appInsightsOutput + $env:ArmOutputs = ConvertTo-Json $appInsightsOutput Set-AzDevOpsArmOutputsToVariableGroup -VariableGroupName '${{ parameters.variableGroupName }}' \ No newline at end of file From 2ebd9ca21c412c557144a1d419fa31539a2b5138 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 28 May 2024 09:04:08 +0200 Subject: [PATCH 36/86] pr-fix: correct retrieving api key --- build/deploy-test-resources.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 588de287..49c864be 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -47,8 +47,8 @@ stages: --parameters appInsightsName=${{ parameters.appInsightsName }} ` | ConvertFrom-Json - $apiKeyOutput = az monitor app-insights api-key create --api-key 'Arcus Observability Integration Tests API Key' --app ${{ parameters.appInsightsName }} --resource-group ${{ parameters.resourceGroupName }} --read-properties ReadTelemetry - $appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value (ConvertFrom-Json $apiKeyOutput).ApiKey + $apiKeyOutput = az monitor app-insights api-key create --api-key 'Arcus Observability Integration Tests API Key' --app ${{ parameters.appInsightsName }} --resource-group ${{ parameters.resourceGroupName }} --read-properties ReadTelemetry | ConvertFrom-Json + $appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value $apiKeyOutput.apiKey $env:ArmOutputs = ConvertTo-Json $appInsightsOutput Set-AzDevOpsArmOutputsToVariableGroup -VariableGroupName '${{ parameters.variableGroupName }}' \ No newline at end of file From 1cc8d195360effd0a55e60f38c92be286f0d6e1a Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 28 May 2024 09:13:36 +0200 Subject: [PATCH 37/86] pr-fix: delete api key if present --- build/deploy-test-resources.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 49c864be..7b03a35b 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -47,7 +47,19 @@ stages: --parameters appInsightsName=${{ parameters.appInsightsName }} ` | ConvertFrom-Json - $apiKeyOutput = az monitor app-insights api-key create --api-key 'Arcus Observability Integration Tests API Key' --app ${{ parameters.appInsightsName }} --resource-group ${{ parameters.resourceGroupName }} --read-properties ReadTelemetry | ConvertFrom-Json + $apiKeyName = 'Arcus Observability Integration Tests API Key' + az monitor app-insights api-key delete ` + --api-key $apiKeyName ` + --app ${{ parameters.appInsightsName }} ` + --resource-group ${{ parameters.resourceGroupName }} ` + --yes -ErrorAction SilentlyContinue + + $apiKeyOutput = az monitor app-insights api-key create ` + --api-key $apiKeyName ` + --app ${{ parameters.appInsightsName }} ` + --resource-group ${{ parameters.resourceGroupName }} ` + --read-properties ReadTelemetry ` + | ConvertFrom-Json $appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value $apiKeyOutput.apiKey $env:ArmOutputs = ConvertTo-Json $appInsightsOutput From bc2828b874af1219a66cf802a41667cd3fe65f02 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 28 May 2024 09:17:37 +0200 Subject: [PATCH 38/86] pr-fix: show app insights output --- build/deploy-test-resources.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 7b03a35b..c4422a53 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -61,6 +61,7 @@ stages: --read-properties ReadTelemetry ` | ConvertFrom-Json $appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value $apiKeyOutput.apiKey + Write-Host $appInsightsOutput $env:ArmOutputs = ConvertTo-Json $appInsightsOutput Set-AzDevOpsArmOutputsToVariableGroup -VariableGroupName '${{ parameters.variableGroupName }}' \ No newline at end of file From 303959e83202ee5772c56f1817281c48c234ebcd Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 28 May 2024 09:25:39 +0200 Subject: [PATCH 39/86] pr-fix: upsert api key --- build/deploy-test-resources.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index c4422a53..fd52fb83 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -48,12 +48,15 @@ stages: | ConvertFrom-Json $apiKeyName = 'Arcus Observability Integration Tests API Key' - az monitor app-insights api-key delete ` + + if (az monitor app-insights api-key show --app ${{ parameters.appInsightsName }} --resource-group ${{ parameters.resourceGroupName }} --api-key $apiKeyName) { + az monitor app-insights api-key delete ` --api-key $apiKeyName ` --app ${{ parameters.appInsightsName }} ` --resource-group ${{ parameters.resourceGroupName }} ` - --yes -ErrorAction SilentlyContinue - + --yes + } + $apiKeyOutput = az monitor app-insights api-key create ` --api-key $apiKeyName ` --app ${{ parameters.appInsightsName }} ` From f1bb28d2e17477d02a1030120023b299c5910636 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 28 May 2024 09:30:41 +0200 Subject: [PATCH 40/86] pr-fix: only expose properties --- build/deploy-test-resources.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index fd52fb83..c23e7f56 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -49,14 +49,17 @@ stages: $apiKeyName = 'Arcus Observability Integration Tests API Key' - if (az monitor app-insights api-key show --app ${{ parameters.appInsightsName }} --resource-group ${{ parameters.resourceGroupName }} --api-key $apiKeyName) { + if (az monitor app-insights api-key show ` + --app ${{ parameters.appInsightsName }} ` + --resource-group ${{ parameters.resourceGroupName }} ` + --api-key $apiKeyName) { az monitor app-insights api-key delete ` --api-key $apiKeyName ` --app ${{ parameters.appInsightsName }} ` --resource-group ${{ parameters.resourceGroupName }} ` --yes } - + $apiKeyOutput = az monitor app-insights api-key create ` --api-key $apiKeyName ` --app ${{ parameters.appInsightsName }} ` @@ -64,7 +67,6 @@ stages: --read-properties ReadTelemetry ` | ConvertFrom-Json $appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value $apiKeyOutput.apiKey - Write-Host $appInsightsOutput - $env:ArmOutputs = ConvertTo-Json $appInsightsOutput + $env:ArmOutputs = ConvertTo-Json $appInsightsOutput.properties.outputs Set-AzDevOpsArmOutputsToVariableGroup -VariableGroupName '${{ parameters.variableGroupName }}' \ No newline at end of file From 93c977662394b2eb43ffe9d2cd69c4d333608115 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 28 May 2024 09:36:43 +0200 Subject: [PATCH 41/86] pr-fix: add system access token --- build/deploy-test-resources.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index c23e7f56..2e33b74b 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -30,6 +30,8 @@ stages: vmImage: '$(Vm.Image)' steps: - task: AzureCLI@2 + env: + SYSTEM_ACCESSTOKEN: $(System.AccessToken) inputs: azureSubscription: '${{ parameters.azureServiceConnection }}' scriptType: 'pscore' @@ -48,7 +50,6 @@ stages: | ConvertFrom-Json $apiKeyName = 'Arcus Observability Integration Tests API Key' - if (az monitor app-insights api-key show ` --app ${{ parameters.appInsightsName }} ` --resource-group ${{ parameters.resourceGroupName }} ` From 7d9a44933604fec3edb2127b2aa5e3a9b398dd10 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 28 May 2024 09:59:11 +0200 Subject: [PATCH 42/86] pr-fix: save secrets in vault --- build/deploy-test-resources.yml | 11 +++++++++-- build/templates/deploy-test-resources.bicep | 19 ++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 2e33b74b..6ace6161 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -19,6 +19,8 @@ parameters: default: Arcus Observability - Integration Testing variables: + - name: keyVaultName + value: 'arcus-observability-dev-we-kv' - template: ./variables/build.yml stages: @@ -46,7 +48,8 @@ stages: --template-file ./build/templates/deploy-test-resources.bicep ` --parameters location=westeurope ` --parameters resourceGroupName=${{ parameters.resourceGroupName }} ` - --parameters appInsightsName=${{ parameters.appInsightsName }} ` + --parameters appInsightsName=${{ parameters.appInsightsName }} + --parameters keyVaultName=${{ variables.keyVaultName }}` | ConvertFrom-Json $apiKeyName = 'Arcus Observability Integration Tests API Key' @@ -67,7 +70,11 @@ stages: --resource-group ${{ parameters.resourceGroupName }} ` --read-properties ReadTelemetry ` | ConvertFrom-Json - $appInsightsOutput.properties.outputs | Add-Member -Type NoteProperty -Name 'ApplicationInsights_ApiKey' -Value $apiKeyOutput.apiKey + + az keyvault secret set ` + --vault-name ${{ variables.keyVaultName }} ` + --name 'ApplicationInsights_ApiKey' ` + --value $apiKeyOutput.apiKey ` $env:ArmOutputs = ConvertTo-Json $appInsightsOutput.properties.outputs Set-AzDevOpsArmOutputsToVariableGroup -VariableGroupName '${{ parameters.variableGroupName }}' \ No newline at end of file diff --git a/build/templates/deploy-test-resources.bicep b/build/templates/deploy-test-resources.bicep index 9ef1d408..dce698bb 100644 --- a/build/templates/deploy-test-resources.bicep +++ b/build/templates/deploy-test-resources.bicep @@ -7,6 +7,9 @@ param resourceGroupName string // Define the name of the Application Insights component. param appInsightsName string +// Define the name of the Key Vault. +param keyVaultName string + targetScope='subscription' resource resourceGroup 'Microsoft.Resources/resourceGroups@2022-09-01' = { @@ -33,6 +36,20 @@ module component 'br/public:avm/res/insights/component:0.3.0' = { } } +module vault 'br/public:avm/res/key-vault/vault:0.6.1' = { + name: 'vaultDeployment' + scope: resourceGroup + params: { + name: keyVaultName + location: location + secrets: [ + { + name: 'ApplicationInsights_ConnectionString' + value: component.outputs.connectionString + } + ] + } +} + output ApplicationInsights_WorkspaceId string = workspace.outputs.resourceId output ApplicationInsights_ApplicationId string = component.outputs.applicationId -output ApplicationInsights_ConnectionString string = component.outputs.connectionString From 72a905f8a12e5107594fe580c40ae4456d1784e6 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 28 May 2024 10:02:41 +0200 Subject: [PATCH 43/86] pr-fix: correct back tick --- build/deploy-test-resources.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 6ace6161..baad8a16 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -48,8 +48,8 @@ stages: --template-file ./build/templates/deploy-test-resources.bicep ` --parameters location=westeurope ` --parameters resourceGroupName=${{ parameters.resourceGroupName }} ` - --parameters appInsightsName=${{ parameters.appInsightsName }} - --parameters keyVaultName=${{ variables.keyVaultName }}` + --parameters appInsightsName=${{ parameters.appInsightsName }} ` + --parameters keyVaultName=${{ variables.keyVaultName }} ` | ConvertFrom-Json $apiKeyName = 'Arcus Observability Integration Tests API Key' From 9a1c359e17edda454a27661c3edeeba45df77957 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 28 May 2024 10:07:01 +0200 Subject: [PATCH 44/86] pr-fix: correct back tick --- build/deploy-test-resources.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index baad8a16..45ed4d4c 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -20,7 +20,7 @@ parameters: variables: - name: keyVaultName - value: 'arcus-observability-dev-we-kv' + value: 'arcus-observability-kv' - template: ./variables/build.yml stages: From 33944ebeaebb9c60fc15ffe1e38eac3a834e4180 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 28 May 2024 10:17:08 +0200 Subject: [PATCH 45/86] pr-fix: correct secret name --- build/deploy-test-resources.yml | 2 +- build/templates/deploy-test-resources.bicep | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 45ed4d4c..cabec37f 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -73,7 +73,7 @@ stages: az keyvault secret set ` --vault-name ${{ variables.keyVaultName }} ` - --name 'ApplicationInsights_ApiKey' ` + --name 'ApplicationInsights-ApiKey' ` --value $apiKeyOutput.apiKey ` $env:ArmOutputs = ConvertTo-Json $appInsightsOutput.properties.outputs diff --git a/build/templates/deploy-test-resources.bicep b/build/templates/deploy-test-resources.bicep index dce698bb..bd227048 100644 --- a/build/templates/deploy-test-resources.bicep +++ b/build/templates/deploy-test-resources.bicep @@ -53,3 +53,4 @@ module vault 'br/public:avm/res/key-vault/vault:0.6.1' = { output ApplicationInsights_WorkspaceId string = workspace.outputs.resourceId output ApplicationInsights_ApplicationId string = component.outputs.applicationId +output KeyVault_Uri string = vault.outputs.uri From ec486bb4b725387e96c06214f908dce472087d89 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 30 May 2024 06:08:19 +0200 Subject: [PATCH 46/86] pr-fix: add role assignments to key vault for the service principal --- build/deploy-test-resources.yml | 1 + build/templates/deploy-test-resources.bicep | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index cabec37f..09196b2b 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -36,6 +36,7 @@ stages: SYSTEM_ACCESSTOKEN: $(System.AccessToken) inputs: azureSubscription: '${{ parameters.azureServiceConnection }}' + addSpnToEnvironment: true scriptType: 'pscore' scriptLocation: 'inlineScript' inlineScript: | diff --git a/build/templates/deploy-test-resources.bicep b/build/templates/deploy-test-resources.bicep index bd227048..2f49f85e 100644 --- a/build/templates/deploy-test-resources.bicep +++ b/build/templates/deploy-test-resources.bicep @@ -10,6 +10,9 @@ param appInsightsName string // Define the name of the Key Vault. param keyVaultName string +// Define the Service Principal ID that needs access to the Key Vault. +param servicePrincipalId string + targetScope='subscription' resource resourceGroup 'Microsoft.Resources/resourceGroups@2022-09-01' = { @@ -42,6 +45,12 @@ module vault 'br/public:avm/res/key-vault/vault:0.6.1' = { params: { name: keyVaultName location: location + roleAssignments: [ + { + principalId: servicePrincipalId + roleDefinitionIdOrName: 'Key Vault Secrets Contributor' + } + ] secrets: [ { name: 'ApplicationInsights_ConnectionString' From 94c65318f3cb66adbd6bb537aa9008c8683bc1c2 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 30 May 2024 06:09:38 +0200 Subject: [PATCH 47/86] pr-fix: add service principal ID to bicep parameters --- build/deploy-test-resources.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 09196b2b..7d2a31d3 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -51,6 +51,7 @@ stages: --parameters resourceGroupName=${{ parameters.resourceGroupName }} ` --parameters appInsightsName=${{ parameters.appInsightsName }} ` --parameters keyVaultName=${{ variables.keyVaultName }} ` + --parameters servicePrincipalId=$env:servicePrincipalId ` | ConvertFrom-Json $apiKeyName = 'Arcus Observability Integration Tests API Key' From 4a5cff79edb9804f00aad2c20b10af0f5ad62866 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 30 May 2024 06:23:54 +0200 Subject: [PATCH 48/86] pr-fix: add owner role assignment for service principal to rg --- build/templates/deploy-test-resources.bicep | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/build/templates/deploy-test-resources.bicep b/build/templates/deploy-test-resources.bicep index 2f49f85e..2d41f217 100644 --- a/build/templates/deploy-test-resources.bicep +++ b/build/templates/deploy-test-resources.bicep @@ -10,14 +10,22 @@ param appInsightsName string // Define the name of the Key Vault. param keyVaultName string -// Define the Service Principal ID that needs access to the Key Vault. +// Define the Service Principal ID that needs access full access to the deployed resource group. param servicePrincipalId string targetScope='subscription' -resource resourceGroup 'Microsoft.Resources/resourceGroups@2022-09-01' = { +resource resourceGroup 'br/public:avm/res/resources/resource-group:0.2.3' = { name: resourceGroupName - location: location + params: { + location: location + roleAssignments: [ + { + principalId: servicePrincipalId + roleDefinitionIdOrName: 'Owner' + } + ] + } } module workspace 'br/public:avm/res/operational-insights/workspace:0.3.4' = { From 6f08dbe29d04e6ee6d3831200db83b7b39603ff3 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 30 May 2024 06:33:34 +0200 Subject: [PATCH 49/86] pr-fix: resource group deployment --- build/templates/deploy-test-resources.bicep | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/build/templates/deploy-test-resources.bicep b/build/templates/deploy-test-resources.bicep index 2d41f217..8562be0f 100644 --- a/build/templates/deploy-test-resources.bicep +++ b/build/templates/deploy-test-resources.bicep @@ -15,9 +15,10 @@ param servicePrincipalId string targetScope='subscription' -resource resourceGroup 'br/public:avm/res/resources/resource-group:0.2.3' = { - name: resourceGroupName +module resourceGroup 'br/public:avm/res/resources/resource-group:0.2.3' = { + name: 'resourceGroupDeployment' params: { + name: resourceGroupName location: location roleAssignments: [ { @@ -28,9 +29,13 @@ resource resourceGroup 'br/public:avm/res/resources/resource-group:0.2.3' = { } } +resource rg 'Microsoft.Resources/resourceGroups@2021-04-01' existing = { + name: resourceGroupName +} + module workspace 'br/public:avm/res/operational-insights/workspace:0.3.4' = { name: 'workspaceDeployment' - scope: resourceGroup + scope: rg params: { name: 'arcus-observability-dev-we-workspace' location: location @@ -39,7 +44,7 @@ module workspace 'br/public:avm/res/operational-insights/workspace:0.3.4' = { module component 'br/public:avm/res/insights/component:0.3.0' = { name: 'componentDeployment' - scope: resourceGroup + scope: rg params: { name: appInsightsName workspaceResourceId: workspace.outputs.resourceId @@ -49,7 +54,7 @@ module component 'br/public:avm/res/insights/component:0.3.0' = { module vault 'br/public:avm/res/key-vault/vault:0.6.1' = { name: 'vaultDeployment' - scope: resourceGroup + scope: rg params: { name: keyVaultName location: location From ae207c4e2e8da6133c5eb11c475393938aa4b8d6 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 30 May 2024 06:45:20 +0200 Subject: [PATCH 50/86] pr-fix: use correct key vault role name --- build/templates/deploy-test-resources.bicep | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/build/templates/deploy-test-resources.bicep b/build/templates/deploy-test-resources.bicep index 8562be0f..665b28b3 100644 --- a/build/templates/deploy-test-resources.bicep +++ b/build/templates/deploy-test-resources.bicep @@ -20,12 +20,6 @@ module resourceGroup 'br/public:avm/res/resources/resource-group:0.2.3' = { params: { name: resourceGroupName location: location - roleAssignments: [ - { - principalId: servicePrincipalId - roleDefinitionIdOrName: 'Owner' - } - ] } } @@ -61,7 +55,7 @@ module vault 'br/public:avm/res/key-vault/vault:0.6.1' = { roleAssignments: [ { principalId: servicePrincipalId - roleDefinitionIdOrName: 'Key Vault Secrets Contributor' + roleDefinitionIdOrName: 'Key Vault Secrets officer' } ] secrets: [ From 701c895506cac17eb5d127ce1031839776eca0fa Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 30 May 2024 07:11:08 +0200 Subject: [PATCH 51/86] pr-fix: use object id instead --- build/deploy-test-resources.yml | 1 + build/templates/deploy-test-resources.bicep | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 7d2a31d3..946ed1ce 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -44,6 +44,7 @@ stages: Install-Module -Name Arcus.Scripting.DevOps -AllowClobber az extension add --name application-insights + $objectId = az ad sp show --id $env:servicePrincipalId --query objectId --output tsv $appInsightsOutput = az deployment sub create ` --location westeurope ` --template-file ./build/templates/deploy-test-resources.bicep ` diff --git a/build/templates/deploy-test-resources.bicep b/build/templates/deploy-test-resources.bicep index 665b28b3..f25e9b5a 100644 --- a/build/templates/deploy-test-resources.bicep +++ b/build/templates/deploy-test-resources.bicep @@ -11,7 +11,7 @@ param appInsightsName string param keyVaultName string // Define the Service Principal ID that needs access full access to the deployed resource group. -param servicePrincipalId string +param servicePrincipal_objectId string targetScope='subscription' @@ -54,7 +54,7 @@ module vault 'br/public:avm/res/key-vault/vault:0.6.1' = { location: location roleAssignments: [ { - principalId: servicePrincipalId + principalId: servicePrincipal_objectId roleDefinitionIdOrName: 'Key Vault Secrets officer' } ] From 2e56d1608f96031daa9322f49b2b5a51501ebe0b Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 30 May 2024 07:13:07 +0200 Subject: [PATCH 52/86] pr-fix: use object id instead --- build/deploy-test-resources.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 946ed1ce..838551c4 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -52,7 +52,7 @@ stages: --parameters resourceGroupName=${{ parameters.resourceGroupName }} ` --parameters appInsightsName=${{ parameters.appInsightsName }} ` --parameters keyVaultName=${{ variables.keyVaultName }} ` - --parameters servicePrincipalId=$env:servicePrincipalId ` + --parameters servicePrincipal_objectId=$objectId ` | ConvertFrom-Json $apiKeyName = 'Arcus Observability Integration Tests API Key' From 24e7db49dea051260ad509a6cf4a5f3eb75f51ee Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 30 May 2024 07:23:16 +0200 Subject: [PATCH 53/86] pr-fix: use correct object id --- build/deploy-test-resources.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 838551c4..f22f6b3b 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -44,7 +44,7 @@ stages: Install-Module -Name Arcus.Scripting.DevOps -AllowClobber az extension add --name application-insights - $objectId = az ad sp show --id $env:servicePrincipalId --query objectId --output tsv + $objectId = (az ad sp show --id $env:servicePrincipalId | ConvertFrom-Json).id $appInsightsOutput = az deployment sub create ` --location westeurope ` --template-file ./build/templates/deploy-test-resources.bicep ` From 67a6bbacf34c28109105f0855cc760186aa1f59d Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 30 May 2024 07:28:27 +0200 Subject: [PATCH 54/86] pr-fix: correct secret name --- build/templates/deploy-test-resources.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/templates/deploy-test-resources.bicep b/build/templates/deploy-test-resources.bicep index f25e9b5a..8c93266b 100644 --- a/build/templates/deploy-test-resources.bicep +++ b/build/templates/deploy-test-resources.bicep @@ -60,7 +60,7 @@ module vault 'br/public:avm/res/key-vault/vault:0.6.1' = { ] secrets: [ { - name: 'ApplicationInsights_ConnectionString' + name: 'ApplicationInsights-ConnectionString' value: component.outputs.connectionString } ] From 29afde8f45989dc803fd66611755c67769fd0bd4 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 30 May 2024 07:36:30 +0200 Subject: [PATCH 55/86] pr-fix: update ci pipeline to use new resources --- build/ci-build.yml | 14 ++++++++++++++ build/templates/deploy-test-resources.bicep | 4 ++-- .../appsettings.json | 6 +++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/build/ci-build.yml b/build/ci-build.yml index ac0c22b5..2297ba9b 100644 --- a/build/ci-build.yml +++ b/build/ci-build.yml @@ -18,6 +18,14 @@ parameters: - name: 'Package.Version.ManualTrigger' type: string default: 'preview' + - name: azureServiceConnection + displayName: 'Azure service connection' + type: string + default: 'Azure Codit-Arcus Service Principal' + - name: keyVaultName + displayName: 'Azure Key vault with integration test secrets' + type: string + default: 'arcus-observability-kv' resources: repositories: @@ -116,6 +124,12 @@ stages: inputs: packageType: 'sdk' version: '$(DotNet.Sdk.PreviousVersion)' + - task: AzureKeyVault@2 + displayName: 'Import secrets from Azure Key Vault' + inputs: + azureSubscription: '${{ parameters.azureServiceConnection }}' + KeyVaultName: '${{ parameters.keyVaultName }}' + SecretsFilter: '*' - template: test/run-integration-tests.yml@templates parameters: dotnetSdkVersion: '$(DotNet.Sdk.Version)' diff --git a/build/templates/deploy-test-resources.bicep b/build/templates/deploy-test-resources.bicep index 8c93266b..90541b1c 100644 --- a/build/templates/deploy-test-resources.bicep +++ b/build/templates/deploy-test-resources.bicep @@ -60,8 +60,8 @@ module vault 'br/public:avm/res/key-vault/vault:0.6.1' = { ] secrets: [ { - name: 'ApplicationInsights-ConnectionString' - value: component.outputs.connectionString + name: 'ApplicationInsights-InstrumentationKey' + value: component.outputs.instrumentationKey } ] } diff --git a/src/Arcus.Observability.Tests.Integration/appsettings.json b/src/Arcus.Observability.Tests.Integration/appsettings.json index ce6ee5c4..9713ebcd 100644 --- a/src/Arcus.Observability.Tests.Integration/appsettings.json +++ b/src/Arcus.Observability.Tests.Integration/appsettings.json @@ -1,8 +1,8 @@ { "ApplicationInsights": { - "InstrumentationKey": "#{ApplicationInsights.InstrumentationKey}#", - "ApiKey": "#{ApplicationInsights.ApiKey}#", - "ApplicationId": "#{ApplicationInsights.ApplicationId}#" + "InstrumentationKey": "#{ApplicationInsights_InstrumentationKey}#", + "ApiKey": "#{ApplicationInsights_ApiKey}#", + "ApplicationId": "#{ApplicationInsights_ApplicationId}#" }, "AzureFunctions": { "HttpPort": "#{AzureFunctions.HttpPort}#" From 32f4a2c918c500574db7c625929510deb6fe1572 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 30 May 2024 07:47:45 +0200 Subject: [PATCH 56/86] pr-fix: remove unused additions --- build/templates/deploy-test-resources.bicep | 1 - .../Arcus.Observability.Tests.Integration.csproj | 2 -- 2 files changed, 3 deletions(-) diff --git a/build/templates/deploy-test-resources.bicep b/build/templates/deploy-test-resources.bicep index 90541b1c..33c9f392 100644 --- a/build/templates/deploy-test-resources.bicep +++ b/build/templates/deploy-test-resources.bicep @@ -69,4 +69,3 @@ module vault 'br/public:avm/res/key-vault/vault:0.6.1' = { output ApplicationInsights_WorkspaceId string = workspace.outputs.resourceId output ApplicationInsights_ApplicationId string = component.outputs.applicationId -output KeyVault_Uri string = vault.outputs.uri diff --git a/src/Arcus.Observability.Tests.Integration/Arcus.Observability.Tests.Integration.csproj b/src/Arcus.Observability.Tests.Integration/Arcus.Observability.Tests.Integration.csproj index 086183ed..94e8bc08 100644 --- a/src/Arcus.Observability.Tests.Integration/Arcus.Observability.Tests.Integration.csproj +++ b/src/Arcus.Observability.Tests.Integration/Arcus.Observability.Tests.Integration.csproj @@ -11,8 +11,6 @@ - - From 8864a3a9f79e2bf490f8a20c4803fe53c427af5d Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 30 May 2024 07:55:12 +0200 Subject: [PATCH 57/86] pr-fix: add updated integration test run to release pipeline --- build/ci-build.yml | 24 +++-------------- build/nuget-release.yml | 26 ++++++++----------- .../run-docker-integration-tests.yml | 5 ++++ .../run-self-contained-integration-tests.yml | 22 ++++++++++++++++ 4 files changed, 41 insertions(+), 36 deletions(-) create mode 100644 build/templates/run-self-contained-integration-tests.yml diff --git a/build/ci-build.yml b/build/ci-build.yml index 2297ba9b..520ea89c 100644 --- a/build/ci-build.yml +++ b/build/ci-build.yml @@ -119,23 +119,10 @@ stages: inputs: artifact: 'Build' path: '$(Build.SourcesDirectory)' - - task: UseDotNet@2 - displayName: 'Import .NET Core SDK ($(DotNet.Sdk.PreviousVersion))' - inputs: - packageType: 'sdk' - version: '$(DotNet.Sdk.PreviousVersion)' - - task: AzureKeyVault@2 - displayName: 'Import secrets from Azure Key Vault' - inputs: - azureSubscription: '${{ parameters.azureServiceConnection }}' - KeyVaultName: '${{ parameters.keyVaultName }}' - SecretsFilter: '*' - - template: test/run-integration-tests.yml@templates + - template: test/run-self-contained-integration-tests.yml parameters: - dotnetSdkVersion: '$(DotNet.Sdk.Version)' - includePreviewVersions: $(DotNet.Sdk.IncludePreviewVersions) - projectName: '$(Project).Tests.Integration' - category: 'Integration' + azureServiceConnection: '${{ parameters.azureServiceConnection }}' + keyVaultName: '${{ parameters.keyVaultName }}' - stage: DockerTests displayName: Docker Tests @@ -152,11 +139,6 @@ stages: inputs: artifact: 'Build' path: '$(Build.SourcesDirectory)' - - task: UseDotNet@2 - displayName: 'Import .NET Core SDK ($(DotNet.Sdk.PreviousVersion))' - inputs: - packageType: 'sdk' - version: '$(DotNet.Sdk.PreviousVersion)' - template: templates/run-docker-integration-tests.yml parameters: dockerProjectName: '$(Project).Tests.Runtimes.AzureFunction' diff --git a/build/nuget-release.yml b/build/nuget-release.yml index d81119d3..63a9914c 100644 --- a/build/nuget-release.yml +++ b/build/nuget-release.yml @@ -6,6 +6,14 @@ pr: none parameters: - name: 'Package.Version' type: 'string' + - name: azureServiceConnection + displayName: 'Azure service connection' + type: string + default: 'Azure Codit-Arcus Service Principal' + - name: keyVaultName + displayName: 'Azure Key vault with integration test secrets' + type: string + default: 'arcus-observability-kv' resources: repositories: @@ -93,17 +101,10 @@ stages: inputs: artifact: 'Build' path: '$(Build.SourcesDirectory)' - - task: UseDotNet@2 - displayName: 'Import .NET Core SDK ($(DotNet.Sdk.PreviousVersion))' - inputs: - packageType: 'sdk' - version: '$(DotNet.Sdk.PreviousVersion)' - - template: test/run-integration-tests.yml@templates + - template: test/run-self-contained-integration-tests.yml parameters: - dotnetSdkVersion: '$(DotNet.Sdk.Version)' - includePreviewVersions: $(DotNet.Sdk.IncludePreviewVersions) - projectName: '$(Project).Tests.Integration' - category: 'Integration' + azureServiceConnection: '${{ parameters.azureServiceConnection }}' + keyVaultName: '${{ parameters.keyVaultName }}' - stage: DockerTests displayName: Docker Tests @@ -120,11 +121,6 @@ stages: inputs: artifact: 'Build' path: '$(Build.SourcesDirectory)' - - task: UseDotNet@2 - displayName: 'Import .NET Core SDK ($(DotNet.Sdk.PreviousVersion))' - inputs: - packageType: 'sdk' - version: '$(DotNet.Sdk.PreviousVersion)' - template: templates/run-docker-integration-tests.yml parameters: dockerProjectName: '$(Project).Tests.Runtimes.AzureFunction' diff --git a/build/templates/run-docker-integration-tests.yml b/build/templates/run-docker-integration-tests.yml index 97e817ad..e5c4aea1 100644 --- a/build/templates/run-docker-integration-tests.yml +++ b/build/templates/run-docker-integration-tests.yml @@ -15,6 +15,11 @@ steps: env: PROJECT_NAME: ${{ parameters.dockerProjectName }} HTTP_PORT: ${{ parameters.httpPort }} + - task: UseDotNet@2 + displayName: 'Import .NET Core SDK ($(DotNet.Sdk.PreviousVersion))' + inputs: + packageType: 'sdk' + version: '$(DotNet.Sdk.PreviousVersion)' - task: UseDotNet@2 displayName: 'Import .NET Core SDK ($(DotNet.Sdk.Version))' inputs: diff --git a/build/templates/run-self-contained-integration-tests.yml b/build/templates/run-self-contained-integration-tests.yml new file mode 100644 index 00000000..456ca1b2 --- /dev/null +++ b/build/templates/run-self-contained-integration-tests.yml @@ -0,0 +1,22 @@ +parameters: + azureServiceConnection: '' + keyVaultName: '' + +steps: + - task: UseDotNet@2 + displayName: 'Import .NET Core SDK ($(DotNet.Sdk.PreviousVersion))' + inputs: + packageType: 'sdk' + version: '$(DotNet.Sdk.PreviousVersion)' + - task: AzureKeyVault@2 + displayName: 'Import secrets from Azure Key Vault' + inputs: + azureSubscription: '${{ parameters.azureServiceConnection }}' + KeyVaultName: '${{ parameters.keyVaultName }}' + SecretsFilter: '*' + - template: test/run-integration-tests.yml@templates + parameters: + dotnetSdkVersion: '$(DotNet.Sdk.Version)' + includePreviewVersions: $(DotNet.Sdk.IncludePreviewVersions) + projectName: '$(Project).Tests.Integration' + category: 'Integration' \ No newline at end of file From a205f92ea5a19dd1fc01b6f8287e72c30f7711ae Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 30 May 2024 07:56:10 +0200 Subject: [PATCH 58/86] pr-fix: correct template path --- build/ci-build.yml | 2 +- build/nuget-release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build/ci-build.yml b/build/ci-build.yml index 520ea89c..7bb8cff8 100644 --- a/build/ci-build.yml +++ b/build/ci-build.yml @@ -119,7 +119,7 @@ stages: inputs: artifact: 'Build' path: '$(Build.SourcesDirectory)' - - template: test/run-self-contained-integration-tests.yml + - template: templates/run-self-contained-integration-tests.yml parameters: azureServiceConnection: '${{ parameters.azureServiceConnection }}' keyVaultName: '${{ parameters.keyVaultName }}' diff --git a/build/nuget-release.yml b/build/nuget-release.yml index 63a9914c..275e52ad 100644 --- a/build/nuget-release.yml +++ b/build/nuget-release.yml @@ -101,7 +101,7 @@ stages: inputs: artifact: 'Build' path: '$(Build.SourcesDirectory)' - - template: test/run-self-contained-integration-tests.yml + - template: templates/run-self-contained-integration-tests.yml parameters: azureServiceConnection: '${{ parameters.azureServiceConnection }}' keyVaultName: '${{ parameters.keyVaultName }}' From af6dedf23f606bb2aeacc0205baf02a3d7d3b8d6 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 30 Jul 2024 18:31:18 +0200 Subject: [PATCH 59/86] chore: use new monitor package w/ dev tenant resources --- build/ci-build.yml | 62 +----- build/deploy-test-resources.yml | 50 +---- build/nuget-release.yml | 62 +----- build/templates/deploy-test-resources.bicep | 33 ++- build/templates/import-keyvault-secrets.yml | 23 ++ .../run-docker-integration-tests.yml | 133 +++++++----- .../run-self-contained-integration-tests.yml | 47 ++-- build/templates/run-unit-tests.yml | 23 ++ build/variables/test.yml | 5 +- ...cus.Observability.Tests.Integration.csproj | 7 +- .../AssertX.cs | 4 +- .../Configuration/ServicePrincipal.cs | 57 +++++ .../IntegrationTest.cs | 12 +- .../ApplicationInsights/AppInsightsClient.cs | 189 ++++++++++++++++ .../ApplicationInsightsClient.cs | 120 ----------- .../ApplicationInsightsSinkExtensionTests.cs | 69 +++--- .../ApplicationInsightsSinkTests.cs | 130 +++++------ .../AzureFunctionsDockerTests.cs | 15 +- .../AzureKeyVaultDependencyTests.cs | 14 +- .../AzureSearchDependencyTests.cs | 14 +- .../BlobStorageDependencyTests.cs | 16 +- .../CosmosSqlDependencyTests.cs | 15 +- .../CustomDependencyTests.cs | 24 ++- .../ApplicationInsights/CustomRequestTests.cs | 15 +- .../EventHubsDependencyTests.cs | 17 +- .../EventHubsRequestTests.cs | 19 +- .../Sinks/ApplicationInsights/EventTests.cs | 62 +++--- .../ApplicationInsights/ExceptionTests.cs | 41 ++-- .../Fixture/ITelemetryQueryClient.cs | 202 ++++++++++++++++++ ...ryApplicationInsightsTelemetryConverter.cs | 40 ++++ .../Fixture/InMemoryTelemetryQueryClient.cs | 118 ++++++++++ .../HttpDependencyTests.cs | 36 ++-- .../HttpRequestDataTests.cs | 10 +- .../Sinks/ApplicationInsights/IoTHubTests.cs | 26 +-- .../Sinks/ApplicationInsights/MetricTests.cs | 46 ++-- .../Sinks/ApplicationInsights/RequestTests.cs | 48 +++-- .../ServiceBusDependencyTests.cs | 24 +-- .../ServiceBusRequestTests.cs | 65 +++--- .../ApplicationInsights/SqlDependencyTests.cs | 26 +-- .../TableStorageDependencyTests.cs | 16 +- .../Sinks/ApplicationInsights/TraceTests.cs | 19 +- .../appsettings.json | 18 +- .../Arcus.Observability.Tests.Unit.csproj | 2 +- 43 files changed, 1214 insertions(+), 760 deletions(-) create mode 100644 build/templates/import-keyvault-secrets.yml create mode 100644 build/templates/run-unit-tests.yml create mode 100644 src/Arcus.Observability.Tests.Integration/Configuration/ServicePrincipal.cs create mode 100644 src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AppInsightsClient.cs delete mode 100644 src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsClient.cs create mode 100644 src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/ITelemetryQueryClient.cs create mode 100644 src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/InMemoryApplicationInsightsTelemetryConverter.cs create mode 100644 src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/InMemoryTelemetryQueryClient.cs diff --git a/build/ci-build.yml b/build/ci-build.yml index 7bb8cff8..234a03ee 100644 --- a/build/ci-build.yml +++ b/build/ci-build.yml @@ -22,10 +22,6 @@ parameters: displayName: 'Azure service connection' type: string default: 'Azure Codit-Arcus Service Principal' - - name: keyVaultName - displayName: 'Azure Key vault with integration test secrets' - type: string - default: 'arcus-observability-kv' resources: repositories: @@ -35,7 +31,6 @@ resources: endpoint: arcus-azure variables: - - group: 'Arcus Observability - Integration Testing' - group: 'Arcus - GitHub Package Registry' - group: 'Build Configuration' - template: ./variables/build.yml @@ -83,66 +78,27 @@ stages: dependsOn: Build condition: succeeded() jobs: - - job: UnitTests - displayName: 'Run unit tests' - pool: - vmImage: '$(Vm.Image)' - steps: - - task: DownloadPipelineArtifact@2 - displayName: 'Download build artifacts' - inputs: - artifact: 'Build' - path: '$(Build.SourcesDirectory)' - - task: UseDotNet@2 - displayName: 'Import .NET Core SDK ($(DotNet.Sdk.PreviousVersion))' - inputs: - packageType: 'sdk' - version: '$(DotNet.Sdk.PreviousVersion)' - - template: test/run-unit-tests.yml@templates - parameters: - dotnetSdkVersion: '$(DotNet.Sdk.Version)' - includePreviewVersions: $(DotNet.Sdk.IncludePreviewVersions) - projectName: '$(Project).Tests.Unit' + - template: templates/run-unit-tests.yml - stage: IntegrationTests displayName: Integration Tests dependsOn: Build condition: succeeded() jobs: - - job: IntegrationTests - displayName: 'Run integration tests' - pool: - vmImage: '$(Vm.Image)' - steps: - - task: DownloadPipelineArtifact@2 - displayName: 'Download build artifacts' - inputs: - artifact: 'Build' - path: '$(Build.SourcesDirectory)' - - template: templates/run-self-contained-integration-tests.yml - parameters: - azureServiceConnection: '${{ parameters.azureServiceConnection }}' - keyVaultName: '${{ parameters.keyVaultName }}' + - template: templates/run-self-contained-integration-tests.yml + parameters: + azureServiceConnection: '${{ parameters.azureServiceConnection }}' - stage: DockerTests displayName: Docker Tests dependsOn: Build condition: succeeded() jobs: - - job: DockerTests - displayName: 'Run Docker tests' - pool: - vmImage: '$(Vm.Image)' - steps: - - task: DownloadPipelineArtifact@2 - displayName: 'Download build artifacts' - inputs: - artifact: 'Build' - path: '$(Build.SourcesDirectory)' - - template: templates/run-docker-integration-tests.yml - parameters: - dockerProjectName: '$(Project).Tests.Runtimes.AzureFunction' - httpPort: '$(AzureFunctions.HttpPort)' + - template: templates/run-docker-integration-tests.yml + parameters: + dockerProjectName: '$(Project).Tests.Runtimes.AzureFunction' + httpPort: '$(AzureFunctions.HttpPort)' + azureServiceConnection: '${{ parameters.azureServiceConnection }}' - stage: ReleaseToMyget displayName: 'Release to MyGet' diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index f22f6b3b..b863631f 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -11,17 +11,10 @@ parameters: - name: resourceGroupName displayName: 'Resource group name' default: arcus-observability-dev-we-rg - - name: appInsightsName - displayName: 'Application Insights name' - default: arcus-observability-dev-we-app-insights - - name: variableGroupName - displayName: 'Variable group name' - default: Arcus Observability - Integration Testing variables: - - name: keyVaultName - value: 'arcus-observability-kv' - template: ./variables/build.yml + - template: ./variables/test.yml stages: - stage: Deploy @@ -40,44 +33,13 @@ stages: scriptType: 'pscore' scriptLocation: 'inlineScript' inlineScript: | - Set-PSRepository -Name PSGallery -InstallationPolicy Trusted - Install-Module -Name Arcus.Scripting.DevOps -AllowClobber - az extension add --name application-insights - $objectId = (az ad sp show --id $env:servicePrincipalId | ConvertFrom-Json).id - $appInsightsOutput = az deployment sub create ` + az deployment sub create ` --location westeurope ` --template-file ./build/templates/deploy-test-resources.bicep ` --parameters location=westeurope ` --parameters resourceGroupName=${{ parameters.resourceGroupName }} ` - --parameters appInsightsName=${{ parameters.appInsightsName }} ` - --parameters keyVaultName=${{ variables.keyVaultName }} ` - --parameters servicePrincipal_objectId=$objectId ` - | ConvertFrom-Json - - $apiKeyName = 'Arcus Observability Integration Tests API Key' - if (az monitor app-insights api-key show ` - --app ${{ parameters.appInsightsName }} ` - --resource-group ${{ parameters.resourceGroupName }} ` - --api-key $apiKeyName) { - az monitor app-insights api-key delete ` - --api-key $apiKeyName ` - --app ${{ parameters.appInsightsName }} ` - --resource-group ${{ parameters.resourceGroupName }} ` - --yes - } - - $apiKeyOutput = az monitor app-insights api-key create ` - --api-key $apiKeyName ` - --app ${{ parameters.appInsightsName }} ` - --resource-group ${{ parameters.resourceGroupName }} ` - --read-properties ReadTelemetry ` - | ConvertFrom-Json - - az keyvault secret set ` - --vault-name ${{ variables.keyVaultName }} ` - --name 'ApplicationInsights-ApiKey' ` - --value $apiKeyOutput.apiKey ` - - $env:ArmOutputs = ConvertTo-Json $appInsightsOutput.properties.outputs - Set-AzDevOpsArmOutputsToVariableGroup -VariableGroupName '${{ parameters.variableGroupName }}' \ No newline at end of file + --parameters instrumentationKey_secretName=${{ variables['Arcus.ApplicationInsights.InstrumentationKey.SecretName'] }} ` + --parameters resourceId_secretName=${{ variables['Arcus.LogAnalyticsWorkspace.ResourceId.SecretName'] }} ` + --parameters keyVaultName=${{ variables['KeyVault.Name'] }} ` + --parameters servicePrincipal_objectId=$objectId \ No newline at end of file diff --git a/build/nuget-release.yml b/build/nuget-release.yml index 275e52ad..6a14f33a 100644 --- a/build/nuget-release.yml +++ b/build/nuget-release.yml @@ -10,10 +10,6 @@ parameters: displayName: 'Azure service connection' type: string default: 'Azure Codit-Arcus Service Principal' - - name: keyVaultName - displayName: 'Azure Key vault with integration test secrets' - type: string - default: 'arcus-observability-kv' resources: repositories: @@ -23,7 +19,6 @@ resources: endpoint: arcus-azure variables: - - group: 'Arcus Observability - Integration Testing' - group: 'Build Configuration' - template: ./variables/build.yml - template: ./variables/test.yml @@ -65,66 +60,27 @@ stages: dependsOn: Build condition: succeeded() jobs: - - job: UnitTests - displayName: 'Run unit tests' - pool: - vmImage: '$(Vm.Image)' - steps: - - task: DownloadPipelineArtifact@2 - displayName: 'Download build artifacts' - inputs: - artifact: 'Build' - path: '$(Build.SourcesDirectory)' - - task: UseDotNet@2 - displayName: 'Import .NET Core SDK ($(DotNet.Sdk.PreviousVersion))' - inputs: - packageType: 'sdk' - version: '$(DotNet.Sdk.PreviousVersion)' - - template: test/run-unit-tests.yml@templates - parameters: - dotnetSdkVersion: '$(DotNet.Sdk.Version)' - includePreviewVersions: $(DotNet.Sdk.IncludePreviewVersions) - projectName: '$(Project).Tests.Unit' + - template: templates/run-unit-tests.yml - stage: IntegrationTests displayName: Integration Tests dependsOn: Build condition: succeeded() jobs: - - job: IntegrationTests - displayName: 'Run integration tests' - pool: - vmImage: '$(Vm.Image)' - steps: - - task: DownloadPipelineArtifact@2 - displayName: 'Download build artifacts' - inputs: - artifact: 'Build' - path: '$(Build.SourcesDirectory)' - - template: templates/run-self-contained-integration-tests.yml - parameters: - azureServiceConnection: '${{ parameters.azureServiceConnection }}' - keyVaultName: '${{ parameters.keyVaultName }}' + - template: templates/run-self-contained-integration-tests.yml + parameters: + azureServiceConnection: '${{ parameters.azureServiceConnection }}' - stage: DockerTests displayName: Docker Tests dependsOn: Build condition: succeeded() jobs: - - job: DockerTests - displayName: 'Run Docker tests' - pool: - vmImage: '$(Vm.Image)' - steps: - - task: DownloadPipelineArtifact@2 - displayName: 'Download build artifacts' - inputs: - artifact: 'Build' - path: '$(Build.SourcesDirectory)' - - template: templates/run-docker-integration-tests.yml - parameters: - dockerProjectName: '$(Project).Tests.Runtimes.AzureFunction' - httpPort: '$(AzureFunctions.HttpPort)' + - template: templates/run-docker-integration-tests.yml + parameters: + dockerProjectName: '$(Project).Tests.Runtimes.AzureFunction' + httpPort: '$(AzureFunctions.HttpPort)' + azureServiceConnection: '${{ parameters.azureServiceConnection }}' - stage: Release displayName: 'Release to NuGet.org' diff --git a/build/templates/deploy-test-resources.bicep b/build/templates/deploy-test-resources.bicep index 33c9f392..77f6fdcb 100644 --- a/build/templates/deploy-test-resources.bicep +++ b/build/templates/deploy-test-resources.bicep @@ -4,8 +4,11 @@ param location string // Define the name of the resource group where the components will be deployed. param resourceGroupName string -// Define the name of the Application Insights component. -param appInsightsName string +// Define the name of the secret that will store the Application Insights Instrumentation Key. +param instrumentationKey_secretName string + +// Define the name of the secret that will store the Application Insights workspace resource ID. +param resourceId_secretName string // Define the name of the Key Vault. param keyVaultName string @@ -29,6 +32,9 @@ resource rg 'Microsoft.Resources/resourceGroups@2021-04-01' existing = { module workspace 'br/public:avm/res/operational-insights/workspace:0.3.4' = { name: 'workspaceDeployment' + dependsOn: [ + resourceGroup + ] scope: rg params: { name: 'arcus-observability-dev-we-workspace' @@ -38,16 +44,28 @@ module workspace 'br/public:avm/res/operational-insights/workspace:0.3.4' = { module component 'br/public:avm/res/insights/component:0.3.0' = { name: 'componentDeployment' + dependsOn: [ + resourceGroup + ] scope: rg params: { - name: appInsightsName + name: 'arcus-observability-dev-we-app-insights' workspaceResourceId: workspace.outputs.resourceId location: location + roleAssignments: [ + { + principalId: servicePrincipal_objectId + roleDefinitionIdOrName: 'Log Analytics Contributor' + } + ] } } module vault 'br/public:avm/res/key-vault/vault:0.6.1' = { name: 'vaultDeployment' + dependsOn: [ + resourceGroup + ] scope: rg params: { name: keyVaultName @@ -60,12 +78,13 @@ module vault 'br/public:avm/res/key-vault/vault:0.6.1' = { ] secrets: [ { - name: 'ApplicationInsights-InstrumentationKey' + name: instrumentationKey_secretName value: component.outputs.instrumentationKey } + { + name: resourceId_secretName + value: workspace.outputs.resourceGroupName + } ] } } - -output ApplicationInsights_WorkspaceId string = workspace.outputs.resourceId -output ApplicationInsights_ApplicationId string = component.outputs.applicationId diff --git a/build/templates/import-keyvault-secrets.yml b/build/templates/import-keyvault-secrets.yml new file mode 100644 index 00000000..fb09846e --- /dev/null +++ b/build/templates/import-keyvault-secrets.yml @@ -0,0 +1,23 @@ +parameters: + azureServiceConnection: '' + +steps: + - task: AzureCLI@2 + displayName: 'Import secrets from Azure Key Vault' + inputs: + azureSubscription: '${{ parameters.azureServiceConnection }}' + scriptType: 'pscore' + scriptLocation: 'inlineScript' + inlineScript: | + Set-PSRepository -Name PSGallery -InstallationPolicy Trusted + Install-Module -Name Arcus.Scripting.DevOps -AllowClobber + + Set-AzDevOpsVariable -Name 'Arcus.Observability.TenantId' -Value $env:tenantId + Set-AzDevOpsVariable -Name 'Arcus.Observability.ServicePrincipal.ClientId' -Value $env:servicePrincipalId + Set-AzDevOpsVariable -Name 'Arcus.Observability.ServicePrincipal.ClientSecret' -Value $env:servicePrincipalKey + + $keyVaultName = ${{ variables['Arcus.KeyVault.Name'] }} + $resourceId_secretName = ${{ variables['Arcus.LogAnalyticsWorkspace.ResourceId.SecretName'] }} + $instrumentationKey_secretName = ${{ variables['Arcus.ApplicationInsights.InstrumentationKey.SecretName'] }} + az keyvault secret show --name $instrumentationKey_secretName --vault-name $keyVaultName --query value -o tsv | Set-AzDevOpsVariable -AsSecret -Name 'Arcus.Observability.ApplicationInsights.InstrumentationKey' -Value + az keyvault secret show --name $resourceId_secretName --vault-name $keyVaultName --query value -o tsv | Set-AzDevOpsVariable -AsSecret -Name 'Arcus.Observability.LogAnalyticsWorkspace.ResourceId' -Value \ No newline at end of file diff --git a/build/templates/run-docker-integration-tests.yml b/build/templates/run-docker-integration-tests.yml index e5c4aea1..007d2370 100644 --- a/build/templates/run-docker-integration-tests.yml +++ b/build/templates/run-docker-integration-tests.yml @@ -1,59 +1,82 @@ parameters: dockerProjectName: '' httpPort: '' + azureServiceConnection: '' -steps: - - bash: | - if [ -z "$PROJECT_NAME" ]; then - echo "##vso[task.logissue type=error;]Missing template parameter \"dockerProjectName\"" - echo "##vso[task.complete result=Failed;]" - fi - if [ -z "$HTTP_PORT" ]; then - echo "##vso[task.logissue type=error;]Missing template parameter \"httpPort\"" - echo "##vso[task.complete result=Failed;]" - fi - env: - PROJECT_NAME: ${{ parameters.dockerProjectName }} - HTTP_PORT: ${{ parameters.httpPort }} - - task: UseDotNet@2 - displayName: 'Import .NET Core SDK ($(DotNet.Sdk.PreviousVersion))' - inputs: - packageType: 'sdk' - version: '$(DotNet.Sdk.PreviousVersion)' - - task: UseDotNet@2 - displayName: 'Import .NET Core SDK ($(DotNet.Sdk.Version))' - inputs: - packageType: 'sdk' - version: '$(DotNet.Sdk.Version)' - includePreviewVersions: $(DotNet.Sdk.IncludePreviewVersions) - - task: Docker@1 - displayName: 'Build Docker image from ${{ parameters.dockerProjectName }}' - inputs: - dockerFile: src/${{ parameters.dockerProjectName }}/Dockerfile - imageName: '${{ parameters.dockerProjectName }}:$(Build.BuildId)' - useDefaultContext: false - buildContext: src - - task: Docker@1 - displayName: 'Run new project Docker image from ${{ parameters.dockerProjectName }}' - inputs: - command: 'Run an image' - imageName: '${{ parameters.dockerProjectName }}:$(Build.BuildId)' - containerName: '${{ parameters.dockerProjectName }}' - ports: '${{ parameters.httpPort }}:80' - envVars: | - APPINSIGHTS_INSTRUMENTATIONKEY=$(ApplicationInsights.InstrumentationKey) - AzureWebJobsStorage=$(Arcus.AzureFunctions.AzureWebJobsStorage) - - template: test/run-integration-tests.yml@templates - parameters: - dotnetSdkVersion: '$(DotNet.Sdk.Version)' - includePreviewVersions: $(DotNet.Sdk.IncludePreviewVersions) - projectName: '$(Project).Tests.Integration' - category: 'Docker' - - task: Bash@3 - inputs: - targetType: 'inline' - script: | - docker logs ${{ parameters.dockerProjectName }} - failOnStderr: true - displayName: Show ${{ parameters.dockerProjectName }} logs - condition: always() +jobs: + - job: DockerTests + displayName: 'Run Docker tests' + pool: + vmImage: '$(Vm.Image)' + steps: + - task: DownloadPipelineArtifact@2 + displayName: 'Download build artifacts' + inputs: + artifact: 'Build' + path: '$(Build.SourcesDirectory)' + + - bash: | + if [ -z "$PROJECT_NAME" ]; then + echo "##vso[task.logissue type=error;]Missing template parameter \"dockerProjectName\"" + echo "##vso[task.complete result=Failed;]" + fi + if [ -z "$HTTP_PORT" ]; then + echo "##vso[task.logissue type=error;]Missing template parameter \"httpPort\"" + echo "##vso[task.complete result=Failed;]" + fi + env: + PROJECT_NAME: ${{ parameters.dockerProjectName }} + HTTP_PORT: ${{ parameters.httpPort }} + + - task: UseDotNet@2 + displayName: 'Import .NET Core SDK ($(DotNet.Sdk.PreviousVersion))' + inputs: + packageType: 'sdk' + version: '$(DotNet.Sdk.PreviousVersion)' + + - task: UseDotNet@2 + displayName: 'Import .NET Core SDK ($(DotNet.Sdk.Version))' + inputs: + packageType: 'sdk' + version: '$(DotNet.Sdk.Version)' + includePreviewVersions: $(DotNet.Sdk.IncludePreviewVersions) + + - template: import-keyvault-secrets.yml + parameters: + azureServiceConnection: '${{ parameters.azureServiceConnection }}' + + - task: Docker@1 + displayName: 'Build Docker image from ${{ parameters.dockerProjectName }}' + inputs: + dockerFile: src/${{ parameters.dockerProjectName }}/Dockerfile + imageName: '${{ parameters.dockerProjectName }}:$(Build.BuildId)' + useDefaultContext: false + buildContext: src + + - task: Docker@1 + displayName: 'Run new project Docker image from ${{ parameters.dockerProjectName }}' + inputs: + command: 'Run an image' + imageName: '${{ parameters.dockerProjectName }}:$(Build.BuildId)' + containerName: '${{ parameters.dockerProjectName }}' + ports: '${{ parameters.httpPort }}:80' + envVars: | + APPINSIGHTS_INSTRUMENTATIONKEY=$(ApplicationInsights_InstrumentationKey) + AzureWebJobsStorage=$(Arcus.AzureFunctions.AzureWebJobsStorage) + + - template: test/run-integration-tests.yml@templates + parameters: + dotnetSdkVersion: '$(DotNet.Sdk.Version)' + includePreviewVersions: $(DotNet.Sdk.IncludePreviewVersions) + projectName: '$(Project).Tests.Integration' + category: 'Docker' + + - task: Bash@3 + inputs: + targetType: 'inline' + script: | + docker logs ${{ parameters.dockerProjectName }} + failOnStderr: true + displayName: Show ${{ parameters.dockerProjectName }} logs + condition: always() + \ No newline at end of file diff --git a/build/templates/run-self-contained-integration-tests.yml b/build/templates/run-self-contained-integration-tests.yml index 456ca1b2..6cf3e5d3 100644 --- a/build/templates/run-self-contained-integration-tests.yml +++ b/build/templates/run-self-contained-integration-tests.yml @@ -1,22 +1,31 @@ parameters: azureServiceConnection: '' - keyVaultName: '' -steps: - - task: UseDotNet@2 - displayName: 'Import .NET Core SDK ($(DotNet.Sdk.PreviousVersion))' - inputs: - packageType: 'sdk' - version: '$(DotNet.Sdk.PreviousVersion)' - - task: AzureKeyVault@2 - displayName: 'Import secrets from Azure Key Vault' - inputs: - azureSubscription: '${{ parameters.azureServiceConnection }}' - KeyVaultName: '${{ parameters.keyVaultName }}' - SecretsFilter: '*' - - template: test/run-integration-tests.yml@templates - parameters: - dotnetSdkVersion: '$(DotNet.Sdk.Version)' - includePreviewVersions: $(DotNet.Sdk.IncludePreviewVersions) - projectName: '$(Project).Tests.Integration' - category: 'Integration' \ No newline at end of file +jobs: + - job: IntegrationTests + displayName: 'Run integration tests' + pool: + vmImage: '$(Vm.Image)' + steps: + - task: DownloadPipelineArtifact@2 + displayName: 'Download build artifacts' + inputs: + artifact: 'Build' + path: '$(Build.SourcesDirectory)' + + - task: UseDotNet@2 + displayName: 'Import .NET Core SDK ($(DotNet.Sdk.PreviousVersion))' + inputs: + packageType: 'sdk' + version: '$(DotNet.Sdk.PreviousVersion)' + + - template: import-keyvault-secrets.yml + parameters: + azureServiceConnection: '${{ parameters.azureServiceConnection }}' + + - template: test/run-integration-tests.yml@templates + parameters: + dotnetSdkVersion: '$(DotNet.Sdk.Version)' + includePreviewVersions: $(DotNet.Sdk.IncludePreviewVersions) + projectName: '$(Project).Tests.Integration' + category: 'Integration' \ No newline at end of file diff --git a/build/templates/run-unit-tests.yml b/build/templates/run-unit-tests.yml new file mode 100644 index 00000000..8f3a4dbd --- /dev/null +++ b/build/templates/run-unit-tests.yml @@ -0,0 +1,23 @@ +jobs: + - job: UnitTests + displayName: 'Run unit tests' + pool: + vmImage: '$(Vm.Image)' + steps: + - task: DownloadPipelineArtifact@2 + displayName: 'Download build artifacts' + inputs: + artifact: 'Build' + path: '$(Build.SourcesDirectory)' + + - task: UseDotNet@2 + displayName: 'Import .NET Core SDK ($(DotNet.Sdk.PreviousVersion))' + inputs: + packageType: 'sdk' + version: '$(DotNet.Sdk.PreviousVersion)' + + - template: test/run-unit-tests.yml@templates + parameters: + dotnetSdkVersion: '$(DotNet.Sdk.Version)' + includePreviewVersions: $(DotNet.Sdk.IncludePreviewVersions) + projectName: '$(Project).Tests.Unit' \ No newline at end of file diff --git a/build/variables/test.yml b/build/variables/test.yml index f6ec8be2..f67dda66 100644 --- a/build/variables/test.yml +++ b/build/variables/test.yml @@ -1,2 +1,5 @@ variables: - AzureFunctions.HttpPort: 5000 \ No newline at end of file + AzureFunctions.HttpPort: 5000 + Arcus.Observability.KeyVault.Name: 'arcus-observability-kv' + Arcus.Observability.ApplicationInsights.InstrumentationKey.SecretName: 'ApplicationInsights-InstrumentationKey' + Arcus.Observability.LogAnalyticsWorkspace.ResourceId.SecretName: 'LogAnalytics-Workspace-ResourceId' \ No newline at end of file diff --git a/src/Arcus.Observability.Tests.Integration/Arcus.Observability.Tests.Integration.csproj b/src/Arcus.Observability.Tests.Integration/Arcus.Observability.Tests.Integration.csproj index 94e8bc08..c910fe98 100644 --- a/src/Arcus.Observability.Tests.Integration/Arcus.Observability.Tests.Integration.csproj +++ b/src/Arcus.Observability.Tests.Integration/Arcus.Observability.Tests.Integration.csproj @@ -10,13 +10,14 @@ - + + + + - - diff --git a/src/Arcus.Observability.Tests.Integration/AssertX.cs b/src/Arcus.Observability.Tests.Integration/AssertX.cs index c44ae3f1..ada57e27 100644 --- a/src/Arcus.Observability.Tests.Integration/AssertX.cs +++ b/src/Arcus.Observability.Tests.Integration/AssertX.cs @@ -25,7 +25,9 @@ public static void Any(IEnumerable collection, Action assertion) { Guard.NotNull(collection, nameof(collection), "Requires collection of elements to find a single element that matches the assertion"); Guard.NotNull(assertion, nameof(assertion), "Requires an element assertion to verify if an single element in the collection matches"); - + + Assert.NotEmpty(collection); + T[] array = collection.ToArray(); var stack = new Stack>(); diff --git a/src/Arcus.Observability.Tests.Integration/Configuration/ServicePrincipal.cs b/src/Arcus.Observability.Tests.Integration/Configuration/ServicePrincipal.cs new file mode 100644 index 00000000..1ebd8834 --- /dev/null +++ b/src/Arcus.Observability.Tests.Integration/Configuration/ServicePrincipal.cs @@ -0,0 +1,57 @@ +using Arcus.Testing; +using GuardNet; + +namespace Arcus.Observability.Tests.Integration.Configuration +{ + /// + /// Represents the service principal to authenticate against Azure services. + /// + public class ServicePrincipal + { + /// + /// Initializes a new instance of the class. + /// + public ServicePrincipal(string tenantId, string clientId, string clientSecret) + { + Guard.NotNullOrWhitespace(tenantId, nameof(tenantId)); + Guard.NotNullOrWhitespace(clientId, nameof(clientId)); + Guard.NotNullOrWhitespace(clientSecret, nameof(clientSecret)); + + TenantId = tenantId; + ClientId = clientId; + ClientSecret = clientSecret; + } + + /// + /// Gets the tenant ID of the Azure Active Directory tenant. + /// + public string TenantId { get; } + + /// + /// Gets the client ID of the service principal. + /// + public string ClientId { get; } + + /// + /// Gets the client secret of the service principal. + /// + public string ClientSecret { get; } + } + + /// + /// Extensions on the to load the service principal from the test configuration. + /// + public static class TestConfigExtensions + { + /// + /// Loads the service principal from the test configuration. + /// + public static ServicePrincipal GetServicePrincipal(this TestConfig config) + { + return new ServicePrincipal( + config["Arcus:TenantId"], + config["Arcus:ServicePrincipal:ClientId"], + config["Arcus:ServicePrincipal:ClientSecret"]); + } + } +} \ No newline at end of file diff --git a/src/Arcus.Observability.Tests.Integration/IntegrationTest.cs b/src/Arcus.Observability.Tests.Integration/IntegrationTest.cs index 4d244eec..dd0c3898 100644 --- a/src/Arcus.Observability.Tests.Integration/IntegrationTest.cs +++ b/src/Arcus.Observability.Tests.Integration/IntegrationTest.cs @@ -1,21 +1,15 @@ -using Arcus.Testing.Logging; -using Microsoft.Extensions.Configuration; +using Arcus.Testing; using Xunit.Abstractions; namespace Arcus.Observability.Tests.Integration { public class IntegrationTest { - protected IConfiguration Configuration { get; } + protected TestConfig Configuration { get; } public IntegrationTest(ITestOutputHelper testOutput) { - // The appsettings.local.json allows users to override (gitignored) settings locally for testing purposes - Configuration = new ConfigurationBuilder() - .AddJsonFile(path: "appsettings.json") - .AddJsonFile(path: "appsettings.local.json", optional: true) - .AddEnvironmentVariables() - .Build(); + Configuration = TestConfig.Create(); } } } \ No newline at end of file diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AppInsightsClient.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AppInsightsClient.cs new file mode 100644 index 00000000..e4f77630 --- /dev/null +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AppInsightsClient.cs @@ -0,0 +1,189 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Arcus.Observability.Tests.Integration.Configuration; +using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; +using Arcus.Testing; +using Azure.Identity; +using Azure.Monitor.Query; +using Azure.Monitor.Query.Models; +using Newtonsoft.Json; + +namespace Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights +{ + /// + /// Represents a remote client to query telemetry data from the Azure Application Insights instance. + /// + public class AppInsightsClient : ITelemetryQueryClient + { + private readonly LogsQueryClient _queryClient; + private readonly QueryTimeRange _timeRange; + private readonly string _resourceId; + + /// + /// Initializes a new instance of the class. + /// + public AppInsightsClient(TestConfig config) + { + ServicePrincipal servicePrincipal = config.GetServicePrincipal(); + _queryClient = new LogsQueryClient(new ClientSecretCredential(servicePrincipal.TenantId, servicePrincipal.ClientId, servicePrincipal.ClientSecret)); + _resourceId = config["Arcus:LogAnalyticsWorkspace:ResourceId"]; + _timeRange = new QueryTimeRange(TimeSpan.FromDays(1)); + } + + /// + /// Gets the tracked traces from the Azure Application Insights instance. + /// + public async Task GetTracesAsync() + { + IReadOnlyCollection rows = + await QueryLogsAsync("AppTraces | project Message, OperationId, ParentId, AppRoleName, Properties"); + + return rows.Select(row => + { + string message = row[0].ToString(); + string operationId = row[1].ToString(); + string parentId = row[2].ToString(); + var operation = new OperationResult(operationId, parentId); + + string roleName = row[3].ToString(); + string customDimensionsTxt = row[4].ToString(); + var customDimensions = JsonConvert.DeserializeObject>(customDimensionsTxt); + + return new TraceResult(message, roleName, operation, customDimensions); + + }).ToArray(); + } + + /// + /// Gets the tracked metrics from the Azure Application Insights instance. + /// + public Task GetMetricsAsync(string metricName) + { + throw new NotImplementedException(); + } + + /// + /// Gets the tracked custom events from the Azure Application Insights instance. + /// + public async Task GetCustomEventsAsync() + { + IReadOnlyCollection rows = + await QueryLogsAsync("AppEvents | project Name, AppRoleName, Properties"); + + return rows.Select(row => + { + string name = row[0].ToString(); + string roleName = row[1].ToString(); + + var customDimensionsTxt = row[2].ToString(); + var customDimensions = JsonConvert.DeserializeObject>(customDimensionsTxt); + + return new CustomEventResult(name, roleName, customDimensions); + + }).ToArray(); + } + + /// + /// Gets the tracked requests from the Azure Application Insights instance. + /// + public async Task GetRequestsAsync() + { + IReadOnlyCollection rows = + await QueryLogsAsync( + "AppRequests | project Id, Name, Source, Url, Success, ResultCode, AppRoleName, OperationId, ParentId, Properties"); + + return rows.Select(row => + { + string id = row[0].ToString(); + string name = row[1].ToString(); + string source = row[2].ToString(); + string url = row[3].ToString(); + bool success = bool.Parse(row[4].ToString() ?? string.Empty); + string resultCode = row[5].ToString(); + string roleName = row[6].ToString(); + + string operationId = row[7].ToString(); + string operationParentId = row[8].ToString(); + var operation = new OperationResult(operationId, operationParentId, name); + + var customDimensionsTxt = row[9].ToString(); + var customDimensions = JsonConvert.DeserializeObject>(customDimensionsTxt); + + return new RequestResult(id, name, source, url, success, resultCode, roleName, operation, customDimensions); + + }).ToArray(); + } + + /// + /// Gets the tracked dependencies from the Azure Application Insights instance. + /// + public async Task GetDependenciesAsync() + { + IReadOnlyCollection rows = + await QueryLogsAsync("AppDependencies | project Id, Target, DependencyType, Name, Data, Success, ResultCode, AppRoleName, OperationId, ParentId, Properties"); + + return rows.Select(row => + { + string id = row[0].ToString(); + string target = row[1].ToString(); + string type = row[2].ToString(); + string name = row[3].ToString(); + string data = row[4].ToString(); + + bool success = bool.Parse(row[5].ToString() ?? string.Empty); + var resultCodeTxt = row[6].ToString(); + int resultCode = string.IsNullOrWhiteSpace(resultCodeTxt) ? 0 : int.Parse(resultCodeTxt); + + string roleName = row[7].ToString(); + + string operationId = row[8].ToString(); + string operationParentId = row[9].ToString(); + var operation = new OperationResult(operationId, operationParentId); + + var customDimensionsTxt = row[10].ToString(); + var customDimensions = JsonConvert.DeserializeObject>(customDimensionsTxt); + + return new DependencyResult(id, type, target, data, success, resultCode, name, roleName, operation, customDimensions); + + }).ToArray(); + } + + /// + /// Gets the tracked exceptions from the Azure Application Insights instance. + /// + public async Task GetExceptionsAsync() + { + IReadOnlyCollection rows = + await QueryLogsAsync("AppExceptions | project Message, OperationId, ParentId, AppRoleName, Properties"); + + return rows.Select(row => + { + string message = row[0].ToString(); + string operationId = row[1].ToString(); + string parentId = row[2].ToString(); + var operation = new OperationResult(operationId, parentId); + + string roleName = row[3].ToString(); + + string customDimensionsTxt = row[4].ToString(); + var customDimensions = JsonConvert.DeserializeObject>(customDimensionsTxt); + + return new ExceptionResult(message, operation, roleName, customDimensions); + + }).ToArray(); + } + + private async Task> QueryLogsAsync(string query) + { + LogsQueryResult response = await _queryClient.QueryWorkspaceAsync( + _resourceId, + query, + timeRange: _timeRange, + new LogsQueryOptions { ServerTimeout = TimeSpan.FromSeconds(3) }); + + return response.Table.Rows; + } + } +} diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsClient.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsClient.cs deleted file mode 100644 index 00e1df10..00000000 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsClient.cs +++ /dev/null @@ -1,120 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using GuardNet; -using Microsoft.Azure.ApplicationInsights.Query; -using Microsoft.Azure.ApplicationInsights.Query.Models; -using Xunit; -using Xunit.Sdk; - -namespace Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights -{ - /// - /// Represents a simple client to interact with the available features of Application Insights. - /// - public class ApplicationInsightsClient - { - private const string PastHalfHourTimeSpan = "PT30M"; - - private readonly IApplicationInsightsDataClient _dataClient; - private readonly string _applicationId; - - /// - /// Initializes a new instance of the class. - /// - /// The core client to retrieve telemetry from Application Insights. - /// The application ID to identify the Application Insights resource to request telemetry from. - /// Thrown when the is null. - /// Thrown when the is blank. - public ApplicationInsightsClient(IApplicationInsightsDataClient dataClient, string applicationId) - { - Guard.NotNull(dataClient, nameof(dataClient), "Requires a data client implementation to retrieve telemetry form Application Insights"); - Guard.NotNullOrWhitespace(applicationId, nameof(applicationId), "Requires an application ID to identify the Application Insights resource to request telemetry from"); - - _dataClient = dataClient; - _applicationId = applicationId; - } - - /// - /// Gets the currently available dependencies tracked on Application Insights. - /// - /// Thrown when the retrieved telemetry doesn't contain any items. - public async Task GetDependenciesAsync() - { - EventsResults result = - await _dataClient.Events.GetDependencyEventsAsync(_applicationId, timespan: PastHalfHourTimeSpan); - - Assert.NotEmpty(result.Value); - return result.Value.ToArray(); - } - - /// - /// Gets the currently available requests tracked on Application Insights. - /// - /// Thrown when the retrieved telemetry doesn't contain any items. - public async Task GetRequestsAsync() - { - EventsResults result = - await _dataClient.Events.GetRequestEventsAsync(_applicationId, timespan: PastHalfHourTimeSpan); - - Assert.NotEmpty(result.Value); - return result.Value.ToArray(); - } - - /// - /// Gets the currently available metrics tracked on Application Insights. - /// - /// The schema body content of the request to filter out metrics. - /// Thrown when the is null. - /// Thrown when the retrieved telemetry doesn't contain any items. - public async Task GetMetricsAsync(MetricsPostBodySchema body) - { - Guard.NotNull(body, nameof(body), "Requires a metrics body schema to request specific metrics from Application Insights"); - - IList items = - await _dataClient.Metrics.GetMultipleAsync(_applicationId, new List { body }); - - return items.ToArray(); - } - - /// - /// Gets the currently available exceptions tracked on Application Insights. - /// - /// Thrown when the retrieved telemetry doesn't contain any items. - public async Task GetExceptionsAsync() - { - EventsResults result = - await _dataClient.Events.GetExceptionEventsAsync(_applicationId, timespan: PastHalfHourTimeSpan); - - Assert.NotEmpty(result.Value); - return result.Value.ToArray(); - } - - /// - /// Gets the currently available traces tracked on Application Insights. - /// - /// Thrown when the retrieved telemetry doesn't contain any items. - public async Task GetTracesAsync() - { - EventsResults result = - await _dataClient.Events.GetTraceEventsAsync(_applicationId, timespan: PastHalfHourTimeSpan); - - Assert.NotEmpty(result.Value); - return result.Value.ToArray(); - } - - /// - /// Gets the currently available events tracked on Application Insights. - /// - /// Thrown when the retrieved telemetry doesn't contain any items. - public async Task GetEventsAsync() - { - EventsResults result = - await _dataClient.Events.GetCustomEventsAsync(_applicationId, timespan: PastHalfHourTimeSpan); - - Assert.NotEmpty(result.Value); - return result.Value.ToArray(); - } - } -} \ No newline at end of file diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsSinkExtensionTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsSinkExtensionTests.cs index adcd9f27..de522832 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsSinkExtensionTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsSinkExtensionTests.cs @@ -1,11 +1,10 @@ using System; -using System.Net.Http; using System.Threading.Tasks; using Arcus.Observability.Correlation; using Arcus.Observability.Telemetry.Core; +using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; using Microsoft.ApplicationInsights; using Microsoft.AspNetCore.Http; -using Microsoft.Azure.ApplicationInsights.Query.Models; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Serilog; @@ -43,10 +42,10 @@ public async Task Sink_WithConnectionString_WritesTelemetry() // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsTraceResult[] traces = await client.GetTracesAsync(); + TraceResult[] traces = await client.GetTracesAsync(); AssertX.Any(traces, trace => { - Assert.Equal(message, trace.Trace.Message); + Assert.Equal(message, trace.Message); }); }); } @@ -72,10 +71,10 @@ public async Task Sink_WithConnectionStringWithServiceProvider_WritesTelemetry() // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsTraceResult[] traces = await client.GetTracesAsync(); + TraceResult[] traces = await client.GetTracesAsync(); AssertX.Any(traces, trace => { - Assert.Equal(message, trace.Trace.Message); + Assert.Equal(message, trace.Message); }); }); } @@ -96,10 +95,10 @@ public async Task Sink_WithInstrumentationKey_WritesTelemetry() // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsTraceResult[] traces = await client.GetTracesAsync(); + TraceResult[] traces = await client.GetTracesAsync(); AssertX.Any(traces, trace => { - Assert.Equal(message, trace.Trace.Message); + Assert.Equal(message, trace.Message); }); }); } @@ -123,10 +122,10 @@ public async Task Sink_WithInstrumentationKeyWithServiceProvider_WritesTelemetry // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsTraceResult[] traces = await client.GetTracesAsync(); + TraceResult[] traces = await client.GetTracesAsync(); AssertX.Any(traces, trace => { - Assert.Equal(message, trace.Trace.Message); + Assert.Equal(message, trace.Message); }); }); } @@ -151,12 +150,12 @@ public async Task SinkWithCustomTransactionIdPropertyName_TrackNonRequest_Enrich // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsTraceResult[] result = await client.GetTracesAsync(); - AssertX.Any(result, result => + TraceResult[] result = await client.GetTracesAsync(); + AssertX.Any(result, trace => { - Assert.Equal(message, result.Trace.Message); - Assert.Equal(correlation.TransactionId, result.Operation.Id); - Assert.Equal(correlation.OperationId, result.Operation.ParentId); + Assert.Equal(message, trace.Message); + Assert.Equal(correlation.TransactionId, trace.Operation.Id); + Assert.Equal(correlation.OperationId, trace.Operation.ParentId); }); }); } @@ -181,12 +180,12 @@ public async Task SinkWithCustomOperationIdPropertyName_TrackNonRequest_EnrichCo // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsTraceResult[] result = await client.GetTracesAsync(); - AssertX.Any(result, result => + TraceResult[] result = await client.GetTracesAsync(); + AssertX.Any(result, trace => { - Assert.Equal(message, result.Trace.Message); - Assert.Equal(correlation.TransactionId, result.Operation.Id); - Assert.Equal(correlation.OperationId, result.Operation.ParentId); + Assert.Equal(message, trace.Message); + Assert.Equal(correlation.TransactionId, trace.Operation.Id); + Assert.Equal(correlation.OperationId, trace.Operation.ParentId); }); }); } @@ -218,12 +217,12 @@ public async Task SinkWithCustomTransactionIdPropertyName_TrackRequest_EnrichCor // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsRequestResult[] result = await client.GetRequestsAsync(); - AssertX.Any(result, result => + RequestResult[] result = await client.GetRequestsAsync(); + AssertX.Any(result, request => { - Assert.Equal(correlation.TransactionId, result.Operation.Id); - Assert.Equal(correlation.OperationId, result.Request.Id); - Assert.Equal(correlation.OperationParentId, result.Operation.ParentId); + Assert.Equal(correlation.TransactionId, request.Operation.Id); + Assert.Equal(correlation.OperationId, request.Id); + Assert.Equal(correlation.OperationParentId, request.Operation.ParentId); }); }); } @@ -255,12 +254,12 @@ public async Task SinkWithCustomOperationIdPropertyName_TrackRequest_EnrichCorre // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsRequestResult[] result = await client.GetRequestsAsync(); - AssertX.Any(result, result => + RequestResult[] result = await client.GetRequestsAsync(); + AssertX.Any(result, request => { - Assert.Equal(correlation.TransactionId, result.Operation.Id); - Assert.Equal(correlation.OperationId, result.Request.Id); - Assert.Equal(correlation.OperationParentId, result.Operation.ParentId); + Assert.Equal(correlation.TransactionId, request.Operation.Id); + Assert.Equal(correlation.OperationId, request.Id); + Assert.Equal(correlation.OperationParentId, request.Operation.ParentId); }); }); } @@ -292,12 +291,12 @@ public async Task SinkWithCustomOperationParentIdPropertyName_TrackRequest_Enric // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsRequestResult[] result = await client.GetRequestsAsync(); - AssertX.Any(result, result => + RequestResult[] result = await client.GetRequestsAsync(); + AssertX.Any(result, request => { - Assert.Equal(correlation.TransactionId, result.Operation.Id); - Assert.Equal(correlation.OperationId, result.Request.Id); - Assert.Equal(correlation.OperationParentId, result.Operation.ParentId); + Assert.Equal(correlation.TransactionId, request.Operation.Id); + Assert.Equal(correlation.OperationId, request.Id); + Assert.Equal(correlation.OperationParentId, request.Operation.ParentId); }); }); } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsSinkTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsSinkTests.cs index 18c83ce3..b6f35fd1 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsSinkTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsSinkTests.cs @@ -3,50 +3,56 @@ using System.Runtime.CompilerServices; using System.Threading.Tasks; using Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights.Configuration; -using Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights.Converters; -using Arcus.Observability.Tests.Core; +using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; +using Arcus.Testing; using Bogus; using GuardNet; -using Microsoft.Azure.ApplicationInsights.Query; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; -using Polly; -using Polly.Timeout; using Serilog; +using Serilog.Configuration; using Xunit; using Xunit.Abstractions; +using Xunit.Sdk; using ILogger = Microsoft.Extensions.Logging.ILogger; +using InMemoryLogSink = Arcus.Observability.Tests.Core.InMemoryLogSink; namespace Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights { + public enum TestLocation { Local, Remote } + [Trait(name: "Category", value: "Integration")] public class ApplicationInsightsSinkTests : IntegrationTest { + private readonly ITestOutputHelper _testOutput; private readonly InMemoryLogSink _memoryLogSink; + private readonly InMemoryApplicationInsightsTelemetryConverter _telemetrySink; + /// /// Gets the test generator to create bogus content during the integration test. /// - protected static readonly Faker BogusGenerator = new Faker(); + protected static readonly Faker BogusGenerator = new(); /// /// Initializes a new instance of the class. /// - public ApplicationInsightsSinkTests(ITestOutputHelper outputWriter) : base(outputWriter) + protected ApplicationInsightsSinkTests(ITestOutputHelper outputWriter) : base(outputWriter) { _memoryLogSink = new InMemoryLogSink(); - TestOutput = outputWriter; + _testOutput = outputWriter; ApplicationInsightsSinkOptions = new ApplicationInsightsSinkOptions(); LoggerConfiguration = new LoggerConfiguration(); InstrumentationKey = Configuration.GetValue("ApplicationInsights:InstrumentationKey"); ApplicationId = Configuration.GetValue("ApplicationInsights:ApplicationId"); + _telemetrySink = new InMemoryApplicationInsightsTelemetryConverter(); } /// - /// Gets the to write information to the test output. + /// Gets or sets the test location to determine where the telemetry should be logged to. /// - protected ITestOutputHelper TestOutput { get; } + protected TestLocation TestLocation { get; set; } /// /// Gets the instrumentation key to connect to the Azure Application Insights instance. @@ -75,12 +81,35 @@ protected ILogger Logger { get { + ApplicationInsightsSinkOptions userOptions = ApplicationInsightsSinkOptions; + _telemetrySink.Options = userOptions; + LoggerConfiguration .MinimumLevel.Verbose() - .WriteTo.Sink(new XunitLogEventSink(TestOutput)) - .WriteTo.ApplicationInsights("InstrumentationKey=" + InstrumentationKey, ApplicationInsightsTelemetryConverter.Create(ApplicationInsightsSinkOptions)) + .WriteTo.Sink(new XunitLogEventSink(_testOutput)) .WriteTo.Sink(_memoryLogSink); + switch (TestLocation) + { + case TestLocation.Local: + LoggerConfiguration.WriteTo.ApplicationInsights(_telemetrySink); + break; + + case TestLocation.Remote: + LoggerConfiguration.WriteTo.AzureApplicationInsightsWithConnectionString("InstrumentationKey=" + InstrumentationKey, options => + { + options.Correlation.OperationIdPropertyName = userOptions.Correlation.OperationIdPropertyName; + options.Correlation.OperationParentIdPropertyName = userOptions.Correlation.OperationParentIdPropertyName; + options.Correlation.TransactionIdPropertyName = userOptions.Correlation.TransactionIdPropertyName; + + options.Exception.IncludeProperties = userOptions.Exception.IncludeProperties; + options.Exception.PropertyFormat = userOptions.Exception.PropertyFormat; + + options.Request.GenerateId = userOptions.Request.GenerateId; + }); + break; + } + ILogger logger = CreateLogger(LoggerConfiguration); return logger; } @@ -100,6 +129,9 @@ protected ILogger CreateLogger(LoggerConfiguration config) { Guard.NotNull(config, nameof(config), "Requires a Serilog logger configuration instance to setup the test logger used during the test"); + _telemetrySink.Options = ApplicationInsightsSinkOptions; + config.WriteTo.ApplicationInsights(_telemetrySink); + ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddSerilog(config.CreateLogger(), dispose: true)); ILogger logger = loggerFactory.CreateLogger(); @@ -113,7 +145,7 @@ protected ILogger CreateLogger(LoggerConfiguration config) protected Dictionary CreateTestTelemetryContext([CallerMemberName] string memberName = "") { var testId = Guid.NewGuid(); - TestOutput.WriteLine("Testing '{0}' using {1}", memberName, testId); + _testOutput.WriteLine("Testing '{0}' using {1}", memberName, testId); return new Dictionary { @@ -127,65 +159,35 @@ protected Dictionary CreateTestTelemetryContext([CallerMemberNam /// /// The assertion function that takes in an Application Insights client which provides access to the available telemetry. /// Thrown when the is null. - /// Thrown when the failed to be verified within the configured timeout. - protected async Task RetryAssertUntilTelemetryShouldBeAvailableAsync(Func assertion) + /// Thrown when the failed to be verified within the configured timeout. + protected async Task RetryAssertUntilTelemetryShouldBeAvailableAsync(Func assertion) { - Guard.NotNull(assertion, nameof(assertion), "Requires an assertion function to correctly verify if the logged telemetry is tracked in Application Insights"); + Guard.NotNull(assertion, nameof(assertion)); - using (ApplicationInsightsDataClient dataClient = CreateApplicationInsightsClient()) + if (TestLocation is TestLocation.Remote) { - await RetryAssertUntilTelemetryShouldBeAvailableAsync(async () => - { - var client = new ApplicationInsightsClient(dataClient, ApplicationId); - await assertion(client); - }, timeout: TimeSpan.FromMinutes(8)); + var client = new AppInsightsClient(Configuration); + await RetryAssertUntilTelemetryShouldBeAvailableAsync( + async () => await assertion(client), + timeout: TimeSpan.FromMinutes(5)); + } + else if (TestLocation is TestLocation.Local) + { + var client = new InMemoryTelemetryQueryClient(_telemetrySink); + await RetryAssertUntilTelemetryShouldBeAvailableAsync( + async () => await assertion(client), + TimeSpan.FromSeconds(5)); } } - private ApplicationInsightsDataClient CreateApplicationInsightsClient() - { - var clientCredentials = new ApiKeyClientCredentials(Configuration.GetValue("ApplicationInsights:ApiKey")); - var client = new ApplicationInsightsDataClient(clientCredentials); - - return client; - } - - private static async Task RetryAssertUntilTelemetryShouldBeAvailableAsync(Func assertion, TimeSpan timeout) + private async Task RetryAssertUntilTelemetryShouldBeAvailableAsync(Func assertion, TimeSpan timeout) { - Exception lastException = null; - PolicyResult result = - await Policy.TimeoutAsync(timeout) - .WrapAsync(Policy.Handle() - .WaitAndRetryForeverAsync(index => TimeSpan.FromSeconds(1))) - .ExecuteAndCaptureAsync(async () => - { - try - { - await assertion(); - } - catch (Exception exception) - { - lastException = exception; - throw; - } - }); - - if (result.Outcome is OutcomeType.Failure) + await Poll.UntilAvailableAsync(assertion, options => { - if (result.FinalException is TimeoutRejectedException - && result.FinalException.InnerException != null - && result.FinalException.InnerException is not TaskCanceledException) - { - throw result.FinalException.InnerException; - } - - if (lastException != null) - { - throw lastException; - } - - throw result.FinalException; - } + options.Interval = TimeSpan.FromSeconds(1); + options.Timeout = timeout; + options.FailureMessage = $"({TestLocation}) Telemetry should be available in Application Insights but it wasn't within the given timeout"; + }); } } } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureFunctionsDockerTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureFunctionsDockerTests.cs index 4911dcb8..d55c5cc5 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureFunctionsDockerTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureFunctionsDockerTests.cs @@ -1,6 +1,5 @@ -using System.Net.Http; -using System.Threading.Tasks; -using Microsoft.Azure.ApplicationInsights.Query.Models; +using System.Threading.Tasks; +using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; using Xunit; using Xunit.Abstractions; @@ -10,8 +9,6 @@ namespace Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsight [Trait("Category", "Docker")] public class AzureFunctionsDockerTests : ApplicationInsightsSinkTests { - private static readonly HttpClient HttpClient = new HttpClient(); - /// /// Initializes a new instance of the class. /// @@ -23,13 +20,15 @@ public AzureFunctionsDockerTests(ITestOutputHelper outputWriter) [Fact] public async Task LogRequest_WithRequestsOperationName_SinksToApplicationInsights() { + TestLocation = TestLocation.Remote; + await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsRequestResult[] results = await client.GetRequestsAsync(); + RequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { - Assert.Equal("200", result.Request.ResultCode); - Assert.Equal("Timer", result.Request.Source); + Assert.Equal("200", result.ResultCode); + Assert.Equal("Timer", result.Source); Assert.Equal("Triggered", result.Operation.Name); }); }); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureKeyVaultDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureKeyVaultDependencyTests.cs index 49003997..1def20c1 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureKeyVaultDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureKeyVaultDependencyTests.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.Azure.ApplicationInsights.Query.Models; +using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; using Microsoft.Extensions.Logging; using Xunit; using Xunit.Abstractions; @@ -37,14 +37,14 @@ public async Task LogAzureKeyVaultDependency_SinksToApplicationInsights_ResultsI // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsDependencyResult[] results = await client.GetDependenciesAsync(); + DependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal(dependencyType, result.Dependency.Type); - Assert.Equal(dependencyId, result.Dependency.Id); - Assert.Equal(vaultUri, result.Dependency.Target); - Assert.Equal(secretName, result.Dependency.Data); - Assert.Equal(dependencyName, result.Dependency.Name); + Assert.Equal(dependencyType, result.Type); + Assert.Equal(dependencyId, result.Id); + Assert.Equal(vaultUri, result.Target); + Assert.Equal(secretName, result.Data); + Assert.Equal(dependencyName, result.Name); }); }); } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureSearchDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureSearchDependencyTests.cs index 822c905e..9ab7127c 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureSearchDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureSearchDependencyTests.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.Azure.ApplicationInsights.Query.Models; +using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; using Microsoft.Extensions.Logging; using Xunit; using Xunit.Abstractions; @@ -38,14 +38,14 @@ public async Task LogAzureSearchDependency_SinksToApplicationInsights_ResultsInA // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsDependencyResult[] results = await client.GetDependenciesAsync(); + DependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal(dependencyType, result.Dependency.Type); - Assert.Equal(dependencyId, result.Dependency.Id); - Assert.Equal(searchServiceName, result.Dependency.Target); - Assert.Equal(operationName, result.Dependency.Data); - Assert.Equal(dependencyName, result.Dependency.Name); + Assert.Equal(dependencyType, result.Type); + Assert.Equal(dependencyId, result.Id); + Assert.Equal(searchServiceName, result.Target); + Assert.Equal(operationName, result.Data); + Assert.Equal(dependencyName, result.Name); }); }); } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/BlobStorageDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/BlobStorageDependencyTests.cs index b4d12f89..abfa1ffe 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/BlobStorageDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/BlobStorageDependencyTests.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.Azure.ApplicationInsights.Query.Models; +using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; using Microsoft.Extensions.Logging; using Serilog; using Xunit; @@ -39,15 +39,15 @@ public async Task LogBlobStorageDependency_SinksToApplicationInsights_ResultsInB // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsDependencyResult[] results = await client.GetDependenciesAsync(); + DependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal(dependencyType, result.Dependency.Type); - Assert.Equal(accountName, result.Dependency.Target); - Assert.Equal(containerName, result.Dependency.Data); - Assert.Equal(componentName, result.Cloud.RoleName); - Assert.Equal(dependencyName, result.Dependency.Name); - Assert.Equal(dependencyId, result.Dependency.Id); + Assert.Equal(dependencyType, result.Type); + Assert.Equal(accountName, result.Target); + Assert.Equal(containerName, result.Data); + Assert.Equal(componentName, result.RoleName); + Assert.Equal(dependencyName, result.Name); + Assert.Equal(dependencyId, result.Id); }); }); } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CosmosSqlDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CosmosSqlDependencyTests.cs index f0e47ab5..16c11aa5 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CosmosSqlDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CosmosSqlDependencyTests.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.Azure.ApplicationInsights.Query.Models; +using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; using Microsoft.Extensions.Logging; using Serilog; using Xunit; @@ -40,14 +40,15 @@ public async Task LogCosmosSqlDependency_SinksToApplicationInsights_ResultsInCos // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsDependencyResult[] results = await client.GetDependenciesAsync(); + DependencyResult[] results = await client.GetDependenciesAsync(); + Assert.NotEmpty(results); AssertX.Any(results, result => { - Assert.Equal(dependencyType, result.Dependency.Type); - Assert.Equal(accountName, result.Dependency.Target); - Assert.Equal(dependencyName, result.Dependency.Data); - Assert.Equal(componentName, result.Cloud.RoleName); - Assert.Equal(dependencyName, result.Dependency.Name); + Assert.Equal(dependencyType, result.Type); + Assert.Equal(accountName, result.Target); + Assert.Equal(dependencyName, result.Data); + Assert.Equal(componentName, result.RoleName); + Assert.Equal(dependencyName, result.Name); }); }); } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomDependencyTests.cs index 04a5181a..8875a01c 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomDependencyTests.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.Azure.ApplicationInsights.Query.Models; +using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; using Microsoft.Extensions.Logging; using Xunit; using Xunit.Abstractions; @@ -33,12 +33,12 @@ public async Task LogDependency_SinksToApplicationInsights_ResultsInDependencyTe // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsDependencyResult[] results = await client.GetDependenciesAsync(); + DependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal(dependencyType, result.Dependency.Type); - Assert.Equal(dependencyData, result.Dependency.Data); - Assert.Equal(dependencyId, result.Dependency.Id); + Assert.Equal(dependencyType, result.Type); + Assert.Equal(dependencyData, result.Data); + Assert.Equal(dependencyId, result.Id); }); }); } @@ -56,6 +56,8 @@ public async Task LogDependency_SinksToApplicationInsights_ResultsInDependencyTe DateTimeOffset startTime = DateTimeOffset.Now; TimeSpan duration = BogusGenerator.Date.Timespan(); Dictionary telemetryContext = CreateTestTelemetryContext(); + + TestLocation = TestLocation.Remote; // Act Logger.LogDependency(dependencyType, dependencyData, isSuccessful, dependencyName, startTime, duration, dependencyId, telemetryContext); @@ -63,13 +65,15 @@ public async Task LogDependency_SinksToApplicationInsights_ResultsInDependencyTe // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsDependencyResult[] results = await client.GetDependenciesAsync(); + DependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal(dependencyType, result.Dependency.Type); - Assert.Equal(dependencyData, result.Dependency.Data); - Assert.Equal(dependencyName, result.Dependency.Name); - Assert.Equal(dependencyId, result.Dependency.Id); + Assert.Equal(dependencyType, result.Type); + Assert.Equal(dependencyData, result.Data); + Assert.Equal(dependencyName, result.Name); + Assert.Equal(dependencyId, result.Id); + Assert.Equal(isSuccessful, result.Success); + Assert.All(telemetryContext, item => Assert.Equal(item.Value.ToString(), Assert.Contains(item.Key, result.CustomDimensions))); }); }); } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomRequestTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomRequestTests.cs index 36ff9f76..bead5f7d 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomRequestTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomRequestTests.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.Azure.ApplicationInsights.Query.Models; +using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; using Microsoft.Extensions.Logging; using Serilog; using Xunit; @@ -36,16 +36,15 @@ public async Task LogCustomRequest_SinksToApplicationInsights_ResultsInCustomReq // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsRequestResult[] requests = await client.GetRequestsAsync(); + RequestResult[] requests = await client.GetRequestsAsync(); AssertX.Any(requests, result => { - Assert.Equal(operationName, result.Request.Name); - Assert.Contains(customRequestSource, result.Request.Source); - Assert.Empty(result.Request.Url); + Assert.Equal(operationName, result.Name); + Assert.Contains(customRequestSource, result.Source); + Assert.True(string.IsNullOrWhiteSpace(result.Url), "request URL should be blank"); Assert.Equal(operationName, result.Operation.Name); - Assert.True(bool.TryParse(result.Request.Success, out bool success)); - Assert.Equal(isSuccessful, success); - Assert.Equal(componentName, result.Cloud.RoleName); + Assert.Equal(isSuccessful, result.Success); + Assert.Equal(componentName, result.RoleName); }); }); } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsDependencyTests.cs index bd0e2ca8..54e07f60 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsDependencyTests.cs @@ -1,8 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Arcus.Observability.Correlation; -using Microsoft.Azure.ApplicationInsights.Query.Models; +using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; using Microsoft.Extensions.Logging; using Serilog; using Xunit; @@ -40,15 +39,15 @@ public async Task LogEventHubsDependency_SinksToApplicationInsights_ResultsInEve // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsDependencyResult[] results = await client.GetDependenciesAsync(); + DependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal(dependencyType, result.Dependency.Type); - Assert.Equal(eventHubName, result.Dependency.Target); - Assert.Equal(namespaceName, result.Dependency.Data); - Assert.Equal(componentName, result.Cloud.RoleName); - Assert.Equal(dependencyName, result.Dependency.Name); - Assert.Equal(dependencyId, result.Dependency.Id); + Assert.Equal(dependencyType, result.Type); + Assert.Equal(eventHubName, result.Target); + Assert.Equal(namespaceName, result.Data); + Assert.Equal(componentName, result.RoleName); + Assert.Equal(dependencyName, result.Name); + Assert.Equal(dependencyId, result.Id); }); }); } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsRequestTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsRequestTests.cs index 4a4fb1dc..f7dba9f5 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsRequestTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsRequestTests.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.Azure.ApplicationInsights.Query.Models; +using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; using Microsoft.Extensions.Logging; using Serilog; using Xunit; @@ -39,17 +39,16 @@ public async Task LogEventHubsRequest_SinksToApplicationInsights_ResultsInEventH // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsRequestResult[] requests = await client.GetRequestsAsync(); + RequestResult[] requests = await client.GetRequestsAsync(); AssertX.Any(requests, result => { - Assert.Equal(operationName, result.Request.Name); - Assert.Contains(eventHubsName, result.Request.Source); - Assert.Contains(eventHubsNamespace, result.Request.Source); - Assert.Empty(result.Request.Url); + Assert.Equal(operationName, result.Name); + Assert.Contains(eventHubsName, result.Source); + Assert.Contains(eventHubsNamespace, result.Source); + Assert.True(string.IsNullOrWhiteSpace(result.Url), "request URL should be blank"); Assert.Equal(operationName, result.Operation.Name); - Assert.True(bool.TryParse(result.Request.Success, out bool success)); - Assert.Equal(isSuccessful, success); - Assert.Equal(componentName, result.Cloud.RoleName); + Assert.Equal(isSuccessful, result.Success); + Assert.Equal(componentName, result.RoleName); AssertContainsCustomDimension(result.CustomDimensions, EventHubs.Namespace, eventHubsNamespace); AssertContainsCustomDimension(result.CustomDimensions, EventHubs.ConsumerGroup, eventHubsConsumerGroup); @@ -58,7 +57,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => }); } - private static void AssertContainsCustomDimension(EventsResultDataCustomDimensions customDimensions, string key, string expected) + private static void AssertContainsCustomDimension(IDictionary customDimensions, string key, string expected) { Assert.True(customDimensions.TryGetValue(key, out string actual), $"Cannot find {key} in custom dimensions: {String.Join(", ", customDimensions.Keys)}"); Assert.Equal(expected, actual); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventTests.cs index 403acda3..928d01ed 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventTests.cs @@ -5,7 +5,7 @@ using Arcus.Observability.Telemetry.Core; using Arcus.Observability.Telemetry.Serilog.Enrichers; using Arcus.Observability.Tests.Core; -using Microsoft.Azure.ApplicationInsights.Query.Models; +using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; using Microsoft.Extensions.Logging; using Serilog; using Xunit; @@ -32,8 +32,11 @@ public async Task LogCustomEvent_SinksToApplicationInsights_ResultsInEventTeleme // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsCustomEventResult[] results = await client.GetEventsAsync(); - Assert.Contains(results, result => result.CustomEvent.Name == eventName); + CustomEventResult[] results = await client.GetCustomEventsAsync(); + AssertX.Any(results, ev => + { + Assert.Equal(eventName, ev.Name); + }); }); } @@ -51,8 +54,12 @@ public async Task LogEventWithComponentName_SinksToApplicationInsights_ResultsIn // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsTraceResult[] results = await client.GetTracesAsync(); - Assert.Contains(results, result => result.Trace.Message == message && result.Cloud.RoleName == componentName); + TraceResult[] results = await client.GetTracesAsync(); + AssertX.Any(results, trace => + { + Assert.Equal(message, trace.Message); + Assert.Equal(componentName, trace.RoleName); + }); }); } @@ -62,6 +69,7 @@ public async Task LogCustomEventWithVersion_SinksToApplicationInsights_ResultsIn // Arrange var eventName = "Update version"; LoggerConfiguration.Enrich.WithVersion(); + TestLocation = TestLocation.Remote; // Act Logger.LogCustomEvent(eventName); @@ -69,12 +77,12 @@ public async Task LogCustomEventWithVersion_SinksToApplicationInsights_ResultsIn // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsCustomEventResult[] events = await client.GetEventsAsync(); - Assert.Contains(events, ev => + CustomEventResult[] events = await client.GetCustomEventsAsync(); + AssertX.Any(events, ev => { - return ev.CustomEvent.Name == eventName - && ev.CustomDimensions.TryGetValue(VersionEnricher.DefaultPropertyName, out string actualVersion) - && !String.IsNullOrWhiteSpace(actualVersion); + Assert.Equal(eventName, ev.Name); + string actualVersion = Assert.Contains(VersionEnricher.DefaultPropertyName, ev.CustomDimensions); + Assert.False(string.IsNullOrWhiteSpace(actualVersion), "enriched event version should not be blank"); }); }); } @@ -98,19 +106,16 @@ public async Task LogEventWithCorrelationInfo_SinksToApplicationInsights_Results // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsTraceResult[] traceEvents = await client.GetTracesAsync(); + TraceResult[] traceEvents = await client.GetTracesAsync(); AssertX.Any(traceEvents, trace => { - Assert.Equal(message, trace.Trace.Message); - Assert.True(trace.CustomDimensions.TryGetValue(ContextProperties.Correlation.OperationId, out string actualOperationId), "Requires a operation ID in the custom dimensions"); - Assert.True(trace.CustomDimensions.TryGetValue(ContextProperties.Correlation.TransactionId, out string actualTransactionId), "Requires a transaction ID in the custom dimensions"); - Assert.True(trace.CustomDimensions.TryGetValue(ContextProperties.Correlation.OperationParentId, out string actualOperationParentId), "Requires a operation parent ID in the custom dimensions"); - - Assert.Equal(operationId, actualOperationId); - Assert.Equal(transactionId, actualTransactionId); - Assert.Equal(operationParentId, actualOperationParentId); - Assert.Equal(transactionId, trace.Operation.Id); - Assert.Equal(operationId, trace.Operation.ParentId); + Assert.Equal(message, trace.Message); + Assert.Equal(operationId, Assert.Contains(ContextProperties.Correlation.OperationId, trace.CustomDimensions)); + Assert.Equal(transactionId, Assert.Contains(ContextProperties.Correlation.TransactionId, trace.CustomDimensions)); + Assert.Equal(operationParentId, Assert.Contains(ContextProperties.Correlation.OperationParentId, trace.CustomDimensions)); + + Assert.Equal(transactionId, trace.Operation.Id); + Assert.Equal(operationId, trace.Operation.ParentId); }); }); } @@ -137,16 +142,13 @@ public async Task LogEventWithKubernetesInfo_SinksToApplicationInsights_ResultsI // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsTraceResult[] traceEvents = await client.GetTracesAsync(); - Assert.Contains(traceEvents, trace => + TraceResult[] traceEvents = await client.GetTracesAsync(); + AssertX.Any(traceEvents, trace => { - return message == trace.Trace.Message - && trace.CustomDimensions.TryGetValue(ContextProperties.Kubernetes.NodeName, out string actualNodeName) - && nodeName == actualNodeName - && trace.CustomDimensions.TryGetValue(ContextProperties.Kubernetes.PodName, out string actualPodName) - && podName == actualPodName - && trace.CustomDimensions.TryGetValue(ContextProperties.Kubernetes.Namespace, out string actualNamespace) - && @namespace == actualNamespace; + Assert.Equal(message, trace.Message); + Assert.Equal(nodeName, Assert.Contains(ContextProperties.Kubernetes.NodeName, trace.CustomDimensions)); + Assert.Equal(podName, Assert.Contains(ContextProperties.Kubernetes.PodName, trace.CustomDimensions)); + Assert.Equal(@namespace, Assert.Contains(ContextProperties.Kubernetes.Namespace, trace.CustomDimensions)); }); }); } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ExceptionTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ExceptionTests.cs index 4d588b16..98d291dc 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ExceptionTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ExceptionTests.cs @@ -3,10 +3,9 @@ using System.Threading.Tasks; using Arcus.Observability.Correlation; using Arcus.Observability.Tests.Integration.Fixture; -using Microsoft.Azure.ApplicationInsights.Query.Models; +using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; using Microsoft.Extensions.Logging; using Serilog; -using Serilog.Events; using Xunit; using Xunit.Abstractions; @@ -32,10 +31,10 @@ public async Task LogException_SinksToApplicationInsights_ResultsInExceptionTele // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsExceptionResult[] results = await client.GetExceptionsAsync(); + ExceptionResult[] results = await client.GetExceptionsAsync(); AssertX.Any(results, result => { - Assert.Equal(exception.Message, result.Exception.OuterMessage); + Assert.Equal(exception.Message, result.Message); Assert.DoesNotContain($"Exception-{nameof(TestException.SpyProperty)}", result.CustomDimensions.Keys); }); }); @@ -56,12 +55,11 @@ public async Task LogException_SinksToApplicationInsightsWithIncludedProperties_ // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsExceptionResult[] results = await client.GetExceptionsAsync(); + ExceptionResult[] results = await client.GetExceptionsAsync(); AssertX.Any(results, result => { - Assert.Equal(exception.Message, result.Exception.OuterMessage); - Assert.True(result.CustomDimensions.TryGetValue($"Exception-{nameof(TestException.SpyProperty)}", out string actualProperty)); - Assert.Equal(expectedProperty, actualProperty); + Assert.Equal(exception.Message, result.Message); + Assert.Equal(expectedProperty, Assert.Contains($"Exception-{nameof(TestException.SpyProperty)}", result.CustomDimensions)); }); }); } @@ -76,6 +74,7 @@ public async Task LogExceptionWithCustomPropertyFormat_SinksToApplicationInsight string propertyFormat = "Exception.{0}"; ApplicationInsightsSinkOptions.Exception.IncludeProperties = true; ApplicationInsightsSinkOptions.Exception.PropertyFormat = propertyFormat; + TestLocation = TestLocation.Remote; // Act Logger.LogCritical(exception, exception.Message); @@ -83,12 +82,12 @@ public async Task LogExceptionWithCustomPropertyFormat_SinksToApplicationInsight // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsExceptionResult[] results = await client.GetExceptionsAsync(); + ExceptionResult[] results = await client.GetExceptionsAsync(); AssertX.Any(results, result => { string propertyName = String.Format(propertyFormat, nameof(TestException.SpyProperty)); - Assert.Equal(exception.Message, result.Exception.OuterMessage); + Assert.Equal(exception.Message, result.Message); Assert.True(result.CustomDimensions.TryGetValue(propertyName, out string actualProperty)); Assert.Equal(expectedProperty, actualProperty); }); @@ -110,11 +109,11 @@ public async Task LogExceptionWithComponentName_SinksToApplicationInsights_Resul // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsExceptionResult[] results = await client.GetExceptionsAsync(); + ExceptionResult[] results = await client.GetExceptionsAsync(); AssertX.Any(results, result => { - Assert.Equal(exception.Message, result.Exception.OuterMessage); - Assert.Equal(componentName, result.Cloud.RoleName); + Assert.Equal(exception.Message, result.Message); + Assert.Equal(componentName, result.RoleName); }); }); } @@ -140,10 +139,10 @@ public async Task LogExceptionWithCorrelationInfo_SinksToApplicationInsights_Res // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsExceptionResult[] results = await client.GetExceptionsAsync(); + ExceptionResult[] results = await client.GetExceptionsAsync(); AssertX.Any(results, result => { - Assert.Equal(exception.Message, result.Exception.OuterMessage); + Assert.Equal(exception.Message, result.Message); Assert.Equal(transactionId, result.Operation.Id); Assert.Equal(operationId, result.Operation.ParentId); }); @@ -167,10 +166,10 @@ public async Task LogWarning_SinksToApplicationInsights_ResultsInTraceTelemetry( // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsExceptionResult[] results = await client.GetExceptionsAsync(); + ExceptionResult[] results = await client.GetExceptionsAsync(); AssertX.Any(results, result => { - Assert.Equal(exception.Message, result.Exception.OuterMessage); + Assert.Equal(exception.Message, result.Message); Assert.True(result.CustomDimensions.TryGetValue(key, out string actual), "Should contain custom dimension property"); Assert.Equal(expected, actual); }); @@ -194,10 +193,10 @@ public async Task LogError_SinksToApplicationInsights_ResultsInTraceTelemetry() // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsExceptionResult[] results = await client.GetExceptionsAsync(); + ExceptionResult[] results = await client.GetExceptionsAsync(); AssertX.Any(results, result => { - Assert.Equal(exception.Message, result.Exception.OuterMessage); + Assert.Equal(exception.Message, result.Message); Assert.True(result.CustomDimensions.TryGetValue(key, out string actual), "Should contain custom dimension property"); Assert.Equal(expected, actual); }); @@ -221,10 +220,10 @@ public async Task LogCritical_SinksToApplicationInsights_ResultsInTraceTelemetry // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsExceptionResult[] results = await client.GetExceptionsAsync(); + ExceptionResult[] results = await client.GetExceptionsAsync(); AssertX.Any(results, result => { - Assert.Equal(exception.Message, result.Exception.OuterMessage); + Assert.Equal(exception.Message, result.Message); Assert.True(result.CustomDimensions.TryGetValue(key, out string actual), "Should contain custom dimension property"); Assert.Equal(expected, actual); }); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/ITelemetryQueryClient.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/ITelemetryQueryClient.cs new file mode 100644 index 00000000..8e85a178 --- /dev/null +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/ITelemetryQueryClient.cs @@ -0,0 +1,202 @@ +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Threading.Tasks; + +namespace Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture +{ + /// + /// Represents a client to query telemetry data from the Azure Application Insights instance. + /// + public interface ITelemetryQueryClient + { + /// + /// Gets the tracked traces from the Azure Application Insights instance. + /// + Task GetTracesAsync(); + + /// + /// Gets the tracked metrics from the Azure Application Insights instance. + /// + Task GetMetricsAsync(string metricName); + + /// + /// Gets the tracked custom events from the Azure Application Insights instance. + /// + Task GetCustomEventsAsync(); + + /// + /// Gets the tracked requests from the Azure Application Insights instance. + /// + Task GetRequestsAsync(); + + /// + /// Gets the tracked dependencies from the Azure Application Insights instance. + /// + Task GetDependenciesAsync(); + + /// + /// Gets the tracked exceptions from the Azure Application Insights instance. + /// + Task GetExceptionsAsync(); + } + + public class OperationResult + { + public OperationResult(string id, string parentId) + { + Id = id; + ParentId = parentId; + } + + public OperationResult(string id, string parentId, string name) + { + Id = id; + ParentId = parentId; + Name = name; + } + + public string Id { get; } + public string Name { get; } + public string ParentId { get; } + } + + public class TraceResult + { + public TraceResult(string message, string roleName, OperationResult operation, IDictionary customDimensions) + { + Message = message; + RoleName = roleName; + Operation = operation; + CustomDimensions = customDimensions; + } + + public string Message { get; } + public string RoleName { get; } + public OperationResult Operation { get; } + public IDictionary CustomDimensions { get; } + } + + public class CustomEventResult + { + /// + /// Initializes a new instance of the class. + /// + public CustomEventResult(string name, string roleName, IDictionary customDimensions) + { + Name = name; + RoleName = roleName; + CustomDimensions = new ReadOnlyDictionary(customDimensions); + } + + public string Name { get; } + public string RoleName { get; } + public IReadOnlyDictionary CustomDimensions { get; } + } + + public class MetricsResult + { + public MetricsResult(string name, double value, IDictionary customDimensions) + { + Name = name; + Value = value; + CustomDimensions = customDimensions; + } + + public string Name { get; } + public double Value { get; } + public IDictionary CustomDimensions { get; } + } + + public class RequestResult + { + public RequestResult( + string id, + string name, + string source, + string url, + bool success, + string resultCode, + string roleName, + OperationResult operation, + IDictionary customDimensions) + { + Id = id; + Name = name; + Source = source; + Url = url; + Success = success; + ResultCode = resultCode; + RoleName = roleName; + Operation = operation; + CustomDimensions = customDimensions; + } + + public string Id { get; } + public string Name { get; } + public string Source { get; } + public string Url { get; } + public bool Success { get; } + public string ResultCode { get; } + public string RoleName { get; } + public OperationResult Operation { get; } + public IDictionary CustomDimensions { get; } + } + + public class DependencyResult + { + public DependencyResult( + string id, + string type, + string target, + string data, + bool success, + int resultCode, + string name, + string roleName, + OperationResult operation, + IDictionary customDimensions) + { + Id = id; + Type = type; + Target = target; + Data = data; + Success = success; + ResultCode = resultCode; + Name = name; + RoleName = roleName; + Operation = operation; + CustomDimensions = customDimensions; + } + + public string Type { get; } + public string Id { get; } + public string Target { get; } + public string Data { get; } + public bool Success { get; } + public int ResultCode { get; } + public string Name { get; } + public string RoleName { get; } + public OperationResult Operation { get; } + public IDictionary CustomDimensions { get; } + } + + public class ExceptionResult + { + /// + /// Initializes a new instance of the class. + /// + public ExceptionResult(string message, OperationResult operation, string roleName, IDictionary customDimensions) + { + Message = message; + Operation = operation; + RoleName = roleName; + CustomDimensions = customDimensions; + } + + public string Message { get; } + public OperationResult Operation { get; } + public string RoleName { get; } + public IDictionary CustomDimensions { get; } + + } +} \ No newline at end of file diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/InMemoryApplicationInsightsTelemetryConverter.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/InMemoryApplicationInsightsTelemetryConverter.cs new file mode 100644 index 00000000..c2447740 --- /dev/null +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/InMemoryApplicationInsightsTelemetryConverter.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights.Configuration; +using Arcus.Observability.Telemetry.Serilog.Sinks.ApplicationInsights.Converters; +using Microsoft.ApplicationInsights.Channel; +using Microsoft.ApplicationInsights.DataContracts; +using Serilog.Events; +using Serilog.Sinks.ApplicationInsights.TelemetryConverters; + +namespace Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture +{ + public class InMemoryApplicationInsightsTelemetryConverter : TelemetryConverterBase + { + private readonly ConcurrentStack _telemetries = new(); + + public ApplicationInsightsSinkOptions Options { get; set; } + + public RequestTelemetry[] Requests => _telemetries.ToArray().OfType().ToArray(); + public DependencyTelemetry[] Dependencies => _telemetries.ToArray().OfType().ToArray(); + public EventTelemetry[] Events => _telemetries.ToArray().OfType().ToArray(); + public MetricTelemetry[] Metrics => _telemetries.ToArray().OfType().ToArray(); + public TraceTelemetry[] Traces => _telemetries.ToArray().OfType().ToArray(); + public ExceptionTelemetry[] Exceptions => _telemetries.ToArray().OfType().ToArray(); + + public override IEnumerable Convert(LogEvent logEvent, IFormatProvider formatProvider) + { + var converter = ApplicationInsightsTelemetryConverter.Create(Options); + + IEnumerable telemetries = converter.Convert(logEvent, formatProvider); + foreach (ITelemetry telemetry in telemetries) + { + _telemetries.Push(telemetry); + } + + return Enumerable.Empty(); + } + } +} diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/InMemoryTelemetryQueryClient.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/InMemoryTelemetryQueryClient.cs new file mode 100644 index 00000000..1ec60353 --- /dev/null +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/InMemoryTelemetryQueryClient.cs @@ -0,0 +1,118 @@ +using System.Linq; +using System.Threading.Tasks; +using GuardNet; + +namespace Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture +{ + /// + /// Represents an in-memory implementation to query telemetry data from the Azure Application Insights instance. + /// + public class InMemoryTelemetryQueryClient : ITelemetryQueryClient + { + private readonly InMemoryApplicationInsightsTelemetryConverter _telemetrySink; + + /// + /// Initializes a new instance of the class. + /// + public InMemoryTelemetryQueryClient(InMemoryApplicationInsightsTelemetryConverter telemetrySink) + { + Guard.NotNull(telemetrySink, nameof(telemetrySink)); + _telemetrySink = telemetrySink; + } + + /// + /// Gets the tracked traces from the Azure Application Insights instance. + /// + public Task GetTracesAsync() + { + return Task.FromResult(_telemetrySink.Traces.Select(t => + { + return new TraceResult( + t.Message, + t.Context.Cloud.RoleName, + new OperationResult( + t.Context.Operation.Id, + t.Context.Operation.ParentId, + t.Context.Operation.Name), + t.Properties); + }).ToArray()); + } + + /// + /// Gets the tracked metrics from the Azure Application Insights instance. + /// + public Task GetMetricsAsync(string metricName) + { + return Task.FromResult(_telemetrySink.Metrics.Where(m => m.Name == metricName).Select(m => new MetricsResult(m.Name, m.Sum, m.Properties)).ToArray()); + } + + /// + /// Gets the tracked custom events from the Azure Application Insights instance. + /// + public Task GetCustomEventsAsync() + { + return Task.FromResult(_telemetrySink.Events.Select(e => new CustomEventResult(e.Name, e.Context.Cloud.RoleName, e.Properties)).ToArray()); + } + + /// + /// Gets the tracked requests from the Azure Application Insights instance. + /// + public Task GetRequestsAsync() + { + return Task.FromResult(_telemetrySink.Requests.Select(r => + { + var operation = new OperationResult(r.Context.Operation.Id, r.Context.Operation.ParentId, r.Context.Operation.Name); + return new RequestResult( + r.Id, + r.Name, + r.Source, + r.Url?.ToString(), + r.Success ?? false, + r.ResponseCode, + r.Context.Cloud.RoleName, + operation, + r.Properties); + }).ToArray()); + } + + /// + /// Gets the tracked dependencies from the Azure Application Insights instance. + /// + public Task GetDependenciesAsync() + { + return Task.FromResult(_telemetrySink.Dependencies.Select(d => + { + var operation = new OperationResult(d.Context.Operation.Id, d.Context.Operation.ParentId, d.Context.Operation.Name); + return new DependencyResult(d.Id, + d.Type, + d.Target, + d.Data, + d.Success ?? false, + string.IsNullOrWhiteSpace(d.ResultCode) ? 0 : int.Parse(d.ResultCode), + d.Name, + d.Context.Cloud.RoleName, + operation, + d.Properties); + }).ToArray()); + } + + /// + /// Gets the tracked exceptions from the Azure Application Insights instance. + /// + public Task GetExceptionsAsync() + { + return Task.FromResult(_telemetrySink.Exceptions.Select(e => + { + var operation = new OperationResult(e.Context.Operation.Id, + e.Context.Operation.ParentId, + e.Context.Operation.Name); + + return new ExceptionResult( + e.Exception.Message, + operation, + e.Context.Cloud.RoleName, + e.Properties); + }).ToArray()); + } + } +} \ No newline at end of file diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpDependencyTests.cs index d85c046e..82ed7ece 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpDependencyTests.cs @@ -4,8 +4,8 @@ using System.Net.Http; using System.Threading.Tasks; using Arcus.Observability.Correlation; +using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; using Microsoft.AspNetCore.Http; -using Microsoft.Azure.ApplicationInsights.Query.Models; using Microsoft.Extensions.Logging; using Moq; using Serilog; @@ -50,14 +50,14 @@ public async Task LogHttpDependencyWithRequestMessageWithCorrelation_SinksToAppl var requestUri = new Uri(requestUrl); await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsDependencyResult[] results = await client.GetDependenciesAsync(); + DependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal(DependencyType, result.Dependency.Type); - Assert.Equal(requestUri.Host, result.Dependency.Target); - Assert.Equal($"{httpMethod} {requestUri.AbsolutePath}", result.Dependency.Name); - Assert.Equal(dependencyId, result.Dependency.Id); - Assert.Equal(componentName, result.Cloud.RoleName); + Assert.Equal(DependencyType, result.Type, StringComparer.OrdinalIgnoreCase); + Assert.Equal(requestUri.Host, result.Target); + Assert.Equal($"{httpMethod} {requestUri.AbsolutePath}", result.Name); + Assert.Equal(dependencyId, result.Id); + Assert.Equal(componentName, result.RoleName); Assert.Equal(correlation.OperationId, result.Operation.ParentId); Assert.Equal(correlation.TransactionId, result.Operation.Id); @@ -89,14 +89,14 @@ public async Task LogHttpDependencyWithRequestMessage_SinksToApplicationInsights var requestUri = new Uri(requestUrl); await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsDependencyResult[] results = await client.GetDependenciesAsync(); + DependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal(DependencyType, result.Dependency.Type); - Assert.Equal(requestUri.Host, result.Dependency.Target); - Assert.Equal($"{httpMethod} {requestUri.AbsolutePath}", result.Dependency.Name); - Assert.Equal(dependencyId, result.Dependency.Id); - Assert.Equal(componentName, result.Cloud.RoleName); + Assert.Equal(DependencyType, result.Type, StringComparer.OrdinalIgnoreCase); + Assert.Equal(requestUri.Host, result.Target); + Assert.Equal($"{httpMethod} {requestUri.AbsolutePath}", result.Name); + Assert.Equal(dependencyId, result.Id); + Assert.Equal(componentName, result.RoleName); }); }); } @@ -129,13 +129,13 @@ public async Task LogHttpDependencyWithRequest_SinksToApplicationInsights_Result // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsDependencyResult[] results = await client.GetDependenciesAsync(); + DependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal(DependencyType, result.Dependency.Type); - Assert.Equal(request.Host.Host, result.Dependency.Target); - Assert.Equal($"{httpMethod} {request.Path}", result.Dependency.Name); - Assert.Equal(dependencyId, result.Dependency.Id); + Assert.Equal(DependencyType, result.Type, StringComparer.OrdinalIgnoreCase); + Assert.Equal(request.Host.Host, result.Target); + Assert.Equal($"{httpMethod} {request.Path}", result.Name); + Assert.Equal(dependencyId, result.Id); }); }); } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpRequestDataTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpRequestDataTests.cs index 231ea95f..1088296f 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpRequestDataTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpRequestDataTests.cs @@ -4,7 +4,7 @@ using System.Net.Http; using System.Threading.Tasks; using Arcus.Observability.Correlation; -using Microsoft.Azure.ApplicationInsights.Query.Models; +using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker.Http; using Microsoft.Extensions.Logging; @@ -46,14 +46,14 @@ public async Task LogRequest_SinksToApplicationInsightsWithCorrelation_ResultsIn // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsRequestResult[] results = await client.GetRequestsAsync(); + RequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { - Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Request.Url); - Assert.Equal(((int) statusCode).ToString(), result.Request.ResultCode); + Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Url); + Assert.Equal(((int) statusCode).ToString(), result.ResultCode); Assert.Equal($"{httpMethod.Method} {operationName}", result.Operation.Name); - Assert.Equal(correlation.OperationId, result.Request.Id); + Assert.Equal(correlation.OperationId, result.Id); Assert.Equal(correlation.TransactionId, result.Operation.Id); Assert.Equal(correlation.OperationParentId, result.Operation.ParentId); }); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/IoTHubTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/IoTHubTests.cs index 853a6e96..663a2066 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/IoTHubTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/IoTHubTests.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.Azure.ApplicationInsights.Query.Models; +using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; using Microsoft.Extensions.Logging; using Serilog; using Xunit; @@ -37,14 +37,14 @@ public async Task LogIoTHubDependency_SinksToApplicationInsights_ResultsIEventHu // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsDependencyResult[] results = await client.GetDependenciesAsync(); + DependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal("Azure IoT Hub", result.Dependency.Type); - Assert.Equal(iotHubName, result.Dependency.Target); - Assert.Equal(componentName, result.Cloud.RoleName); - Assert.Equal(dependencyName, result.Dependency.Name); - Assert.Equal(dependencyId, result.Dependency.Id); + Assert.Equal("Azure IoT Hub", result.Type); + Assert.Equal(iotHubName, result.Target); + Assert.Equal(componentName, result.RoleName); + Assert.Equal(dependencyName, result.Name); + Assert.Equal(dependencyId, result.Id); }); }); } @@ -72,14 +72,14 @@ public async Task LogIoTHubDependencyWithConnectionString_SinksToApplicationInsi // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsDependencyResult[] results = await client.GetDependenciesAsync(); + DependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal("Azure IoT Hub", result.Dependency.Type); - Assert.Equal(hostName, result.Dependency.Target); - Assert.Equal(componentName, result.Cloud.RoleName); - Assert.Equal(dependencyName, result.Dependency.Name); - Assert.Equal(dependencyId, result.Dependency.Id); + Assert.Equal("Azure IoT Hub", result.Type); + Assert.Equal(hostName, result.Target); + Assert.Equal(componentName, result.RoleName); + Assert.Equal(dependencyName, result.Name); + Assert.Equal(dependencyId, result.Id); }); }); } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/MetricTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/MetricTests.cs index b79c4d46..d2641ddd 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/MetricTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/MetricTests.cs @@ -1,7 +1,7 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.Azure.ApplicationInsights.Query.Models; +using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; +using Azure.Monitor.Query.Models; using Microsoft.Extensions.Logging; using Xunit; using Xunit.Abstractions; @@ -15,7 +15,7 @@ public MetricTests(ITestOutputHelper outputWriter) : base(outputWriter) } [Fact] - public async Task LogMetric_SinksToApplicationInsights_ResultsInMetricTelemetry() + public async Task LogCustomMetric_SinksToApplicationInsights_ResultsInMetricTelemetry() { // Arrange string metricName = "threshold"; @@ -23,40 +23,28 @@ public async Task LogMetric_SinksToApplicationInsights_ResultsInMetricTelemetry( Dictionary telemetryContext = CreateTestTelemetryContext(); // Act - Logger.LogMetric(metricName, metricValue, telemetryContext); + Logger.LogCustomMetric(metricName, metricValue, telemetryContext); // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - var bodySchema = new MetricsPostBodySchema( - id: Guid.NewGuid().ToString(), - parameters: new MetricsPostBodySchemaParameters("customMetrics/" + metricName)); - - MetricsResultsItem[] results = await client.GetMetricsAsync(bodySchema); - Assert.NotEmpty(results); + MetricsResult[] results = await client.GetMetricsAsync(metricName); + AssertX.Any(results, metric => + { + Assert.Equal(metricName, metric.Name); + Assert.Equal(metricValue, metric.Value); + + ContainsTelemetryContext(telemetryContext, metric); + }); }); } - [Fact] - public async Task LogCustomMetric_SinksToApplicationInsights_ResultsInMetricTelemetry() + private static void ContainsTelemetryContext(Dictionary telemetryContext, MetricsResult metric) { - // Arrange - string metricName = "threshold"; - double metricValue = 0.25; - Dictionary telemetryContext = CreateTestTelemetryContext(); - - // Act - Logger.LogCustomMetric(metricName, metricValue, telemetryContext); - - // Assert - await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => + Assert.All(telemetryContext, item => { - var bodySchema = new MetricsPostBodySchema( - id: Guid.NewGuid().ToString(), - parameters: new MetricsPostBodySchemaParameters("customMetrics/" + metricName)); - - MetricsResultsItem[] results = await client.GetMetricsAsync(bodySchema); - Assert.NotEmpty(results); + string actual = Assert.Contains(item.Key, metric.CustomDimensions); + Assert.Equal(item.Value.ToString(), actual); }); } } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/RequestTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/RequestTests.cs index 6f4b153e..10eaa48c 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/RequestTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/RequestTests.cs @@ -5,8 +5,8 @@ using System.Threading.Tasks; using Arcus.Observability.Correlation; using Arcus.Observability.Telemetry.Core; +using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; using Microsoft.AspNetCore.Http; -using Microsoft.Azure.ApplicationInsights.Query.Models; using Microsoft.Extensions.Logging; using Moq; using Serilog; @@ -47,14 +47,14 @@ public async Task LogRequest_SinksToApplicationInsightsWithCorrelation_ResultsIn // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsRequestResult[] results = await client.GetRequestsAsync(); + RequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { - Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Request.Url); - Assert.Equal(((int) statusCode).ToString(), result.Request.ResultCode); + Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Url); + Assert.Equal(((int) statusCode).ToString(), result.ResultCode); Assert.Equal($"{httpMethod.Method} {operationName}", result.Operation.Name); - Assert.Equal(correlation.OperationId, result.Request.Id); + Assert.Equal(correlation.OperationId, result.Id); Assert.Equal(correlation.TransactionId, result.Operation.Id); Assert.Equal(correlation.OperationParentId, result.Operation.ParentId); }); @@ -82,11 +82,11 @@ public async Task LogRequest_SinksToApplicationInsightsWithoutCustomId_ResultsIn // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsRequestResult[] results = await client.GetRequestsAsync(); + RequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { - Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Request.Url); - Assert.Equal(((int) statusCode).ToString(), result.Request.ResultCode); + Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Url); + Assert.Equal(((int) statusCode).ToString(), result.ResultCode); Assert.Equal($"{httpMethod.Method} {operationName}", result.Operation.Name); }); }); @@ -117,11 +117,11 @@ public async Task LogRequest_SinksToApplicationInsightsWithResponseWithCustomId_ // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsRequestResult[] results = await client.GetRequestsAsync(); + RequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { - Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Request.Url); - Assert.Equal(((int)statusCode).ToString(), result.Request.ResultCode); + Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Url); + Assert.Equal(((int)statusCode).ToString(), result.ResultCode); Assert.StartsWith(httpMethod.Method, result.Operation.Name); }); }); @@ -145,18 +145,20 @@ public async Task LogRequest_SinksToApplicationInsightsWithResponseStatusCodeWit DateTimeOffset startTime = DateTimeOffset.Now; Dictionary telemetryContext = CreateTestTelemetryContext(); + TestLocation = TestLocation.Remote; + // Act Logger.LogRequest(request, (int) statusCode, operationName, startTime, duration, telemetryContext); // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsRequestResult[] results = await client.GetRequestsAsync(); + RequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { - Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Request.Url); - Assert.Equal(((int)statusCode).ToString(), result.Request.ResultCode); - Assert.Equal(requestId, result.Request.Id); + Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Url); + Assert.Equal(((int)statusCode).ToString(), result.ResultCode); + Assert.Equal(requestId, result.Id); }); }); } @@ -186,14 +188,14 @@ public async Task LogRequestMessage_SinksToApplicationInsightsWithResponseWithCu // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsRequestResult[] results = await client.GetRequestsAsync(); + RequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { - Assert.Equal(requestUri.ToString(), result.Request.Url); - Assert.Equal(((int)statusCode).ToString(), result.Request.ResultCode); - Assert.Equal(requestId, result.Request.Id); + Assert.Equal(requestUri.ToString(), result.Url); + Assert.Equal(((int)statusCode).ToString(), result.ResultCode); + Assert.Equal(requestId, result.Id); Assert.Equal($"{httpMethod.Method} {operationName}", result.Operation.Name); - Assert.Equal(requestId, result.Request.Id); + Assert.Equal(requestId, result.Id); }); }); } @@ -220,11 +222,11 @@ public async Task LogRequestMessage_SinksToApplicationInsightsWithResponseWithou // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsRequestResult[] results = await client.GetRequestsAsync(); + RequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { - Assert.Equal(requestUri.ToString(), result.Request.Url); - Assert.Equal(((int)statusCode).ToString(), result.Request.ResultCode); + Assert.Equal(requestUri.ToString(), result.Url); + Assert.Equal(((int)statusCode).ToString(), result.ResultCode); Assert.Equal($"{httpMethod.Method} {operationName}", result.Operation.Name); }); }); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusDependencyTests.cs index 8db04714..def4d7ae 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusDependencyTests.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; using Arcus.Observability.Correlation; using Arcus.Observability.Telemetry.Core; -using Microsoft.Azure.ApplicationInsights.Query.Models; +using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; using Microsoft.Extensions.Logging; using Serilog; using Xunit; @@ -44,13 +44,13 @@ public async Task LogServiceBusDependencyWithCorrelation_SinksToApplicationInsig // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsDependencyResult[] results = await client.GetDependenciesAsync(); + DependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal(dependencyType, result.Dependency.Type); - Assert.Contains(entityName, result.Dependency.Target); - Assert.Equal(dependencyName, result.Dependency.Name); - Assert.Equal(dependencyId, result.Dependency.Id); + Assert.Equal(dependencyType, result.Type); + Assert.Contains(entityName, result.Target); + Assert.Equal(dependencyName, result.Name); + Assert.Equal(dependencyId, result.Id); AssertContainsCustomDimension(result.CustomDimensions, ContextProperties.DependencyTracking.ServiceBus.EntityType, entityType.ToString()); AssertContainsCustomDimension(result.CustomDimensions, ContextProperties.DependencyTracking.ServiceBus.Endpoint, namespaceEndpoint); @@ -83,13 +83,13 @@ public async Task LogServiceBusDependency_SinksToApplicationInsights_ResultsInSe // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsDependencyResult[] results = await client.GetDependenciesAsync(); + DependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal(dependencyType, result.Dependency.Type); - Assert.Contains(entityName, result.Dependency.Target); - Assert.Equal(dependencyName, result.Dependency.Name); - Assert.Equal(dependencyId, result.Dependency.Id); + Assert.Equal(dependencyType, result.Type); + Assert.Contains(entityName, result.Target); + Assert.Equal(dependencyName, result.Name); + Assert.Equal(dependencyId, result.Id); AssertContainsCustomDimension(result.CustomDimensions, ContextProperties.DependencyTracking.ServiceBus.EntityType, entityType.ToString()); AssertContainsCustomDimension(result.CustomDimensions, ContextProperties.DependencyTracking.ServiceBus.Endpoint, namespaceEndpoint); @@ -97,7 +97,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => }); } - private static void AssertContainsCustomDimension(EventsResultDataCustomDimensions customDimensions, string key, string expected) + private static void AssertContainsCustomDimension(IDictionary customDimensions, string key, string expected) { Assert.True(customDimensions.TryGetValue(key, out string actual), $"Cannot find {key} in custom dimensions: {String.Join(", ", customDimensions.Keys)}"); Assert.Equal(expected, actual); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusRequestTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusRequestTests.cs index 453b8053..fcf1091a 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusRequestTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusRequestTests.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; using Arcus.Observability.Correlation; using Arcus.Observability.Telemetry.Core; -using Microsoft.Azure.ApplicationInsights.Query.Models; +using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; using Microsoft.Extensions.Logging; using Serilog; using Xunit; @@ -40,22 +40,21 @@ public async Task LogServiceBusQueueRequestWithCorrelation_SinksToApplicationIns // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsRequestResult[] results = await client.GetRequestsAsync(); + RequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { - Assert.Equal(operationName, result.Request.Name); - Assert.Contains(queueName, result.Request.Source); - Assert.Contains(serviceBusNamespace, result.Request.Source); - Assert.Empty(result.Request.Url); + Assert.Equal(operationName, result.Name); + Assert.Contains(queueName, result.Source); + Assert.Contains(serviceBusNamespace, result.Source); + Assert.True(string.IsNullOrWhiteSpace(result.Url), "request URL should be blank"); Assert.Equal(operationName, result.Operation.Name); - Assert.True(bool.TryParse(result.Request.Success, out bool success)); - Assert.Equal(isSuccessful, success); + Assert.Equal(isSuccessful, result.Success); AssertContainsCustomDimension(result.CustomDimensions, ContextProperties.RequestTracking.ServiceBus.EntityType, ServiceBusEntityType.Queue.ToString()); AssertContainsCustomDimension(result.CustomDimensions, ContextProperties.RequestTracking.ServiceBus.EntityName, queueName); AssertContainsCustomDimension(result.CustomDimensions, ContextProperties.RequestTracking.ServiceBus.Endpoint, serviceBusNamespace); - Assert.Equal(correlation.OperationId, result.Request.Id); + Assert.Equal(correlation.OperationId, result.Id); Assert.Equal(correlation.TransactionId, result.Operation.Id); Assert.Equal(correlation.OperationParentId, result.Operation.ParentId); }); @@ -80,16 +79,15 @@ public async Task LogServiceBusQueueRequest_SinksToApplicationInsights_ResultsIn // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsRequestResult[] results = await client.GetRequestsAsync(); + RequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { - Assert.Equal(operationName, result.Request.Name); - Assert.Contains(queueName, result.Request.Source); - Assert.Contains(serviceBusNamespace, result.Request.Source); - Assert.Empty(result.Request.Url); + Assert.Equal(operationName, result.Name); + Assert.Contains(queueName, result.Source); + Assert.Contains(serviceBusNamespace, result.Source); + Assert.True(string.IsNullOrWhiteSpace(result.Url), "request URL should be blank"); Assert.Equal(operationName, result.Operation.Name); - Assert.True(bool.TryParse(result.Request.Success, out bool success)); - Assert.Equal(isSuccessful, success); + Assert.Equal(isSuccessful, result.Success); AssertContainsCustomDimension(result.CustomDimensions, ContextProperties.RequestTracking.ServiceBus.EntityType, ServiceBusEntityType.Queue.ToString()); AssertContainsCustomDimension(result.CustomDimensions, ContextProperties.RequestTracking.ServiceBus.EntityName, queueName); @@ -118,17 +116,16 @@ public async Task LogServiceBusTopicRequestWithSuffix_SinksToApplicationInsights // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsRequestResult[] results = await client.GetRequestsAsync(); + RequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { - Assert.Equal(operationName, result.Request.Name); - Assert.Contains(topicName, result.Request.Source); - Assert.Contains(serviceBusNamespace, result.Request.Source); - Assert.Contains(serviceBusNamespaceSuffix, result.Request.Source); - Assert.Empty(result.Request.Url); + Assert.Equal(operationName, result.Name); + Assert.Contains(topicName, result.Source); + Assert.Contains(serviceBusNamespace, result.Source); + Assert.Contains(serviceBusNamespaceSuffix, result.Source); + Assert.True(string.IsNullOrWhiteSpace(result.Url), "request URL should be blank"); Assert.Equal(operationName, result.Operation.Name); - Assert.True(bool.TryParse(result.Request.Success, out bool success)); - Assert.Equal(isSuccessful, success); + Assert.Equal(isSuccessful, result.Success); AssertContainsCustomDimension(result.CustomDimensions, ContextProperties.RequestTracking.ServiceBus.EntityType, ServiceBusEntityType.Topic.ToString()); AssertContainsCustomDimension(result.CustomDimensions, ContextProperties.RequestTracking.ServiceBus.EntityName, topicName); @@ -151,22 +148,23 @@ public async Task LogServiceBusRequest_SinksToApplicationInsights_ResultsInReque var entityType = BogusGenerator.PickRandom(); Dictionary telemetryContext = CreateTestTelemetryContext(); + TestLocation = TestLocation.Remote; + // Act Logger.LogServiceBusRequest(serviceBusNamespace, entityName, operationName, isSuccessful, duration, startTime, entityType, telemetryContext); // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsRequestResult[] results = await client.GetRequestsAsync(); + RequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { - Assert.Equal(operationName, result.Request.Name); - Assert.Contains(entityName, result.Request.Source); - Assert.Contains(serviceBusNamespace, result.Request.Source); - Assert.Empty(result.Request.Url); + Assert.Equal(operationName, result.Name); + Assert.Contains(entityName, result.Source); + Assert.Contains(serviceBusNamespace, result.Source); + Assert.True(string.IsNullOrWhiteSpace(result.Url), "request URL should be blank"); Assert.Equal(operationName, result.Operation.Name); - Assert.True(bool.TryParse(result.Request.Success, out bool success)); - Assert.Equal(isSuccessful, success); + Assert.Equal(isSuccessful, result.Success); AssertContainsCustomDimension(result.CustomDimensions, ContextProperties.RequestTracking.ServiceBus.EntityType, entityType.ToString()); AssertContainsCustomDimension(result.CustomDimensions, ContextProperties.RequestTracking.ServiceBus.EntityName, entityName); @@ -175,10 +173,9 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => }); } - private static void AssertContainsCustomDimension(EventsResultDataCustomDimensions customDimensions, string key, string expected) + private static void AssertContainsCustomDimension(IDictionary customDimensions, string key, string expected) { - Assert.True(customDimensions.TryGetValue(key, out string actual), $"Cannot find {key} in custom dimensions: {String.Join(", ", customDimensions.Keys)}"); - Assert.Equal(expected, actual); + Assert.Equal(expected, Assert.Contains(key, customDimensions)); } } } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/SqlDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/SqlDependencyTests.cs index a834b242..f1b600f3 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/SqlDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/SqlDependencyTests.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.Azure.ApplicationInsights.Query.Models; +using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; using Microsoft.Extensions.Logging; using Xunit; using Xunit.Abstractions; @@ -37,14 +37,14 @@ public async Task LogSqlDependency_SinksToApplicationInsights_ResultsInSqlDepend // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsDependencyResult[] results = await client.GetDependenciesAsync(); + DependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal(dependencyType, result.Dependency.Type); - Assert.Equal(serverName, result.Dependency.Target); - Assert.Contains($"{dependencyType}: {databaseName}", result.Dependency.Name); - Assert.Contains(operationName, result.Dependency.Name); - Assert.Equal(dependencyId, result.Dependency.Id); + Assert.Equal(dependencyType, result.Type, StringComparer.OrdinalIgnoreCase); + Assert.Equal(serverName, result.Target); + Assert.Contains(databaseName, result.Name); + Assert.Contains(operationName, result.Name); + Assert.Equal(dependencyId, result.Id); }); }); } @@ -73,14 +73,14 @@ public async Task LogSqlDependencyWithConnectionString_SinksToApplicationInsight // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsDependencyResult[] results = await client.GetDependenciesAsync(); + DependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal(dependencyType, result.Dependency.Type); - Assert.Equal(serverName, result.Dependency.Target); - Assert.Contains($"{dependencyType}: {databaseName}", result.Dependency.Name); - Assert.Contains(operationName, result.Dependency.Name); - Assert.Equal(dependencyId, result.Dependency.Id); + Assert.Equal(dependencyType, result.Type, StringComparer.OrdinalIgnoreCase); + Assert.Equal(serverName, result.Target); + Assert.Contains(databaseName, result.Name); + Assert.Contains(operationName, result.Name); + Assert.Equal(dependencyId, result.Id); }); }); } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TableStorageDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TableStorageDependencyTests.cs index eb1c2e79..b2fb5c55 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TableStorageDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TableStorageDependencyTests.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.Azure.ApplicationInsights.Query.Models; +using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; using Microsoft.Extensions.Logging; using Serilog; using Xunit; @@ -39,15 +39,15 @@ public async Task LogTableStorageDependency_SinksToApplicationInsights_ResultsIn // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsDependencyResult[] results = await client.GetDependenciesAsync(); + DependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal(dependencyType, result.Dependency.Type); - Assert.Equal(accountName, result.Dependency.Target); - Assert.Equal(tableName, result.Dependency.Data); - Assert.Equal(componentName, result.Cloud.RoleName); - Assert.Equal(dependencyName, result.Dependency.Name); - Assert.Equal(dependencyId, result.Dependency.Id); + Assert.Equal(dependencyType, result.Type); + Assert.Equal(accountName, result.Target); + Assert.Equal(tableName, result.Data); + Assert.Equal(componentName, result.RoleName); + Assert.Equal(dependencyName, result.Name); + Assert.Equal(dependencyId, result.Id); }); }); } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TraceTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TraceTests.cs index 6b407cc8..ac8a18ae 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TraceTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TraceTests.cs @@ -1,8 +1,7 @@ using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.Azure.ApplicationInsights.Query.Models; +using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; using Microsoft.Extensions.Logging; -using Serilog.Events; using Xunit; using Xunit.Abstractions; @@ -26,10 +25,10 @@ public async Task LogInformationWithoutContext_SinksToApplicationInsights_Result // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsTraceResult[] results = await client.GetTracesAsync(); + TraceResult[] results = await client.GetTracesAsync(); AssertX.Any(results, result => { - Assert.Contains(message, result.Trace.Message); + Assert.Contains(message, result.Message); }); }); } @@ -50,10 +49,10 @@ public async Task LogInformation_SinksToApplicationInsights_ResultsInTraceTeleme // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsTraceResult[] results = await client.GetTracesAsync(); + TraceResult[] results = await client.GetTracesAsync(); AssertX.Any(results, result => { - Assert.Contains(message, result.Trace.Message); + Assert.Contains(message, result.Message); Assert.True(result.CustomDimensions.TryGetValue(key, out string actual), "Should contain custom dimension property"); Assert.Equal(expected, actual); }); @@ -76,10 +75,10 @@ public async Task LogTrace_SinksToApplicationInsights_ResultsInTraceTelemetry() // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsTraceResult[] results = await client.GetTracesAsync(); + TraceResult[] results = await client.GetTracesAsync(); AssertX.Any(results, result => { - Assert.Contains(message, result.Trace.Message); + Assert.Contains(message, result.Message); Assert.True(result.CustomDimensions.TryGetValue(key, out string actual), "Should contain custom dimension property"); Assert.Equal(expected, actual); }); @@ -102,10 +101,10 @@ public async Task LogDebug_SinksToApplicationInsights_ResultsInTraceTelemetry() // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - EventsTraceResult[] results = await client.GetTracesAsync(); + TraceResult[] results = await client.GetTracesAsync(); AssertX.Any(results, result => { - Assert.Contains(message, result.Trace.Message); + Assert.Contains(message, result.Message); Assert.True(result.CustomDimensions.TryGetValue(key, out string actual), "Should contain custom dimension property"); Assert.Equal(expected, actual); }); diff --git a/src/Arcus.Observability.Tests.Integration/appsettings.json b/src/Arcus.Observability.Tests.Integration/appsettings.json index 9713ebcd..4417cf55 100644 --- a/src/Arcus.Observability.Tests.Integration/appsettings.json +++ b/src/Arcus.Observability.Tests.Integration/appsettings.json @@ -1,10 +1,18 @@ { + "Arcus": { + "TenantId": "#{Arcus.Observability.TenantId}#", + "ServicePrincipal": { + "ClientId": "#{Arcus.Observability.ServicePrincipal.ClientId}#", + "ClientSecret": "#{Arcus.Observability.ServicePrincipal.ClientSecret}#" + } + }, "ApplicationInsights": { - "InstrumentationKey": "#{ApplicationInsights_InstrumentationKey}#", - "ApiKey": "#{ApplicationInsights_ApiKey}#", - "ApplicationId": "#{ApplicationInsights_ApplicationId}#" + "InstrumentationKey": "#{Arcus.ApplicationInsights.InstrumentationKey}#", + "LogAnalyticsWorkspace": { + "ResourceId": "#{Arcus.ApplicationInsights.LogAnalyticsWorkspace.ResourceId}#", + } }, "AzureFunctions": { - "HttpPort": "#{AzureFunctions.HttpPort}#" - } + "HttpPort": "#{AzureFunctions.HttpPort}#" + } } \ No newline at end of file diff --git a/src/Arcus.Observability.Tests.Unit/Arcus.Observability.Tests.Unit.csproj b/src/Arcus.Observability.Tests.Unit/Arcus.Observability.Tests.Unit.csproj index d6f32fc5..9bef7fd2 100644 --- a/src/Arcus.Observability.Tests.Unit/Arcus.Observability.Tests.Unit.csproj +++ b/src/Arcus.Observability.Tests.Unit/Arcus.Observability.Tests.Unit.csproj @@ -18,7 +18,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + From c7321af92a43de919f7fd773b30eefd01b7c1411 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 30 Jul 2024 18:38:43 +0200 Subject: [PATCH 60/86] pr-fix: use guid for role definition --- build/templates/deploy-test-resources.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/templates/deploy-test-resources.bicep b/build/templates/deploy-test-resources.bicep index 77f6fdcb..d9c0986c 100644 --- a/build/templates/deploy-test-resources.bicep +++ b/build/templates/deploy-test-resources.bicep @@ -55,7 +55,7 @@ module component 'br/public:avm/res/insights/component:0.3.0' = { roleAssignments: [ { principalId: servicePrincipal_objectId - roleDefinitionIdOrName: 'Log Analytics Contributor' + roleDefinitionIdOrName: '73c42c96-874c-492b-b04d-ab87d138a893' } ] } From 6f562b9436e15a42c170d95bc6ffb316d5dc8ebb Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 30 Jul 2024 18:43:20 +0200 Subject: [PATCH 61/86] pr-fix: pass in the key vault name --- build/deploy-test-resources.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index b863631f..887191f4 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -41,5 +41,5 @@ stages: --parameters resourceGroupName=${{ parameters.resourceGroupName }} ` --parameters instrumentationKey_secretName=${{ variables['Arcus.ApplicationInsights.InstrumentationKey.SecretName'] }} ` --parameters resourceId_secretName=${{ variables['Arcus.LogAnalyticsWorkspace.ResourceId.SecretName'] }} ` - --parameters keyVaultName=${{ variables['KeyVault.Name'] }} ` + --parameters keyVaultName=${{ variables['Arcus.KeyVault.Name'] }} ` --parameters servicePrincipal_objectId=$objectId \ No newline at end of file From db1cf24eff8b3a4a12115aaf42d23bf177d0562b Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 30 Jul 2024 18:47:05 +0200 Subject: [PATCH 62/86] pr-fix: use guid for role definition --- build/deploy-test-resources.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 887191f4..92cf09e6 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -39,7 +39,7 @@ stages: --template-file ./build/templates/deploy-test-resources.bicep ` --parameters location=westeurope ` --parameters resourceGroupName=${{ parameters.resourceGroupName }} ` - --parameters instrumentationKey_secretName=${{ variables['Arcus.ApplicationInsights.InstrumentationKey.SecretName'] }} ` - --parameters resourceId_secretName=${{ variables['Arcus.LogAnalyticsWorkspace.ResourceId.SecretName'] }} ` - --parameters keyVaultName=${{ variables['Arcus.KeyVault.Name'] }} ` + --parameters instrumentationKey_secretName=${{ variables['Arcus.Observability.ApplicationInsights.InstrumentationKey.SecretName'] }} ` + --parameters resourceId_secretName=${{ variables['Arcus.Observability.LogAnalyticsWorkspace.ResourceId.SecretName'] }} ` + --parameters keyVaultName=${{ variables['Arcus.Observability.KeyVault.Name'] }} ` --parameters servicePrincipal_objectId=$objectId \ No newline at end of file From 54daf36d08074acc550ac784d4f6eef917bfcecc Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Tue, 30 Jul 2024 18:57:16 +0200 Subject: [PATCH 63/86] pr-fix: add servie principal to env --- build/templates/import-keyvault-secrets.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/build/templates/import-keyvault-secrets.yml b/build/templates/import-keyvault-secrets.yml index fb09846e..6aa8cb6a 100644 --- a/build/templates/import-keyvault-secrets.yml +++ b/build/templates/import-keyvault-secrets.yml @@ -6,6 +6,7 @@ steps: displayName: 'Import secrets from Azure Key Vault' inputs: azureSubscription: '${{ parameters.azureServiceConnection }}' + addSpnToEnvironment: true scriptType: 'pscore' scriptLocation: 'inlineScript' inlineScript: | From 67ba308cba3c3b03845e10798e34a493779b7de3 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Wed, 31 Jul 2024 18:20:11 +0200 Subject: [PATCH 64/86] pr-fix: use correct syntax --- build/templates/import-keyvault-secrets.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/build/templates/import-keyvault-secrets.yml b/build/templates/import-keyvault-secrets.yml index 6aa8cb6a..22c4c27b 100644 --- a/build/templates/import-keyvault-secrets.yml +++ b/build/templates/import-keyvault-secrets.yml @@ -18,7 +18,11 @@ steps: Set-AzDevOpsVariable -Name 'Arcus.Observability.ServicePrincipal.ClientSecret' -Value $env:servicePrincipalKey $keyVaultName = ${{ variables['Arcus.KeyVault.Name'] }} - $resourceId_secretName = ${{ variables['Arcus.LogAnalyticsWorkspace.ResourceId.SecretName'] }} + $instrumentationKey_secretName = ${{ variables['Arcus.ApplicationInsights.InstrumentationKey.SecretName'] }} - az keyvault secret show --name $instrumentationKey_secretName --vault-name $keyVaultName --query value -o tsv | Set-AzDevOpsVariable -AsSecret -Name 'Arcus.Observability.ApplicationInsights.InstrumentationKey' -Value - az keyvault secret show --name $resourceId_secretName --vault-name $keyVaultName --query value -o tsv | Set-AzDevOpsVariable -AsSecret -Name 'Arcus.Observability.LogAnalyticsWorkspace.ResourceId' -Value \ No newline at end of file + $instrumentationKeySecret = az keyvault secret show --name "$instrumentationKey_secretName" --vault-name $keyVaultName + Set-AzDevOpsVariable -AsSecret -Name 'Arcus.Observability.ApplicationInsights.InstrumentationKey' -Value $instrumentationKeySecret.value + + $resourceId_secretName = ${{ variables['Arcus.LogAnalyticsWorkspace.ResourceId.SecretName'] }} + $resourceIdSecret = az keyvault secret show --name "$resourceId_secretName" --vault-name $keyVaultName + Set-AzDevOpsVariable -AsSecret -Name 'Arcus.Observability.LogAnalyticsWorkspace.ResourceId' -Value $resourceIdSecret.value \ No newline at end of file From dacdfba35d332712e6adfea53a49d004112f0b59 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Wed, 31 Jul 2024 18:34:08 +0200 Subject: [PATCH 65/86] pr-fix: use single vault name --- build/templates/import-keyvault-secrets.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/templates/import-keyvault-secrets.yml b/build/templates/import-keyvault-secrets.yml index 22c4c27b..3673eca9 100644 --- a/build/templates/import-keyvault-secrets.yml +++ b/build/templates/import-keyvault-secrets.yml @@ -20,9 +20,9 @@ steps: $keyVaultName = ${{ variables['Arcus.KeyVault.Name'] }} $instrumentationKey_secretName = ${{ variables['Arcus.ApplicationInsights.InstrumentationKey.SecretName'] }} - $instrumentationKeySecret = az keyvault secret show --name "$instrumentationKey_secretName" --vault-name $keyVaultName + $instrumentationKeySecret = az keyvault secret show --name "$instrumentationKey_secretName" --vault-name "$keyVaultName" Set-AzDevOpsVariable -AsSecret -Name 'Arcus.Observability.ApplicationInsights.InstrumentationKey' -Value $instrumentationKeySecret.value $resourceId_secretName = ${{ variables['Arcus.LogAnalyticsWorkspace.ResourceId.SecretName'] }} - $resourceIdSecret = az keyvault secret show --name "$resourceId_secretName" --vault-name $keyVaultName + $resourceIdSecret = az keyvault secret show --name "$resourceId_secretName" --vault-name "$keyVaultName" Set-AzDevOpsVariable -AsSecret -Name 'Arcus.Observability.LogAnalyticsWorkspace.ResourceId' -Value $resourceIdSecret.value \ No newline at end of file From fdfd7ad53833c1c3d822c7ebb9cb06fd91765f47 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Wed, 31 Jul 2024 18:51:44 +0200 Subject: [PATCH 66/86] pr-fix: use correct value syntax --- build/templates/import-keyvault-secrets.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/templates/import-keyvault-secrets.yml b/build/templates/import-keyvault-secrets.yml index 3673eca9..2dec1097 100644 --- a/build/templates/import-keyvault-secrets.yml +++ b/build/templates/import-keyvault-secrets.yml @@ -20,9 +20,9 @@ steps: $keyVaultName = ${{ variables['Arcus.KeyVault.Name'] }} $instrumentationKey_secretName = ${{ variables['Arcus.ApplicationInsights.InstrumentationKey.SecretName'] }} - $instrumentationKeySecret = az keyvault secret show --name "$instrumentationKey_secretName" --vault-name "$keyVaultName" + $instrumentationKeySecret = az keyvault secret show --name "$instrumentationKey_secretName" --vault-name "$keyVaultName" | ConvertFrom-Json Set-AzDevOpsVariable -AsSecret -Name 'Arcus.Observability.ApplicationInsights.InstrumentationKey' -Value $instrumentationKeySecret.value $resourceId_secretName = ${{ variables['Arcus.LogAnalyticsWorkspace.ResourceId.SecretName'] }} - $resourceIdSecret = az keyvault secret show --name "$resourceId_secretName" --vault-name "$keyVaultName" + $resourceIdSecret = az keyvault secret show --name "$resourceId_secretName" --vault-name "$keyVaultName" | ConvertFrom-Json Set-AzDevOpsVariable -AsSecret -Name 'Arcus.Observability.LogAnalyticsWorkspace.ResourceId' -Value $resourceIdSecret.value \ No newline at end of file From ddadafc2cce7c8473b162c9368d312343ac0a1e6 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 1 Aug 2024 06:56:10 +0200 Subject: [PATCH 67/86] pr-fix: use pscal case name --- build/templates/import-keyvault-secrets.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/templates/import-keyvault-secrets.yml b/build/templates/import-keyvault-secrets.yml index 2dec1097..d98ca02b 100644 --- a/build/templates/import-keyvault-secrets.yml +++ b/build/templates/import-keyvault-secrets.yml @@ -21,8 +21,8 @@ steps: $instrumentationKey_secretName = ${{ variables['Arcus.ApplicationInsights.InstrumentationKey.SecretName'] }} $instrumentationKeySecret = az keyvault secret show --name "$instrumentationKey_secretName" --vault-name "$keyVaultName" | ConvertFrom-Json - Set-AzDevOpsVariable -AsSecret -Name 'Arcus.Observability.ApplicationInsights.InstrumentationKey' -Value $instrumentationKeySecret.value + Set-AzDevOpsVariable -AsSecret -Name 'Arcus.Observability.ApplicationInsights.InstrumentationKey' -Value $instrumentationKeySecret.Value $resourceId_secretName = ${{ variables['Arcus.LogAnalyticsWorkspace.ResourceId.SecretName'] }} $resourceIdSecret = az keyvault secret show --name "$resourceId_secretName" --vault-name "$keyVaultName" | ConvertFrom-Json - Set-AzDevOpsVariable -AsSecret -Name 'Arcus.Observability.LogAnalyticsWorkspace.ResourceId' -Value $resourceIdSecret.value \ No newline at end of file + Set-AzDevOpsVariable -AsSecret -Name 'Arcus.Observability.LogAnalyticsWorkspace.ResourceId' -Value $resourceIdSecret.Value \ No newline at end of file From cefafaa352665c05d9fa8ecb83bfb077702ac1b3 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 1 Aug 2024 07:00:58 +0200 Subject: [PATCH 68/86] pr-fix: use pascalcase names --- build/templates/import-keyvault-secrets.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/build/templates/import-keyvault-secrets.yml b/build/templates/import-keyvault-secrets.yml index d98ca02b..955123ae 100644 --- a/build/templates/import-keyvault-secrets.yml +++ b/build/templates/import-keyvault-secrets.yml @@ -17,12 +17,15 @@ steps: Set-AzDevOpsVariable -Name 'Arcus.Observability.ServicePrincipal.ClientId' -Value $env:servicePrincipalId Set-AzDevOpsVariable -Name 'Arcus.Observability.ServicePrincipal.ClientSecret' -Value $env:servicePrincipalKey - $keyVaultName = ${{ variables['Arcus.KeyVault.Name'] }} + $keyVaultName = $env:ARCUS_KEYVAULT_NAME + Write-Host "Importing secrets from Key Vault: $keyVaultName" - $instrumentationKey_secretName = ${{ variables['Arcus.ApplicationInsights.InstrumentationKey.SecretName'] }} + $instrumentationKey_secretName = $env:ARCUS_APPLICATIONINSIGHTS_INSTRUMENTATIONKEY_SECRETNAME + Write-Host "Importing secret: $instrumentationKey_secretName" $instrumentationKeySecret = az keyvault secret show --name "$instrumentationKey_secretName" --vault-name "$keyVaultName" | ConvertFrom-Json - Set-AzDevOpsVariable -AsSecret -Name 'Arcus.Observability.ApplicationInsights.InstrumentationKey' -Value $instrumentationKeySecret.Value + Set-AzDevOpsVariable -AsSecret -Name 'Arcus.Observability.ApplicationInsights.InstrumentationKey' -Value $instrumentationKeySecret.value - $resourceId_secretName = ${{ variables['Arcus.LogAnalyticsWorkspace.ResourceId.SecretName'] }} + $resourceId_secretName = $env:ARCUS_LOGANALYTICSWORKSPACE_RESOURCEID_SECRETNAME + Write-Host "Importing secret: $resourceId_secretName" $resourceIdSecret = az keyvault secret show --name "$resourceId_secretName" --vault-name "$keyVaultName" | ConvertFrom-Json - Set-AzDevOpsVariable -AsSecret -Name 'Arcus.Observability.LogAnalyticsWorkspace.ResourceId' -Value $resourceIdSecret.Value \ No newline at end of file + Set-AzDevOpsVariable -AsSecret -Name 'Arcus.Observability.LogAnalyticsWorkspace.ResourceId' -Value $resourceIdSecret.value \ No newline at end of file From 46d6d826f9299cf0e9f1210ea379d30e4f0afc85 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 1 Aug 2024 07:06:40 +0200 Subject: [PATCH 69/86] pr-fix: use observability prefix --- build/templates/import-keyvault-secrets.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/templates/import-keyvault-secrets.yml b/build/templates/import-keyvault-secrets.yml index 955123ae..ab1c3c52 100644 --- a/build/templates/import-keyvault-secrets.yml +++ b/build/templates/import-keyvault-secrets.yml @@ -20,12 +20,12 @@ steps: $keyVaultName = $env:ARCUS_KEYVAULT_NAME Write-Host "Importing secrets from Key Vault: $keyVaultName" - $instrumentationKey_secretName = $env:ARCUS_APPLICATIONINSIGHTS_INSTRUMENTATIONKEY_SECRETNAME + $instrumentationKey_secretName = $env:ARCUS_OBSERVABILITY_APPLICATIONINSIGHTS_INSTRUMENTATIONKEY_SECRETNAME Write-Host "Importing secret: $instrumentationKey_secretName" $instrumentationKeySecret = az keyvault secret show --name "$instrumentationKey_secretName" --vault-name "$keyVaultName" | ConvertFrom-Json Set-AzDevOpsVariable -AsSecret -Name 'Arcus.Observability.ApplicationInsights.InstrumentationKey' -Value $instrumentationKeySecret.value - $resourceId_secretName = $env:ARCUS_LOGANALYTICSWORKSPACE_RESOURCEID_SECRETNAME + $resourceId_secretName = $env:ARCUS_OBSERVABILITY_LOGANALYTICSWORKSPACE_RESOURCEID_SECRETNAME Write-Host "Importing secret: $resourceId_secretName" $resourceIdSecret = az keyvault secret show --name "$resourceId_secretName" --vault-name "$keyVaultName" | ConvertFrom-Json Set-AzDevOpsVariable -AsSecret -Name 'Arcus.Observability.LogAnalyticsWorkspace.ResourceId' -Value $resourceIdSecret.value \ No newline at end of file From 50af20dfa86f4b7e6261b6b6786273389c7cfcc3 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 1 Aug 2024 07:16:09 +0200 Subject: [PATCH 70/86] pr-fix: use pacal case --- build/templates/import-keyvault-secrets.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/templates/import-keyvault-secrets.yml b/build/templates/import-keyvault-secrets.yml index ab1c3c52..492cebcc 100644 --- a/build/templates/import-keyvault-secrets.yml +++ b/build/templates/import-keyvault-secrets.yml @@ -17,7 +17,7 @@ steps: Set-AzDevOpsVariable -Name 'Arcus.Observability.ServicePrincipal.ClientId' -Value $env:servicePrincipalId Set-AzDevOpsVariable -Name 'Arcus.Observability.ServicePrincipal.ClientSecret' -Value $env:servicePrincipalKey - $keyVaultName = $env:ARCUS_KEYVAULT_NAME + $keyVaultName = $env:ARCUS_OBSERVABILITY_KEYVAULT_NAME Write-Host "Importing secrets from Key Vault: $keyVaultName" $instrumentationKey_secretName = $env:ARCUS_OBSERVABILITY_APPLICATIONINSIGHTS_INSTRUMENTATIONKEY_SECRETNAME From 0754a0a8c6540f3299582e4713b0e0a26eb920cb Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 1 Aug 2024 07:21:16 +0200 Subject: [PATCH 71/86] pr-fix: correct replacement variable names --- src/Arcus.Observability.Tests.Integration/appsettings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Arcus.Observability.Tests.Integration/appsettings.json b/src/Arcus.Observability.Tests.Integration/appsettings.json index 4417cf55..1b048be1 100644 --- a/src/Arcus.Observability.Tests.Integration/appsettings.json +++ b/src/Arcus.Observability.Tests.Integration/appsettings.json @@ -7,9 +7,9 @@ } }, "ApplicationInsights": { - "InstrumentationKey": "#{Arcus.ApplicationInsights.InstrumentationKey}#", + "InstrumentationKey": "#{Arcus.Observability.ApplicationInsights.InstrumentationKey}#", "LogAnalyticsWorkspace": { - "ResourceId": "#{Arcus.ApplicationInsights.LogAnalyticsWorkspace.ResourceId}#", + "ResourceId": "#{Arcus.Observability.ApplicationInsights.LogAnalyticsWorkspace.ResourceId}#", } }, "AzureFunctions": { From 0cd5d6f275205418bec4c837464f7ba03637e9f7 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 1 Aug 2024 07:31:09 +0200 Subject: [PATCH 72/86] pr-fix: use corect name --- build/templates/import-keyvault-secrets.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/templates/import-keyvault-secrets.yml b/build/templates/import-keyvault-secrets.yml index 492cebcc..9d980095 100644 --- a/build/templates/import-keyvault-secrets.yml +++ b/build/templates/import-keyvault-secrets.yml @@ -28,4 +28,4 @@ steps: $resourceId_secretName = $env:ARCUS_OBSERVABILITY_LOGANALYTICSWORKSPACE_RESOURCEID_SECRETNAME Write-Host "Importing secret: $resourceId_secretName" $resourceIdSecret = az keyvault secret show --name "$resourceId_secretName" --vault-name "$keyVaultName" | ConvertFrom-Json - Set-AzDevOpsVariable -AsSecret -Name 'Arcus.Observability.LogAnalyticsWorkspace.ResourceId' -Value $resourceIdSecret.value \ No newline at end of file + Set-AzDevOpsVariable -AsSecret -Name 'Arcus.Observability.ApplicationInsights.LogAnalyticsWorkspace.ResourceId' -Value $resourceIdSecret.value \ No newline at end of file From 798eff71cb2bce2be05af7ac460d345d8c3f05f8 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 1 Aug 2024 07:40:18 +0200 Subject: [PATCH 73/86] pr-fix: use correct var name --- .../Serilog/Sinks/ApplicationInsights/AppInsightsClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AppInsightsClient.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AppInsightsClient.cs index e4f77630..57b22b31 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AppInsightsClient.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AppInsightsClient.cs @@ -28,7 +28,7 @@ public AppInsightsClient(TestConfig config) { ServicePrincipal servicePrincipal = config.GetServicePrincipal(); _queryClient = new LogsQueryClient(new ClientSecretCredential(servicePrincipal.TenantId, servicePrincipal.ClientId, servicePrincipal.ClientSecret)); - _resourceId = config["Arcus:LogAnalyticsWorkspace:ResourceId"]; + _resourceId = config["Arcus:ApplicationInsights:LogAnalyticsWorkspace:ResourceId"]; _timeRange = new QueryTimeRange(TimeSpan.FromDays(1)); } From 2df7ca9cea3978ce0d13a79fba88471c1de3f513 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 1 Aug 2024 07:48:01 +0200 Subject: [PATCH 74/86] pr-fix: move to correct location --- .../appsettings.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Arcus.Observability.Tests.Integration/appsettings.json b/src/Arcus.Observability.Tests.Integration/appsettings.json index 1b048be1..8e7b8a3e 100644 --- a/src/Arcus.Observability.Tests.Integration/appsettings.json +++ b/src/Arcus.Observability.Tests.Integration/appsettings.json @@ -4,12 +4,12 @@ "ServicePrincipal": { "ClientId": "#{Arcus.Observability.ServicePrincipal.ClientId}#", "ClientSecret": "#{Arcus.Observability.ServicePrincipal.ClientSecret}#" - } - }, - "ApplicationInsights": { - "InstrumentationKey": "#{Arcus.Observability.ApplicationInsights.InstrumentationKey}#", - "LogAnalyticsWorkspace": { - "ResourceId": "#{Arcus.Observability.ApplicationInsights.LogAnalyticsWorkspace.ResourceId}#", + }, + "ApplicationInsights": { + "InstrumentationKey": "#{Arcus.Observability.ApplicationInsights.InstrumentationKey}#", + "LogAnalyticsWorkspace": { + "ResourceId": "#{Arcus.Observability.ApplicationInsights.LogAnalyticsWorkspace.ResourceId}#", + } } }, "AzureFunctions": { From f0188bbd462ae851652cc592b0c95f9a0a1d1a44 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 1 Aug 2024 07:48:40 +0200 Subject: [PATCH 75/86] pr-fix: move to correct location --- .../Sinks/ApplicationInsights/ApplicationInsightsSinkTests.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsSinkTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsSinkTests.cs index b6f35fd1..b707d702 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsSinkTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsSinkTests.cs @@ -44,8 +44,7 @@ protected ApplicationInsightsSinkTests(ITestOutputHelper outputWriter) : base(ou _testOutput = outputWriter; ApplicationInsightsSinkOptions = new ApplicationInsightsSinkOptions(); LoggerConfiguration = new LoggerConfiguration(); - InstrumentationKey = Configuration.GetValue("ApplicationInsights:InstrumentationKey"); - ApplicationId = Configuration.GetValue("ApplicationInsights:ApplicationId"); + InstrumentationKey = Configuration.GetValue("Arcus:ApplicationInsights:InstrumentationKey"); _telemetrySink = new InMemoryApplicationInsightsTelemetryConverter(); } From 16a11f2be85ace379d626939134bbe8b5c1f97fa Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 1 Aug 2024 08:04:56 +0200 Subject: [PATCH 76/86] pr-fix: correct secret value --- build/templates/deploy-test-resources.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/templates/deploy-test-resources.bicep b/build/templates/deploy-test-resources.bicep index d9c0986c..b51afe59 100644 --- a/build/templates/deploy-test-resources.bicep +++ b/build/templates/deploy-test-resources.bicep @@ -83,7 +83,7 @@ module vault 'br/public:avm/res/key-vault/vault:0.6.1' = { } { name: resourceId_secretName - value: workspace.outputs.resourceGroupName + value: workspace.outputs.resourceId } ] } From 26f3beb6dff4cdc7a4c130e1a4f00b6787fadb87 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 1 Aug 2024 08:21:07 +0200 Subject: [PATCH 77/86] pr-fix: use workspace id --- build/deploy-test-resources.yml | 2 +- build/templates/deploy-test-resources.bicep | 6 +++--- build/templates/import-keyvault-secrets.yml | 4 ++-- build/variables/test.yml | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/build/deploy-test-resources.yml b/build/deploy-test-resources.yml index 92cf09e6..479654b5 100644 --- a/build/deploy-test-resources.yml +++ b/build/deploy-test-resources.yml @@ -40,6 +40,6 @@ stages: --parameters location=westeurope ` --parameters resourceGroupName=${{ parameters.resourceGroupName }} ` --parameters instrumentationKey_secretName=${{ variables['Arcus.Observability.ApplicationInsights.InstrumentationKey.SecretName'] }} ` - --parameters resourceId_secretName=${{ variables['Arcus.Observability.LogAnalyticsWorkspace.ResourceId.SecretName'] }} ` + --parameters workspaceId_secretName=${{ variables['Arcus.Observability.LogAnalytics.WorkspaceId.SecretName'] }} ` --parameters keyVaultName=${{ variables['Arcus.Observability.KeyVault.Name'] }} ` --parameters servicePrincipal_objectId=$objectId \ No newline at end of file diff --git a/build/templates/deploy-test-resources.bicep b/build/templates/deploy-test-resources.bicep index b51afe59..72e1e9ab 100644 --- a/build/templates/deploy-test-resources.bicep +++ b/build/templates/deploy-test-resources.bicep @@ -8,7 +8,7 @@ param resourceGroupName string param instrumentationKey_secretName string // Define the name of the secret that will store the Application Insights workspace resource ID. -param resourceId_secretName string +param workspaceId_secretName string // Define the name of the Key Vault. param keyVaultName string @@ -82,8 +82,8 @@ module vault 'br/public:avm/res/key-vault/vault:0.6.1' = { value: component.outputs.instrumentationKey } { - name: resourceId_secretName - value: workspace.outputs.resourceId + name: workspaceId_secretName + value: workspace.outputs.logAnalyticsWorkspaceId } ] } diff --git a/build/templates/import-keyvault-secrets.yml b/build/templates/import-keyvault-secrets.yml index 9d980095..dd4ba707 100644 --- a/build/templates/import-keyvault-secrets.yml +++ b/build/templates/import-keyvault-secrets.yml @@ -25,7 +25,7 @@ steps: $instrumentationKeySecret = az keyvault secret show --name "$instrumentationKey_secretName" --vault-name "$keyVaultName" | ConvertFrom-Json Set-AzDevOpsVariable -AsSecret -Name 'Arcus.Observability.ApplicationInsights.InstrumentationKey' -Value $instrumentationKeySecret.value - $resourceId_secretName = $env:ARCUS_OBSERVABILITY_LOGANALYTICSWORKSPACE_RESOURCEID_SECRETNAME + $resourceId_secretName = $env:ARCUS_OBSERVABILITY_LOGANALYTICS_WORKSPACEID_SECRETNAME Write-Host "Importing secret: $resourceId_secretName" $resourceIdSecret = az keyvault secret show --name "$resourceId_secretName" --vault-name "$keyVaultName" | ConvertFrom-Json - Set-AzDevOpsVariable -AsSecret -Name 'Arcus.Observability.ApplicationInsights.LogAnalyticsWorkspace.ResourceId' -Value $resourceIdSecret.value \ No newline at end of file + Set-AzDevOpsVariable -AsSecret -Name 'Arcus.Observability.ApplicationInsights.LogAnalytics.WorkspaceId' -Value $resourceIdSecret.value \ No newline at end of file diff --git a/build/variables/test.yml b/build/variables/test.yml index f67dda66..a375fdf5 100644 --- a/build/variables/test.yml +++ b/build/variables/test.yml @@ -2,4 +2,4 @@ variables: AzureFunctions.HttpPort: 5000 Arcus.Observability.KeyVault.Name: 'arcus-observability-kv' Arcus.Observability.ApplicationInsights.InstrumentationKey.SecretName: 'ApplicationInsights-InstrumentationKey' - Arcus.Observability.LogAnalyticsWorkspace.ResourceId.SecretName: 'LogAnalytics-Workspace-ResourceId' \ No newline at end of file + Arcus.Observability.LogAnalytics.WorkspaceId.SecretName: 'LogAnalytics-WorkspaceId' \ No newline at end of file From bcb758f59099f492bbcd9e67b8fd39c70ff71a8f Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 1 Aug 2024 08:29:56 +0200 Subject: [PATCH 78/86] pr-fix: var name --- .../Serilog/Sinks/ApplicationInsights/AppInsightsClient.cs | 6 +++--- src/Arcus.Observability.Tests.Integration/appsettings.json | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AppInsightsClient.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AppInsightsClient.cs index 57b22b31..3d147561 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AppInsightsClient.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AppInsightsClient.cs @@ -19,7 +19,7 @@ public class AppInsightsClient : ITelemetryQueryClient { private readonly LogsQueryClient _queryClient; private readonly QueryTimeRange _timeRange; - private readonly string _resourceId; + private readonly string _workspaceId; /// /// Initializes a new instance of the class. @@ -28,7 +28,7 @@ public AppInsightsClient(TestConfig config) { ServicePrincipal servicePrincipal = config.GetServicePrincipal(); _queryClient = new LogsQueryClient(new ClientSecretCredential(servicePrincipal.TenantId, servicePrincipal.ClientId, servicePrincipal.ClientSecret)); - _resourceId = config["Arcus:ApplicationInsights:LogAnalyticsWorkspace:ResourceId"]; + _workspaceId = config["Arcus:ApplicationInsights:LogAnalytics:WorkspaceId"]; _timeRange = new QueryTimeRange(TimeSpan.FromDays(1)); } @@ -178,7 +178,7 @@ public async Task GetExceptionsAsync() private async Task> QueryLogsAsync(string query) { LogsQueryResult response = await _queryClient.QueryWorkspaceAsync( - _resourceId, + _workspaceId, query, timeRange: _timeRange, new LogsQueryOptions { ServerTimeout = TimeSpan.FromSeconds(3) }); diff --git a/src/Arcus.Observability.Tests.Integration/appsettings.json b/src/Arcus.Observability.Tests.Integration/appsettings.json index 8e7b8a3e..59a41661 100644 --- a/src/Arcus.Observability.Tests.Integration/appsettings.json +++ b/src/Arcus.Observability.Tests.Integration/appsettings.json @@ -7,8 +7,8 @@ }, "ApplicationInsights": { "InstrumentationKey": "#{Arcus.Observability.ApplicationInsights.InstrumentationKey}#", - "LogAnalyticsWorkspace": { - "ResourceId": "#{Arcus.Observability.ApplicationInsights.LogAnalyticsWorkspace.ResourceId}#", + "LogAnalytics": { + "WorkspaceId": "#{Arcus.Observability.ApplicationInsights.LogAnalytics.WorkspaceId}#" } } }, From f3d507369271328d772791f9111db960f9410ac7 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 1 Aug 2024 09:03:54 +0200 Subject: [PATCH 79/86] pr-fix: pass correct instrumentation key --- build/templates/run-docker-integration-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/templates/run-docker-integration-tests.yml b/build/templates/run-docker-integration-tests.yml index 007d2370..174bb0f2 100644 --- a/build/templates/run-docker-integration-tests.yml +++ b/build/templates/run-docker-integration-tests.yml @@ -61,7 +61,7 @@ jobs: containerName: '${{ parameters.dockerProjectName }}' ports: '${{ parameters.httpPort }}:80' envVars: | - APPINSIGHTS_INSTRUMENTATIONKEY=$(ApplicationInsights_InstrumentationKey) + APPINSIGHTS_INSTRUMENTATIONKEY=$(Arcus.Observability.ApplicationInsights.InstrumentationKey) AzureWebJobsStorage=$(Arcus.AzureFunctions.AzureWebJobsStorage) - template: test/run-integration-tests.yml@templates From 3f47744f9b9e088f44910cf5a19f148a14d6c64d Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 1 Aug 2024 09:04:08 +0200 Subject: [PATCH 80/86] pr-fix: correct exception message --- .../Serilog/Sinks/ApplicationInsights/AppInsightsClient.cs | 2 +- .../Serilog/Sinks/ApplicationInsights/ExceptionTests.cs | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AppInsightsClient.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AppInsightsClient.cs index 3d147561..5c5fa3a5 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AppInsightsClient.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AppInsightsClient.cs @@ -156,7 +156,7 @@ public async Task GetDependenciesAsync() public async Task GetExceptionsAsync() { IReadOnlyCollection rows = - await QueryLogsAsync("AppExceptions | project Message, OperationId, ParentId, AppRoleName, Properties"); + await QueryLogsAsync("AppExceptions | project OuterMessage, OperationId, ParentId, AppRoleName, Properties"); return rows.Select(row => { diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ExceptionTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ExceptionTests.cs index 98d291dc..29f92c08 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ExceptionTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ExceptionTests.cs @@ -85,11 +85,10 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => ExceptionResult[] results = await client.GetExceptionsAsync(); AssertX.Any(results, result => { - string propertyName = String.Format(propertyFormat, nameof(TestException.SpyProperty)); + string propertyName = string.Format(propertyFormat, nameof(TestException.SpyProperty)); Assert.Equal(exception.Message, result.Message); - Assert.True(result.CustomDimensions.TryGetValue(propertyName, out string actualProperty)); - Assert.Equal(expectedProperty, actualProperty); + Assert.Equal(expectedProperty, Assert.Contains(propertyName, result.CustomDimensions)); }); }); } From 5e2b926b497899ef92e331e5d604d3e3f734dcf8 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 1 Aug 2024 09:30:06 +0200 Subject: [PATCH 81/86] pr-fix: rename to original class to reduce code changes --- .../ApplicationInsights/AppInsightsClient.cs | 22 +++++----- .../ApplicationInsightsSinkExtensionTests.cs | 18 ++++----- .../AzureFunctionsDockerTests.cs | 2 +- .../AzureKeyVaultDependencyTests.cs | 2 +- .../AzureSearchDependencyTests.cs | 2 +- .../BlobStorageDependencyTests.cs | 2 +- .../CosmosSqlDependencyTests.cs | 2 +- .../CustomDependencyTests.cs | 4 +- .../ApplicationInsights/CustomRequestTests.cs | 2 +- .../EventHubsDependencyTests.cs | 2 +- .../EventHubsRequestTests.cs | 2 +- .../Sinks/ApplicationInsights/EventTests.cs | 10 ++--- .../ApplicationInsights/ExceptionTests.cs | 16 ++++---- .../Fixture/ITelemetryQueryClient.cs | 40 +++++++++---------- .../Fixture/InMemoryTelemetryQueryClient.cs | 24 +++++------ .../HttpDependencyTests.cs | 6 +-- .../HttpRequestDataTests.cs | 2 +- .../Sinks/ApplicationInsights/IoTHubTests.cs | 4 +- .../Sinks/ApplicationInsights/MetricTests.cs | 4 +- .../Sinks/ApplicationInsights/RequestTests.cs | 12 +++--- .../ServiceBusDependencyTests.cs | 4 +- .../ServiceBusRequestTests.cs | 8 ++-- .../ApplicationInsights/SqlDependencyTests.cs | 4 +- .../TableStorageDependencyTests.cs | 2 +- .../Sinks/ApplicationInsights/TraceTests.cs | 8 ++-- 25 files changed, 102 insertions(+), 102 deletions(-) diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AppInsightsClient.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AppInsightsClient.cs index 5c5fa3a5..30e09ab1 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AppInsightsClient.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AppInsightsClient.cs @@ -35,7 +35,7 @@ public AppInsightsClient(TestConfig config) /// /// Gets the tracked traces from the Azure Application Insights instance. /// - public async Task GetTracesAsync() + public async Task GetTracesAsync() { IReadOnlyCollection rows = await QueryLogsAsync("AppTraces | project Message, OperationId, ParentId, AppRoleName, Properties"); @@ -51,7 +51,7 @@ public async Task GetTracesAsync() string customDimensionsTxt = row[4].ToString(); var customDimensions = JsonConvert.DeserializeObject>(customDimensionsTxt); - return new TraceResult(message, roleName, operation, customDimensions); + return new EventsTraceResult(message, roleName, operation, customDimensions); }).ToArray(); } @@ -59,7 +59,7 @@ public async Task GetTracesAsync() /// /// Gets the tracked metrics from the Azure Application Insights instance. /// - public Task GetMetricsAsync(string metricName) + public Task GetMetricsAsync(string metricName) { throw new NotImplementedException(); } @@ -67,7 +67,7 @@ public Task GetMetricsAsync(string metricName) /// /// Gets the tracked custom events from the Azure Application Insights instance. /// - public async Task GetCustomEventsAsync() + public async Task GetCustomEventsAsync() { IReadOnlyCollection rows = await QueryLogsAsync("AppEvents | project Name, AppRoleName, Properties"); @@ -80,7 +80,7 @@ public async Task GetCustomEventsAsync() var customDimensionsTxt = row[2].ToString(); var customDimensions = JsonConvert.DeserializeObject>(customDimensionsTxt); - return new CustomEventResult(name, roleName, customDimensions); + return new EventsCustomEventResult(name, roleName, customDimensions); }).ToArray(); } @@ -88,7 +88,7 @@ public async Task GetCustomEventsAsync() /// /// Gets the tracked requests from the Azure Application Insights instance. /// - public async Task GetRequestsAsync() + public async Task GetRequestsAsync() { IReadOnlyCollection rows = await QueryLogsAsync( @@ -111,7 +111,7 @@ await QueryLogsAsync( var customDimensionsTxt = row[9].ToString(); var customDimensions = JsonConvert.DeserializeObject>(customDimensionsTxt); - return new RequestResult(id, name, source, url, success, resultCode, roleName, operation, customDimensions); + return new EventsRequestResult(id, name, source, url, success, resultCode, roleName, operation, customDimensions); }).ToArray(); } @@ -119,7 +119,7 @@ await QueryLogsAsync( /// /// Gets the tracked dependencies from the Azure Application Insights instance. /// - public async Task GetDependenciesAsync() + public async Task GetDependenciesAsync() { IReadOnlyCollection rows = await QueryLogsAsync("AppDependencies | project Id, Target, DependencyType, Name, Data, Success, ResultCode, AppRoleName, OperationId, ParentId, Properties"); @@ -145,7 +145,7 @@ public async Task GetDependenciesAsync() var customDimensionsTxt = row[10].ToString(); var customDimensions = JsonConvert.DeserializeObject>(customDimensionsTxt); - return new DependencyResult(id, type, target, data, success, resultCode, name, roleName, operation, customDimensions); + return new EventsDependencyResult(id, type, target, data, success, resultCode, name, roleName, operation, customDimensions); }).ToArray(); } @@ -153,7 +153,7 @@ public async Task GetDependenciesAsync() /// /// Gets the tracked exceptions from the Azure Application Insights instance. /// - public async Task GetExceptionsAsync() + public async Task GetExceptionsAsync() { IReadOnlyCollection rows = await QueryLogsAsync("AppExceptions | project OuterMessage, OperationId, ParentId, AppRoleName, Properties"); @@ -170,7 +170,7 @@ public async Task GetExceptionsAsync() string customDimensionsTxt = row[4].ToString(); var customDimensions = JsonConvert.DeserializeObject>(customDimensionsTxt); - return new ExceptionResult(message, operation, roleName, customDimensions); + return new EventsExceptionResult(message, operation, roleName, customDimensions); }).ToArray(); } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsSinkExtensionTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsSinkExtensionTests.cs index de522832..1ddb3079 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsSinkExtensionTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsSinkExtensionTests.cs @@ -42,7 +42,7 @@ public async Task Sink_WithConnectionString_WritesTelemetry() // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - TraceResult[] traces = await client.GetTracesAsync(); + EventsTraceResult[] traces = await client.GetTracesAsync(); AssertX.Any(traces, trace => { Assert.Equal(message, trace.Message); @@ -71,7 +71,7 @@ public async Task Sink_WithConnectionStringWithServiceProvider_WritesTelemetry() // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - TraceResult[] traces = await client.GetTracesAsync(); + EventsTraceResult[] traces = await client.GetTracesAsync(); AssertX.Any(traces, trace => { Assert.Equal(message, trace.Message); @@ -95,7 +95,7 @@ public async Task Sink_WithInstrumentationKey_WritesTelemetry() // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - TraceResult[] traces = await client.GetTracesAsync(); + EventsTraceResult[] traces = await client.GetTracesAsync(); AssertX.Any(traces, trace => { Assert.Equal(message, trace.Message); @@ -122,7 +122,7 @@ public async Task Sink_WithInstrumentationKeyWithServiceProvider_WritesTelemetry // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - TraceResult[] traces = await client.GetTracesAsync(); + EventsTraceResult[] traces = await client.GetTracesAsync(); AssertX.Any(traces, trace => { Assert.Equal(message, trace.Message); @@ -150,7 +150,7 @@ public async Task SinkWithCustomTransactionIdPropertyName_TrackNonRequest_Enrich // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - TraceResult[] result = await client.GetTracesAsync(); + EventsTraceResult[] result = await client.GetTracesAsync(); AssertX.Any(result, trace => { Assert.Equal(message, trace.Message); @@ -180,7 +180,7 @@ public async Task SinkWithCustomOperationIdPropertyName_TrackNonRequest_EnrichCo // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - TraceResult[] result = await client.GetTracesAsync(); + EventsTraceResult[] result = await client.GetTracesAsync(); AssertX.Any(result, trace => { Assert.Equal(message, trace.Message); @@ -217,7 +217,7 @@ public async Task SinkWithCustomTransactionIdPropertyName_TrackRequest_EnrichCor // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - RequestResult[] result = await client.GetRequestsAsync(); + EventsRequestResult[] result = await client.GetRequestsAsync(); AssertX.Any(result, request => { Assert.Equal(correlation.TransactionId, request.Operation.Id); @@ -254,7 +254,7 @@ public async Task SinkWithCustomOperationIdPropertyName_TrackRequest_EnrichCorre // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - RequestResult[] result = await client.GetRequestsAsync(); + EventsRequestResult[] result = await client.GetRequestsAsync(); AssertX.Any(result, request => { Assert.Equal(correlation.TransactionId, request.Operation.Id); @@ -291,7 +291,7 @@ public async Task SinkWithCustomOperationParentIdPropertyName_TrackRequest_Enric // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - RequestResult[] result = await client.GetRequestsAsync(); + EventsRequestResult[] result = await client.GetRequestsAsync(); AssertX.Any(result, request => { Assert.Equal(correlation.TransactionId, request.Operation.Id); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureFunctionsDockerTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureFunctionsDockerTests.cs index d55c5cc5..eab4e718 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureFunctionsDockerTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureFunctionsDockerTests.cs @@ -24,7 +24,7 @@ public async Task LogRequest_WithRequestsOperationName_SinksToApplicationInsight await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - RequestResult[] results = await client.GetRequestsAsync(); + EventsRequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { Assert.Equal("200", result.ResultCode); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureKeyVaultDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureKeyVaultDependencyTests.cs index 1def20c1..8213e560 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureKeyVaultDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureKeyVaultDependencyTests.cs @@ -37,7 +37,7 @@ public async Task LogAzureKeyVaultDependency_SinksToApplicationInsights_ResultsI // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - DependencyResult[] results = await client.GetDependenciesAsync(); + EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { Assert.Equal(dependencyType, result.Type); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureSearchDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureSearchDependencyTests.cs index 9ab7127c..367b813d 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureSearchDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureSearchDependencyTests.cs @@ -38,7 +38,7 @@ public async Task LogAzureSearchDependency_SinksToApplicationInsights_ResultsInA // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - DependencyResult[] results = await client.GetDependenciesAsync(); + EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { Assert.Equal(dependencyType, result.Type); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/BlobStorageDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/BlobStorageDependencyTests.cs index abfa1ffe..e8f110a6 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/BlobStorageDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/BlobStorageDependencyTests.cs @@ -39,7 +39,7 @@ public async Task LogBlobStorageDependency_SinksToApplicationInsights_ResultsInB // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - DependencyResult[] results = await client.GetDependenciesAsync(); + EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { Assert.Equal(dependencyType, result.Type); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CosmosSqlDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CosmosSqlDependencyTests.cs index 16c11aa5..af9b95bc 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CosmosSqlDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CosmosSqlDependencyTests.cs @@ -40,7 +40,7 @@ public async Task LogCosmosSqlDependency_SinksToApplicationInsights_ResultsInCos // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - DependencyResult[] results = await client.GetDependenciesAsync(); + EventsDependencyResult[] results = await client.GetDependenciesAsync(); Assert.NotEmpty(results); AssertX.Any(results, result => { diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomDependencyTests.cs index 8875a01c..a8b3ced4 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomDependencyTests.cs @@ -33,7 +33,7 @@ public async Task LogDependency_SinksToApplicationInsights_ResultsInDependencyTe // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - DependencyResult[] results = await client.GetDependenciesAsync(); + EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { Assert.Equal(dependencyType, result.Type); @@ -65,7 +65,7 @@ public async Task LogDependency_SinksToApplicationInsights_ResultsInDependencyTe // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - DependencyResult[] results = await client.GetDependenciesAsync(); + EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { Assert.Equal(dependencyType, result.Type); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomRequestTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomRequestTests.cs index bead5f7d..3e845536 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomRequestTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomRequestTests.cs @@ -36,7 +36,7 @@ public async Task LogCustomRequest_SinksToApplicationInsights_ResultsInCustomReq // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - RequestResult[] requests = await client.GetRequestsAsync(); + EventsRequestResult[] requests = await client.GetRequestsAsync(); AssertX.Any(requests, result => { Assert.Equal(operationName, result.Name); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsDependencyTests.cs index 54e07f60..7669b5e3 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsDependencyTests.cs @@ -39,7 +39,7 @@ public async Task LogEventHubsDependency_SinksToApplicationInsights_ResultsInEve // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - DependencyResult[] results = await client.GetDependenciesAsync(); + EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { Assert.Equal(dependencyType, result.Type); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsRequestTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsRequestTests.cs index f7dba9f5..b65b8a47 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsRequestTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsRequestTests.cs @@ -39,7 +39,7 @@ public async Task LogEventHubsRequest_SinksToApplicationInsights_ResultsInEventH // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - RequestResult[] requests = await client.GetRequestsAsync(); + EventsRequestResult[] requests = await client.GetRequestsAsync(); AssertX.Any(requests, result => { Assert.Equal(operationName, result.Name); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventTests.cs index 928d01ed..4a1db728 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventTests.cs @@ -32,7 +32,7 @@ public async Task LogCustomEvent_SinksToApplicationInsights_ResultsInEventTeleme // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - CustomEventResult[] results = await client.GetCustomEventsAsync(); + EventsCustomEventResult[] results = await client.GetCustomEventsAsync(); AssertX.Any(results, ev => { Assert.Equal(eventName, ev.Name); @@ -54,7 +54,7 @@ public async Task LogEventWithComponentName_SinksToApplicationInsights_ResultsIn // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - TraceResult[] results = await client.GetTracesAsync(); + EventsTraceResult[] results = await client.GetTracesAsync(); AssertX.Any(results, trace => { Assert.Equal(message, trace.Message); @@ -77,7 +77,7 @@ public async Task LogCustomEventWithVersion_SinksToApplicationInsights_ResultsIn // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - CustomEventResult[] events = await client.GetCustomEventsAsync(); + EventsCustomEventResult[] events = await client.GetCustomEventsAsync(); AssertX.Any(events, ev => { Assert.Equal(eventName, ev.Name); @@ -106,7 +106,7 @@ public async Task LogEventWithCorrelationInfo_SinksToApplicationInsights_Results // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - TraceResult[] traceEvents = await client.GetTracesAsync(); + EventsTraceResult[] traceEvents = await client.GetTracesAsync(); AssertX.Any(traceEvents, trace => { Assert.Equal(message, trace.Message); @@ -142,7 +142,7 @@ public async Task LogEventWithKubernetesInfo_SinksToApplicationInsights_ResultsI // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - TraceResult[] traceEvents = await client.GetTracesAsync(); + EventsTraceResult[] traceEvents = await client.GetTracesAsync(); AssertX.Any(traceEvents, trace => { Assert.Equal(message, trace.Message); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ExceptionTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ExceptionTests.cs index 29f92c08..15f3f194 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ExceptionTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ExceptionTests.cs @@ -31,7 +31,7 @@ public async Task LogException_SinksToApplicationInsights_ResultsInExceptionTele // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - ExceptionResult[] results = await client.GetExceptionsAsync(); + EventsExceptionResult[] results = await client.GetExceptionsAsync(); AssertX.Any(results, result => { Assert.Equal(exception.Message, result.Message); @@ -55,7 +55,7 @@ public async Task LogException_SinksToApplicationInsightsWithIncludedProperties_ // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - ExceptionResult[] results = await client.GetExceptionsAsync(); + EventsExceptionResult[] results = await client.GetExceptionsAsync(); AssertX.Any(results, result => { Assert.Equal(exception.Message, result.Message); @@ -82,7 +82,7 @@ public async Task LogExceptionWithCustomPropertyFormat_SinksToApplicationInsight // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - ExceptionResult[] results = await client.GetExceptionsAsync(); + EventsExceptionResult[] results = await client.GetExceptionsAsync(); AssertX.Any(results, result => { string propertyName = string.Format(propertyFormat, nameof(TestException.SpyProperty)); @@ -108,7 +108,7 @@ public async Task LogExceptionWithComponentName_SinksToApplicationInsights_Resul // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - ExceptionResult[] results = await client.GetExceptionsAsync(); + EventsExceptionResult[] results = await client.GetExceptionsAsync(); AssertX.Any(results, result => { Assert.Equal(exception.Message, result.Message); @@ -138,7 +138,7 @@ public async Task LogExceptionWithCorrelationInfo_SinksToApplicationInsights_Res // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - ExceptionResult[] results = await client.GetExceptionsAsync(); + EventsExceptionResult[] results = await client.GetExceptionsAsync(); AssertX.Any(results, result => { Assert.Equal(exception.Message, result.Message); @@ -165,7 +165,7 @@ public async Task LogWarning_SinksToApplicationInsights_ResultsInTraceTelemetry( // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - ExceptionResult[] results = await client.GetExceptionsAsync(); + EventsExceptionResult[] results = await client.GetExceptionsAsync(); AssertX.Any(results, result => { Assert.Equal(exception.Message, result.Message); @@ -192,7 +192,7 @@ public async Task LogError_SinksToApplicationInsights_ResultsInTraceTelemetry() // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - ExceptionResult[] results = await client.GetExceptionsAsync(); + EventsExceptionResult[] results = await client.GetExceptionsAsync(); AssertX.Any(results, result => { Assert.Equal(exception.Message, result.Message); @@ -219,7 +219,7 @@ public async Task LogCritical_SinksToApplicationInsights_ResultsInTraceTelemetry // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - ExceptionResult[] results = await client.GetExceptionsAsync(); + EventsExceptionResult[] results = await client.GetExceptionsAsync(); AssertX.Any(results, result => { Assert.Equal(exception.Message, result.Message); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/ITelemetryQueryClient.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/ITelemetryQueryClient.cs index 8e85a178..ce754aa6 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/ITelemetryQueryClient.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/ITelemetryQueryClient.cs @@ -12,32 +12,32 @@ public interface ITelemetryQueryClient /// /// Gets the tracked traces from the Azure Application Insights instance. /// - Task GetTracesAsync(); + Task GetTracesAsync(); /// /// Gets the tracked metrics from the Azure Application Insights instance. /// - Task GetMetricsAsync(string metricName); + Task GetMetricsAsync(string metricName); /// /// Gets the tracked custom events from the Azure Application Insights instance. /// - Task GetCustomEventsAsync(); + Task GetCustomEventsAsync(); /// /// Gets the tracked requests from the Azure Application Insights instance. /// - Task GetRequestsAsync(); + Task GetRequestsAsync(); /// /// Gets the tracked dependencies from the Azure Application Insights instance. /// - Task GetDependenciesAsync(); + Task GetDependenciesAsync(); /// /// Gets the tracked exceptions from the Azure Application Insights instance. /// - Task GetExceptionsAsync(); + Task GetExceptionsAsync(); } public class OperationResult @@ -60,9 +60,9 @@ public OperationResult(string id, string parentId, string name) public string ParentId { get; } } - public class TraceResult + public class EventsTraceResult { - public TraceResult(string message, string roleName, OperationResult operation, IDictionary customDimensions) + public EventsTraceResult(string message, string roleName, OperationResult operation, IDictionary customDimensions) { Message = message; RoleName = roleName; @@ -76,12 +76,12 @@ public TraceResult(string message, string roleName, OperationResult operation, I public IDictionary CustomDimensions { get; } } - public class CustomEventResult + public class EventsCustomEventResult { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public CustomEventResult(string name, string roleName, IDictionary customDimensions) + public EventsCustomEventResult(string name, string roleName, IDictionary customDimensions) { Name = name; RoleName = roleName; @@ -93,9 +93,9 @@ public CustomEventResult(string name, string roleName, IDictionary CustomDimensions { get; } } - public class MetricsResult + public class EventsMetricsResult { - public MetricsResult(string name, double value, IDictionary customDimensions) + public EventsMetricsResult(string name, double value, IDictionary customDimensions) { Name = name; Value = value; @@ -107,9 +107,9 @@ public MetricsResult(string name, double value, IDictionary cust public IDictionary CustomDimensions { get; } } - public class RequestResult + public class EventsRequestResult { - public RequestResult( + public EventsRequestResult( string id, string name, string source, @@ -142,9 +142,9 @@ public RequestResult( public IDictionary CustomDimensions { get; } } - public class DependencyResult + public class EventsDependencyResult { - public DependencyResult( + public EventsDependencyResult( string id, string type, string target, @@ -180,12 +180,12 @@ public DependencyResult( public IDictionary CustomDimensions { get; } } - public class ExceptionResult + public class EventsExceptionResult { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public ExceptionResult(string message, OperationResult operation, string roleName, IDictionary customDimensions) + public EventsExceptionResult(string message, OperationResult operation, string roleName, IDictionary customDimensions) { Message = message; Operation = operation; diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/InMemoryTelemetryQueryClient.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/InMemoryTelemetryQueryClient.cs index 1ec60353..de08f42e 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/InMemoryTelemetryQueryClient.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/InMemoryTelemetryQueryClient.cs @@ -23,11 +23,11 @@ public InMemoryTelemetryQueryClient(InMemoryApplicationInsightsTelemetryConverte /// /// Gets the tracked traces from the Azure Application Insights instance. /// - public Task GetTracesAsync() + public Task GetTracesAsync() { return Task.FromResult(_telemetrySink.Traces.Select(t => { - return new TraceResult( + return new EventsTraceResult( t.Message, t.Context.Cloud.RoleName, new OperationResult( @@ -41,28 +41,28 @@ public Task GetTracesAsync() /// /// Gets the tracked metrics from the Azure Application Insights instance. /// - public Task GetMetricsAsync(string metricName) + public Task GetMetricsAsync(string metricName) { - return Task.FromResult(_telemetrySink.Metrics.Where(m => m.Name == metricName).Select(m => new MetricsResult(m.Name, m.Sum, m.Properties)).ToArray()); + return Task.FromResult(_telemetrySink.Metrics.Where(m => m.Name == metricName).Select(m => new EventsMetricsResult(m.Name, m.Sum, m.Properties)).ToArray()); } /// /// Gets the tracked custom events from the Azure Application Insights instance. /// - public Task GetCustomEventsAsync() + public Task GetCustomEventsAsync() { - return Task.FromResult(_telemetrySink.Events.Select(e => new CustomEventResult(e.Name, e.Context.Cloud.RoleName, e.Properties)).ToArray()); + return Task.FromResult(_telemetrySink.Events.Select(e => new EventsCustomEventResult(e.Name, e.Context.Cloud.RoleName, e.Properties)).ToArray()); } /// /// Gets the tracked requests from the Azure Application Insights instance. /// - public Task GetRequestsAsync() + public Task GetRequestsAsync() { return Task.FromResult(_telemetrySink.Requests.Select(r => { var operation = new OperationResult(r.Context.Operation.Id, r.Context.Operation.ParentId, r.Context.Operation.Name); - return new RequestResult( + return new EventsRequestResult( r.Id, r.Name, r.Source, @@ -78,12 +78,12 @@ public Task GetRequestsAsync() /// /// Gets the tracked dependencies from the Azure Application Insights instance. /// - public Task GetDependenciesAsync() + public Task GetDependenciesAsync() { return Task.FromResult(_telemetrySink.Dependencies.Select(d => { var operation = new OperationResult(d.Context.Operation.Id, d.Context.Operation.ParentId, d.Context.Operation.Name); - return new DependencyResult(d.Id, + return new EventsDependencyResult(d.Id, d.Type, d.Target, d.Data, @@ -99,7 +99,7 @@ public Task GetDependenciesAsync() /// /// Gets the tracked exceptions from the Azure Application Insights instance. /// - public Task GetExceptionsAsync() + public Task GetExceptionsAsync() { return Task.FromResult(_telemetrySink.Exceptions.Select(e => { @@ -107,7 +107,7 @@ public Task GetExceptionsAsync() e.Context.Operation.ParentId, e.Context.Operation.Name); - return new ExceptionResult( + return new EventsExceptionResult( e.Exception.Message, operation, e.Context.Cloud.RoleName, diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpDependencyTests.cs index 82ed7ece..2c056a8e 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpDependencyTests.cs @@ -50,7 +50,7 @@ public async Task LogHttpDependencyWithRequestMessageWithCorrelation_SinksToAppl var requestUri = new Uri(requestUrl); await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - DependencyResult[] results = await client.GetDependenciesAsync(); + EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { Assert.Equal(DependencyType, result.Type, StringComparer.OrdinalIgnoreCase); @@ -89,7 +89,7 @@ public async Task LogHttpDependencyWithRequestMessage_SinksToApplicationInsights var requestUri = new Uri(requestUrl); await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - DependencyResult[] results = await client.GetDependenciesAsync(); + EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { Assert.Equal(DependencyType, result.Type, StringComparer.OrdinalIgnoreCase); @@ -129,7 +129,7 @@ public async Task LogHttpDependencyWithRequest_SinksToApplicationInsights_Result // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - DependencyResult[] results = await client.GetDependenciesAsync(); + EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { Assert.Equal(DependencyType, result.Type, StringComparer.OrdinalIgnoreCase); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpRequestDataTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpRequestDataTests.cs index 1088296f..2acf361c 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpRequestDataTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpRequestDataTests.cs @@ -46,7 +46,7 @@ public async Task LogRequest_SinksToApplicationInsightsWithCorrelation_ResultsIn // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - RequestResult[] results = await client.GetRequestsAsync(); + EventsRequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Url); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/IoTHubTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/IoTHubTests.cs index 663a2066..9aa76ac7 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/IoTHubTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/IoTHubTests.cs @@ -37,7 +37,7 @@ public async Task LogIoTHubDependency_SinksToApplicationInsights_ResultsIEventHu // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - DependencyResult[] results = await client.GetDependenciesAsync(); + EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { Assert.Equal("Azure IoT Hub", result.Type); @@ -72,7 +72,7 @@ public async Task LogIoTHubDependencyWithConnectionString_SinksToApplicationInsi // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - DependencyResult[] results = await client.GetDependenciesAsync(); + EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { Assert.Equal("Azure IoT Hub", result.Type); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/MetricTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/MetricTests.cs index d2641ddd..c44fdc35 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/MetricTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/MetricTests.cs @@ -28,7 +28,7 @@ public async Task LogCustomMetric_SinksToApplicationInsights_ResultsInMetricTele // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - MetricsResult[] results = await client.GetMetricsAsync(metricName); + EventsMetricsResult[] results = await client.GetMetricsAsync(metricName); AssertX.Any(results, metric => { Assert.Equal(metricName, metric.Name); @@ -39,7 +39,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => }); } - private static void ContainsTelemetryContext(Dictionary telemetryContext, MetricsResult metric) + private static void ContainsTelemetryContext(Dictionary telemetryContext, EventsMetricsResult metric) { Assert.All(telemetryContext, item => { diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/RequestTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/RequestTests.cs index 10eaa48c..38746321 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/RequestTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/RequestTests.cs @@ -47,7 +47,7 @@ public async Task LogRequest_SinksToApplicationInsightsWithCorrelation_ResultsIn // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - RequestResult[] results = await client.GetRequestsAsync(); + EventsRequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Url); @@ -82,7 +82,7 @@ public async Task LogRequest_SinksToApplicationInsightsWithoutCustomId_ResultsIn // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - RequestResult[] results = await client.GetRequestsAsync(); + EventsRequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Url); @@ -117,7 +117,7 @@ public async Task LogRequest_SinksToApplicationInsightsWithResponseWithCustomId_ // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - RequestResult[] results = await client.GetRequestsAsync(); + EventsRequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Url); @@ -153,7 +153,7 @@ public async Task LogRequest_SinksToApplicationInsightsWithResponseStatusCodeWit // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - RequestResult[] results = await client.GetRequestsAsync(); + EventsRequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Url); @@ -188,7 +188,7 @@ public async Task LogRequestMessage_SinksToApplicationInsightsWithResponseWithCu // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - RequestResult[] results = await client.GetRequestsAsync(); + EventsRequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { Assert.Equal(requestUri.ToString(), result.Url); @@ -222,7 +222,7 @@ public async Task LogRequestMessage_SinksToApplicationInsightsWithResponseWithou // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - RequestResult[] results = await client.GetRequestsAsync(); + EventsRequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { Assert.Equal(requestUri.ToString(), result.Url); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusDependencyTests.cs index def4d7ae..c60dd1a0 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusDependencyTests.cs @@ -44,7 +44,7 @@ public async Task LogServiceBusDependencyWithCorrelation_SinksToApplicationInsig // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - DependencyResult[] results = await client.GetDependenciesAsync(); + EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { Assert.Equal(dependencyType, result.Type); @@ -83,7 +83,7 @@ public async Task LogServiceBusDependency_SinksToApplicationInsights_ResultsInSe // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - DependencyResult[] results = await client.GetDependenciesAsync(); + EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { Assert.Equal(dependencyType, result.Type); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusRequestTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusRequestTests.cs index fcf1091a..0fec918a 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusRequestTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusRequestTests.cs @@ -40,7 +40,7 @@ public async Task LogServiceBusQueueRequestWithCorrelation_SinksToApplicationIns // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - RequestResult[] results = await client.GetRequestsAsync(); + EventsRequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { Assert.Equal(operationName, result.Name); @@ -79,7 +79,7 @@ public async Task LogServiceBusQueueRequest_SinksToApplicationInsights_ResultsIn // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - RequestResult[] results = await client.GetRequestsAsync(); + EventsRequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { Assert.Equal(operationName, result.Name); @@ -116,7 +116,7 @@ public async Task LogServiceBusTopicRequestWithSuffix_SinksToApplicationInsights // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - RequestResult[] results = await client.GetRequestsAsync(); + EventsRequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { Assert.Equal(operationName, result.Name); @@ -156,7 +156,7 @@ public async Task LogServiceBusRequest_SinksToApplicationInsights_ResultsInReque // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - RequestResult[] results = await client.GetRequestsAsync(); + EventsRequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { Assert.Equal(operationName, result.Name); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/SqlDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/SqlDependencyTests.cs index f1b600f3..ac0d53dc 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/SqlDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/SqlDependencyTests.cs @@ -37,7 +37,7 @@ public async Task LogSqlDependency_SinksToApplicationInsights_ResultsInSqlDepend // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - DependencyResult[] results = await client.GetDependenciesAsync(); + EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { Assert.Equal(dependencyType, result.Type, StringComparer.OrdinalIgnoreCase); @@ -73,7 +73,7 @@ public async Task LogSqlDependencyWithConnectionString_SinksToApplicationInsight // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - DependencyResult[] results = await client.GetDependenciesAsync(); + EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { Assert.Equal(dependencyType, result.Type, StringComparer.OrdinalIgnoreCase); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TableStorageDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TableStorageDependencyTests.cs index b2fb5c55..4e0b7b09 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TableStorageDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TableStorageDependencyTests.cs @@ -39,7 +39,7 @@ public async Task LogTableStorageDependency_SinksToApplicationInsights_ResultsIn // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - DependencyResult[] results = await client.GetDependenciesAsync(); + EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { Assert.Equal(dependencyType, result.Type); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TraceTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TraceTests.cs index ac8a18ae..82d544ec 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TraceTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TraceTests.cs @@ -25,7 +25,7 @@ public async Task LogInformationWithoutContext_SinksToApplicationInsights_Result // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - TraceResult[] results = await client.GetTracesAsync(); + EventsTraceResult[] results = await client.GetTracesAsync(); AssertX.Any(results, result => { Assert.Contains(message, result.Message); @@ -49,7 +49,7 @@ public async Task LogInformation_SinksToApplicationInsights_ResultsInTraceTeleme // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - TraceResult[] results = await client.GetTracesAsync(); + EventsTraceResult[] results = await client.GetTracesAsync(); AssertX.Any(results, result => { Assert.Contains(message, result.Message); @@ -75,7 +75,7 @@ public async Task LogTrace_SinksToApplicationInsights_ResultsInTraceTelemetry() // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - TraceResult[] results = await client.GetTracesAsync(); + EventsTraceResult[] results = await client.GetTracesAsync(); AssertX.Any(results, result => { Assert.Contains(message, result.Message); @@ -101,7 +101,7 @@ public async Task LogDebug_SinksToApplicationInsights_ResultsInTraceTelemetry() // Assert await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { - TraceResult[] results = await client.GetTracesAsync(); + EventsTraceResult[] results = await client.GetTracesAsync(); AssertX.Any(results, result => { Assert.Contains(message, result.Message); From ab45203c7a8eb381a74ba84568c2f8309700ced6 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 1 Aug 2024 09:49:04 +0200 Subject: [PATCH 82/86] pr-fix: minimize trace changes --- .../ApplicationInsightsSinkExtensionTests.cs | 12 ++++++------ .../Sinks/ApplicationInsights/EventTests.cs | 6 +++--- .../Fixture/ITelemetryQueryClient.cs | 17 +++++++++++++++-- .../Sinks/ApplicationInsights/TraceTests.cs | 8 ++++---- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsSinkExtensionTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsSinkExtensionTests.cs index 1ddb3079..8c79150c 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsSinkExtensionTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsSinkExtensionTests.cs @@ -45,7 +45,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsTraceResult[] traces = await client.GetTracesAsync(); AssertX.Any(traces, trace => { - Assert.Equal(message, trace.Message); + Assert.Equal(message, trace.Trace.Message); }); }); } @@ -74,7 +74,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsTraceResult[] traces = await client.GetTracesAsync(); AssertX.Any(traces, trace => { - Assert.Equal(message, trace.Message); + Assert.Equal(message, trace.Trace.Message); }); }); } @@ -98,7 +98,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsTraceResult[] traces = await client.GetTracesAsync(); AssertX.Any(traces, trace => { - Assert.Equal(message, trace.Message); + Assert.Equal(message, trace.Trace.Message); }); }); } @@ -125,7 +125,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsTraceResult[] traces = await client.GetTracesAsync(); AssertX.Any(traces, trace => { - Assert.Equal(message, trace.Message); + Assert.Equal(message, trace.Trace.Message); }); }); } @@ -153,7 +153,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsTraceResult[] result = await client.GetTracesAsync(); AssertX.Any(result, trace => { - Assert.Equal(message, trace.Message); + Assert.Equal(message, trace.Trace.Message); Assert.Equal(correlation.TransactionId, trace.Operation.Id); Assert.Equal(correlation.OperationId, trace.Operation.ParentId); }); @@ -183,7 +183,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsTraceResult[] result = await client.GetTracesAsync(); AssertX.Any(result, trace => { - Assert.Equal(message, trace.Message); + Assert.Equal(message, trace.Trace.Message); Assert.Equal(correlation.TransactionId, trace.Operation.Id); Assert.Equal(correlation.OperationId, trace.Operation.ParentId); }); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventTests.cs index 4a1db728..a623cc1a 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventTests.cs @@ -57,7 +57,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsTraceResult[] results = await client.GetTracesAsync(); AssertX.Any(results, trace => { - Assert.Equal(message, trace.Message); + Assert.Equal(message, trace.Trace.Message); Assert.Equal(componentName, trace.RoleName); }); }); @@ -109,7 +109,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsTraceResult[] traceEvents = await client.GetTracesAsync(); AssertX.Any(traceEvents, trace => { - Assert.Equal(message, trace.Message); + Assert.Equal(message, trace.Trace.Message); Assert.Equal(operationId, Assert.Contains(ContextProperties.Correlation.OperationId, trace.CustomDimensions)); Assert.Equal(transactionId, Assert.Contains(ContextProperties.Correlation.TransactionId, trace.CustomDimensions)); Assert.Equal(operationParentId, Assert.Contains(ContextProperties.Correlation.OperationParentId, trace.CustomDimensions)); @@ -145,7 +145,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsTraceResult[] traceEvents = await client.GetTracesAsync(); AssertX.Any(traceEvents, trace => { - Assert.Equal(message, trace.Message); + Assert.Equal(message, trace.Trace.Message); Assert.Equal(nodeName, Assert.Contains(ContextProperties.Kubernetes.NodeName, trace.CustomDimensions)); Assert.Equal(podName, Assert.Contains(ContextProperties.Kubernetes.PodName, trace.CustomDimensions)); Assert.Equal(@namespace, Assert.Contains(ContextProperties.Kubernetes.Namespace, trace.CustomDimensions)); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/ITelemetryQueryClient.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/ITelemetryQueryClient.cs index ce754aa6..b52416c1 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/ITelemetryQueryClient.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/ITelemetryQueryClient.cs @@ -64,16 +64,29 @@ public class EventsTraceResult { public EventsTraceResult(string message, string roleName, OperationResult operation, IDictionary customDimensions) { - Message = message; + Trace = new TraceResult(message); RoleName = roleName; Operation = operation; CustomDimensions = customDimensions; } - public string Message { get; } + public TraceResult Trace { get; } public string RoleName { get; } public OperationResult Operation { get; } public IDictionary CustomDimensions { get; } + + public class TraceResult + { + /// + /// Initializes a new instance of the class. + /// + public TraceResult(string message) + { + Message = message; + } + + public string Message { get; } + } } public class EventsCustomEventResult diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TraceTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TraceTests.cs index 82d544ec..5e9fe948 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TraceTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TraceTests.cs @@ -28,7 +28,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsTraceResult[] results = await client.GetTracesAsync(); AssertX.Any(results, result => { - Assert.Contains(message, result.Message); + Assert.Contains(message, result.Trace.Message); }); }); } @@ -52,7 +52,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsTraceResult[] results = await client.GetTracesAsync(); AssertX.Any(results, result => { - Assert.Contains(message, result.Message); + Assert.Contains(message, result.Trace.Message); Assert.True(result.CustomDimensions.TryGetValue(key, out string actual), "Should contain custom dimension property"); Assert.Equal(expected, actual); }); @@ -78,7 +78,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsTraceResult[] results = await client.GetTracesAsync(); AssertX.Any(results, result => { - Assert.Contains(message, result.Message); + Assert.Contains(message, result.Trace.Message); Assert.True(result.CustomDimensions.TryGetValue(key, out string actual), "Should contain custom dimension property"); Assert.Equal(expected, actual); }); @@ -104,7 +104,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsTraceResult[] results = await client.GetTracesAsync(); AssertX.Any(results, result => { - Assert.Contains(message, result.Message); + Assert.Contains(message, result.Trace.Message); Assert.True(result.CustomDimensions.TryGetValue(key, out string actual), "Should contain custom dimension property"); Assert.Equal(expected, actual); }); From 31270678baf6cf30725bda763ca3912ec5e7ad97 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 1 Aug 2024 10:02:12 +0200 Subject: [PATCH 83/86] pr-fix: use original namespace to reduce changes --- .../ApplicationInsights/AppInsightsClient.cs | 2 +- .../ApplicationInsightsSinkExtensionTests.cs | 42 +++++++++---------- .../ApplicationInsightsSinkTests.cs | 1 + .../AzureFunctionsDockerTests.cs | 2 +- .../AzureKeyVaultDependencyTests.cs | 2 +- .../AzureSearchDependencyTests.cs | 2 +- .../BlobStorageDependencyTests.cs | 2 +- .../CosmosSqlDependencyTests.cs | 2 +- .../CustomDependencyTests.cs | 2 +- .../ApplicationInsights/CustomRequestTests.cs | 2 +- .../EventHubsDependencyTests.cs | 2 +- .../EventHubsRequestTests.cs | 2 +- .../Sinks/ApplicationInsights/EventTests.cs | 2 +- .../ApplicationInsights/ExceptionTests.cs | 2 +- .../Fixture/ITelemetryQueryClient.cs | 20 +++++++-- .../Fixture/InMemoryTelemetryQueryClient.cs | 1 + .../HttpDependencyTests.cs | 2 +- .../HttpRequestDataTests.cs | 4 +- .../Sinks/ApplicationInsights/IoTHubTests.cs | 2 +- .../Sinks/ApplicationInsights/MetricTests.cs | 3 +- .../Sinks/ApplicationInsights/RequestTests.cs | 10 ++--- .../ServiceBusDependencyTests.cs | 2 +- .../ServiceBusRequestTests.cs | 4 +- .../ApplicationInsights/SqlDependencyTests.cs | 2 +- .../TableStorageDependencyTests.cs | 2 +- .../Sinks/ApplicationInsights/TraceTests.cs | 2 +- 26 files changed, 67 insertions(+), 54 deletions(-) diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AppInsightsClient.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AppInsightsClient.cs index 30e09ab1..706a65db 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AppInsightsClient.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AppInsightsClient.cs @@ -3,11 +3,11 @@ using System.Linq; using System.Threading.Tasks; using Arcus.Observability.Tests.Integration.Configuration; -using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; using Arcus.Testing; using Azure.Identity; using Azure.Monitor.Query; using Azure.Monitor.Query.Models; +using Microsoft.Azure.ApplicationInsights.Query.Models; using Newtonsoft.Json; namespace Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsSinkExtensionTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsSinkExtensionTests.cs index 8c79150c..0008d550 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsSinkExtensionTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsSinkExtensionTests.cs @@ -2,9 +2,9 @@ using System.Threading.Tasks; using Arcus.Observability.Correlation; using Arcus.Observability.Telemetry.Core; -using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; using Microsoft.ApplicationInsights; using Microsoft.AspNetCore.Http; +using Microsoft.Azure.ApplicationInsights.Query.Models; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Serilog; @@ -151,11 +151,11 @@ public async Task SinkWithCustomTransactionIdPropertyName_TrackNonRequest_Enrich await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { EventsTraceResult[] result = await client.GetTracesAsync(); - AssertX.Any(result, trace => + AssertX.Any(result, result => { - Assert.Equal(message, trace.Trace.Message); - Assert.Equal(correlation.TransactionId, trace.Operation.Id); - Assert.Equal(correlation.OperationId, trace.Operation.ParentId); + Assert.Equal(message, result.Trace.Message); + Assert.Equal(correlation.TransactionId, result.Operation.Id); + Assert.Equal(correlation.OperationId, result.Operation.ParentId); }); }); } @@ -181,11 +181,11 @@ public async Task SinkWithCustomOperationIdPropertyName_TrackNonRequest_EnrichCo await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { EventsTraceResult[] result = await client.GetTracesAsync(); - AssertX.Any(result, trace => + AssertX.Any(result, result => { - Assert.Equal(message, trace.Trace.Message); - Assert.Equal(correlation.TransactionId, trace.Operation.Id); - Assert.Equal(correlation.OperationId, trace.Operation.ParentId); + Assert.Equal(message, result.Trace.Message); + Assert.Equal(correlation.TransactionId, result.Operation.Id); + Assert.Equal(correlation.OperationId, result.Operation.ParentId); }); }); } @@ -218,11 +218,11 @@ public async Task SinkWithCustomTransactionIdPropertyName_TrackRequest_EnrichCor await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { EventsRequestResult[] result = await client.GetRequestsAsync(); - AssertX.Any(result, request => + AssertX.Any(result, result => { - Assert.Equal(correlation.TransactionId, request.Operation.Id); - Assert.Equal(correlation.OperationId, request.Id); - Assert.Equal(correlation.OperationParentId, request.Operation.ParentId); + Assert.Equal(correlation.TransactionId, result.Operation.Id); + Assert.Equal(correlation.OperationId, result.Request.Id); + Assert.Equal(correlation.OperationParentId, result.Operation.ParentId); }); }); } @@ -255,11 +255,11 @@ public async Task SinkWithCustomOperationIdPropertyName_TrackRequest_EnrichCorre await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { EventsRequestResult[] result = await client.GetRequestsAsync(); - AssertX.Any(result, request => + AssertX.Any(result, result => { - Assert.Equal(correlation.TransactionId, request.Operation.Id); - Assert.Equal(correlation.OperationId, request.Id); - Assert.Equal(correlation.OperationParentId, request.Operation.ParentId); + Assert.Equal(correlation.TransactionId, result.Operation.Id); + Assert.Equal(correlation.OperationId, result.Request.Id); + Assert.Equal(correlation.OperationParentId, result.Operation.ParentId); }); }); } @@ -292,11 +292,11 @@ public async Task SinkWithCustomOperationParentIdPropertyName_TrackRequest_Enric await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { EventsRequestResult[] result = await client.GetRequestsAsync(); - AssertX.Any(result, request => + AssertX.Any(result, result => { - Assert.Equal(correlation.TransactionId, request.Operation.Id); - Assert.Equal(correlation.OperationId, request.Id); - Assert.Equal(correlation.OperationParentId, request.Operation.ParentId); + Assert.Equal(correlation.TransactionId, result.Operation.Id); + Assert.Equal(correlation.OperationId, result.Request.Id); + Assert.Equal(correlation.OperationParentId, result.Operation.ParentId); }); }); } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsSinkTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsSinkTests.cs index b707d702..202d72cc 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsSinkTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ApplicationInsightsSinkTests.cs @@ -7,6 +7,7 @@ using Arcus.Testing; using Bogus; using GuardNet; +using Microsoft.Azure.ApplicationInsights.Query.Models; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Serilog; diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureFunctionsDockerTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureFunctionsDockerTests.cs index eab4e718..87138a4f 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureFunctionsDockerTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureFunctionsDockerTests.cs @@ -1,5 +1,5 @@ using System.Threading.Tasks; -using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; +using Microsoft.Azure.ApplicationInsights.Query.Models; using Xunit; using Xunit.Abstractions; diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureKeyVaultDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureKeyVaultDependencyTests.cs index 8213e560..e0f9fb59 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureKeyVaultDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureKeyVaultDependencyTests.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; +using Microsoft.Azure.ApplicationInsights.Query.Models; using Microsoft.Extensions.Logging; using Xunit; using Xunit.Abstractions; diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureSearchDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureSearchDependencyTests.cs index 367b813d..da5903c8 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureSearchDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureSearchDependencyTests.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; +using Microsoft.Azure.ApplicationInsights.Query.Models; using Microsoft.Extensions.Logging; using Xunit; using Xunit.Abstractions; diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/BlobStorageDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/BlobStorageDependencyTests.cs index e8f110a6..3794b919 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/BlobStorageDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/BlobStorageDependencyTests.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; +using Microsoft.Azure.ApplicationInsights.Query.Models; using Microsoft.Extensions.Logging; using Serilog; using Xunit; diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CosmosSqlDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CosmosSqlDependencyTests.cs index af9b95bc..fbefc423 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CosmosSqlDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CosmosSqlDependencyTests.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; +using Microsoft.Azure.ApplicationInsights.Query.Models; using Microsoft.Extensions.Logging; using Serilog; using Xunit; diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomDependencyTests.cs index a8b3ced4..8e8ccd24 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomDependencyTests.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; +using Microsoft.Azure.ApplicationInsights.Query.Models; using Microsoft.Extensions.Logging; using Xunit; using Xunit.Abstractions; diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomRequestTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomRequestTests.cs index 3e845536..cf9f6bab 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomRequestTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomRequestTests.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; +using Microsoft.Azure.ApplicationInsights.Query.Models; using Microsoft.Extensions.Logging; using Serilog; using Xunit; diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsDependencyTests.cs index 7669b5e3..553dd37e 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsDependencyTests.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; +using Microsoft.Azure.ApplicationInsights.Query.Models; using Microsoft.Extensions.Logging; using Serilog; using Xunit; diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsRequestTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsRequestTests.cs index b65b8a47..227807b6 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsRequestTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsRequestTests.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; +using Microsoft.Azure.ApplicationInsights.Query.Models; using Microsoft.Extensions.Logging; using Serilog; using Xunit; diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventTests.cs index a623cc1a..c693cab2 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventTests.cs @@ -5,7 +5,7 @@ using Arcus.Observability.Telemetry.Core; using Arcus.Observability.Telemetry.Serilog.Enrichers; using Arcus.Observability.Tests.Core; -using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; +using Microsoft.Azure.ApplicationInsights.Query.Models; using Microsoft.Extensions.Logging; using Serilog; using Xunit; diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ExceptionTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ExceptionTests.cs index 15f3f194..348a510f 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ExceptionTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ExceptionTests.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; using Arcus.Observability.Correlation; using Arcus.Observability.Tests.Integration.Fixture; -using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; +using Microsoft.Azure.ApplicationInsights.Query.Models; using Microsoft.Extensions.Logging; using Serilog; using Xunit; diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/ITelemetryQueryClient.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/ITelemetryQueryClient.cs index b52416c1..f6cae167 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/ITelemetryQueryClient.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/ITelemetryQueryClient.cs @@ -2,7 +2,7 @@ using System.Collections.ObjectModel; using System.Threading.Tasks; -namespace Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture +namespace Microsoft.Azure.ApplicationInsights.Query.Models { /// /// Represents a client to query telemetry data from the Azure Application Insights instance. @@ -40,7 +40,7 @@ public interface ITelemetryQueryClient Task GetExceptionsAsync(); } - public class OperationResult + public class OperationResult { public OperationResult(string id, string parentId) { @@ -133,7 +133,7 @@ public EventsRequestResult( OperationResult operation, IDictionary customDimensions) { - Id = id; + Request = new RequestResult(id); Name = name; Source = source; Url = url; @@ -144,7 +144,7 @@ public EventsRequestResult( CustomDimensions = customDimensions; } - public string Id { get; } + public RequestResult Request { get; } public string Name { get; } public string Source { get; } public string Url { get; } @@ -153,6 +153,18 @@ public EventsRequestResult( public string RoleName { get; } public OperationResult Operation { get; } public IDictionary CustomDimensions { get; } + + public class RequestResult + { + /// + /// Initializes a new instance of the class. + /// + public RequestResult(string id) + { + Id = id; + } + public string Id { get; } + } } public class EventsDependencyResult diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/InMemoryTelemetryQueryClient.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/InMemoryTelemetryQueryClient.cs index de08f42e..314c5536 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/InMemoryTelemetryQueryClient.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/InMemoryTelemetryQueryClient.cs @@ -1,6 +1,7 @@ using System.Linq; using System.Threading.Tasks; using GuardNet; +using Microsoft.Azure.ApplicationInsights.Query.Models; namespace Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture { diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpDependencyTests.cs index 2c056a8e..facb17fa 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpDependencyTests.cs @@ -4,8 +4,8 @@ using System.Net.Http; using System.Threading.Tasks; using Arcus.Observability.Correlation; -using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; using Microsoft.AspNetCore.Http; +using Microsoft.Azure.ApplicationInsights.Query.Models; using Microsoft.Extensions.Logging; using Moq; using Serilog; diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpRequestDataTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpRequestDataTests.cs index 2acf361c..47760b67 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpRequestDataTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpRequestDataTests.cs @@ -4,7 +4,7 @@ using System.Net.Http; using System.Threading.Tasks; using Arcus.Observability.Correlation; -using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; +using Microsoft.Azure.ApplicationInsights.Query.Models; using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker.Http; using Microsoft.Extensions.Logging; @@ -53,7 +53,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => Assert.Equal(((int) statusCode).ToString(), result.ResultCode); Assert.Equal($"{httpMethod.Method} {operationName}", result.Operation.Name); - Assert.Equal(correlation.OperationId, result.Id); + Assert.Equal(correlation.OperationId, result.Request.Id); Assert.Equal(correlation.TransactionId, result.Operation.Id); Assert.Equal(correlation.OperationParentId, result.Operation.ParentId); }); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/IoTHubTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/IoTHubTests.cs index 9aa76ac7..9c1ac4df 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/IoTHubTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/IoTHubTests.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; +using Microsoft.Azure.ApplicationInsights.Query.Models; using Microsoft.Extensions.Logging; using Serilog; using Xunit; diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/MetricTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/MetricTests.cs index c44fdc35..cad5bdfb 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/MetricTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/MetricTests.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using System.Threading.Tasks; -using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; -using Azure.Monitor.Query.Models; +using Microsoft.Azure.ApplicationInsights.Query.Models; using Microsoft.Extensions.Logging; using Xunit; using Xunit.Abstractions; diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/RequestTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/RequestTests.cs index 38746321..d26365ca 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/RequestTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/RequestTests.cs @@ -5,8 +5,8 @@ using System.Threading.Tasks; using Arcus.Observability.Correlation; using Arcus.Observability.Telemetry.Core; -using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; using Microsoft.AspNetCore.Http; +using Microsoft.Azure.ApplicationInsights.Query.Models; using Microsoft.Extensions.Logging; using Moq; using Serilog; @@ -54,7 +54,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => Assert.Equal(((int) statusCode).ToString(), result.ResultCode); Assert.Equal($"{httpMethod.Method} {operationName}", result.Operation.Name); - Assert.Equal(correlation.OperationId, result.Id); + Assert.Equal(correlation.OperationId, result.Request.Id); Assert.Equal(correlation.TransactionId, result.Operation.Id); Assert.Equal(correlation.OperationParentId, result.Operation.ParentId); }); @@ -158,7 +158,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Url); Assert.Equal(((int)statusCode).ToString(), result.ResultCode); - Assert.Equal(requestId, result.Id); + Assert.Equal(requestId, result.Request.Id); }); }); } @@ -193,9 +193,9 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { Assert.Equal(requestUri.ToString(), result.Url); Assert.Equal(((int)statusCode).ToString(), result.ResultCode); - Assert.Equal(requestId, result.Id); + Assert.Equal(requestId, result.Request.Id); Assert.Equal($"{httpMethod.Method} {operationName}", result.Operation.Name); - Assert.Equal(requestId, result.Id); + Assert.Equal(requestId, result.Request.Id); }); }); } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusDependencyTests.cs index c60dd1a0..00848a9a 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusDependencyTests.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; using Arcus.Observability.Correlation; using Arcus.Observability.Telemetry.Core; -using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; +using Microsoft.Azure.ApplicationInsights.Query.Models; using Microsoft.Extensions.Logging; using Serilog; using Xunit; diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusRequestTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusRequestTests.cs index 0fec918a..e51a8e55 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusRequestTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusRequestTests.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; using Arcus.Observability.Correlation; using Arcus.Observability.Telemetry.Core; -using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; +using Microsoft.Azure.ApplicationInsights.Query.Models; using Microsoft.Extensions.Logging; using Serilog; using Xunit; @@ -54,7 +54,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => AssertContainsCustomDimension(result.CustomDimensions, ContextProperties.RequestTracking.ServiceBus.EntityName, queueName); AssertContainsCustomDimension(result.CustomDimensions, ContextProperties.RequestTracking.ServiceBus.Endpoint, serviceBusNamespace); - Assert.Equal(correlation.OperationId, result.Id); + Assert.Equal(correlation.OperationId, result.Request.Id); Assert.Equal(correlation.TransactionId, result.Operation.Id); Assert.Equal(correlation.OperationParentId, result.Operation.ParentId); }); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/SqlDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/SqlDependencyTests.cs index ac0d53dc..f84d4b67 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/SqlDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/SqlDependencyTests.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; +using Microsoft.Azure.ApplicationInsights.Query.Models; using Microsoft.Extensions.Logging; using Xunit; using Xunit.Abstractions; diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TableStorageDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TableStorageDependencyTests.cs index 4e0b7b09..826de28e 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TableStorageDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TableStorageDependencyTests.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; +using Microsoft.Azure.ApplicationInsights.Query.Models; using Microsoft.Extensions.Logging; using Serilog; using Xunit; diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TraceTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TraceTests.cs index 5e9fe948..47889629 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TraceTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TraceTests.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; using System.Threading.Tasks; -using Arcus.Observability.Tests.Integration.Serilog.Sinks.ApplicationInsights.Fixture; +using Microsoft.Azure.ApplicationInsights.Query.Models; using Microsoft.Extensions.Logging; using Xunit; using Xunit.Abstractions; From d0e94e41e9e02ad2ccd6e788ed203b9b4b7c5208 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 1 Aug 2024 10:26:43 +0200 Subject: [PATCH 84/86] pr-fix: reduce request, dependency and exception changes --- .../AzureFunctionsDockerTests.cs | 2 +- .../AzureKeyVaultDependencyTests.cs | 10 +-- .../AzureSearchDependencyTests.cs | 10 +-- .../BlobStorageDependencyTests.cs | 10 +-- .../CosmosSqlDependencyTests.cs | 8 +-- .../CustomDependencyTests.cs | 14 ++-- .../ApplicationInsights/CustomRequestTests.cs | 6 +- .../EventHubsDependencyTests.cs | 10 +-- .../EventHubsRequestTests.cs | 8 +-- .../ApplicationInsights/ExceptionTests.cs | 16 ++--- .../Fixture/ITelemetryQueryClient.cs | 66 +++++++++++++------ .../HttpDependencyTests.cs | 24 +++---- .../HttpRequestDataTests.cs | 2 +- .../Sinks/ApplicationInsights/IoTHubTests.cs | 16 ++--- .../Sinks/ApplicationInsights/RequestTests.cs | 12 ++-- .../ServiceBusDependencyTests.cs | 16 ++--- .../ServiceBusRequestTests.cs | 34 +++++----- .../ApplicationInsights/SqlDependencyTests.cs | 20 +++--- .../TableStorageDependencyTests.cs | 10 +-- 19 files changed, 160 insertions(+), 134 deletions(-) diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureFunctionsDockerTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureFunctionsDockerTests.cs index 87138a4f..57eb738a 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureFunctionsDockerTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureFunctionsDockerTests.cs @@ -28,7 +28,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => AssertX.Any(results, result => { Assert.Equal("200", result.ResultCode); - Assert.Equal("Timer", result.Source); + Assert.Equal("Timer", result.Request.Source); Assert.Equal("Triggered", result.Operation.Name); }); }); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureKeyVaultDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureKeyVaultDependencyTests.cs index e0f9fb59..49003997 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureKeyVaultDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureKeyVaultDependencyTests.cs @@ -40,11 +40,11 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal(dependencyType, result.Type); - Assert.Equal(dependencyId, result.Id); - Assert.Equal(vaultUri, result.Target); - Assert.Equal(secretName, result.Data); - Assert.Equal(dependencyName, result.Name); + Assert.Equal(dependencyType, result.Dependency.Type); + Assert.Equal(dependencyId, result.Dependency.Id); + Assert.Equal(vaultUri, result.Dependency.Target); + Assert.Equal(secretName, result.Dependency.Data); + Assert.Equal(dependencyName, result.Dependency.Name); }); }); } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureSearchDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureSearchDependencyTests.cs index da5903c8..822c905e 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureSearchDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureSearchDependencyTests.cs @@ -41,11 +41,11 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal(dependencyType, result.Type); - Assert.Equal(dependencyId, result.Id); - Assert.Equal(searchServiceName, result.Target); - Assert.Equal(operationName, result.Data); - Assert.Equal(dependencyName, result.Name); + Assert.Equal(dependencyType, result.Dependency.Type); + Assert.Equal(dependencyId, result.Dependency.Id); + Assert.Equal(searchServiceName, result.Dependency.Target); + Assert.Equal(operationName, result.Dependency.Data); + Assert.Equal(dependencyName, result.Dependency.Name); }); }); } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/BlobStorageDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/BlobStorageDependencyTests.cs index 3794b919..c51e222d 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/BlobStorageDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/BlobStorageDependencyTests.cs @@ -42,12 +42,12 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal(dependencyType, result.Type); - Assert.Equal(accountName, result.Target); - Assert.Equal(containerName, result.Data); + Assert.Equal(dependencyType, result.Dependency.Type); + Assert.Equal(accountName, result.Dependency.Target); + Assert.Equal(containerName, result.Dependency.Data); Assert.Equal(componentName, result.RoleName); - Assert.Equal(dependencyName, result.Name); - Assert.Equal(dependencyId, result.Id); + Assert.Equal(dependencyName, result.Dependency.Name); + Assert.Equal(dependencyId, result.Dependency.Id); }); }); } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CosmosSqlDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CosmosSqlDependencyTests.cs index fbefc423..3d650970 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CosmosSqlDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CosmosSqlDependencyTests.cs @@ -44,11 +44,11 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => Assert.NotEmpty(results); AssertX.Any(results, result => { - Assert.Equal(dependencyType, result.Type); - Assert.Equal(accountName, result.Target); - Assert.Equal(dependencyName, result.Data); + Assert.Equal(dependencyType, result.Dependency.Type); + Assert.Equal(accountName, result.Dependency.Target); + Assert.Equal(dependencyName, result.Dependency.Data); Assert.Equal(componentName, result.RoleName); - Assert.Equal(dependencyName, result.Name); + Assert.Equal(dependencyName, result.Dependency.Name); }); }); } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomDependencyTests.cs index 8e8ccd24..c0c9fd17 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomDependencyTests.cs @@ -36,9 +36,9 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal(dependencyType, result.Type); - Assert.Equal(dependencyData, result.Data); - Assert.Equal(dependencyId, result.Id); + Assert.Equal(dependencyType, result.Dependency.Type); + Assert.Equal(dependencyData, result.Dependency.Data); + Assert.Equal(dependencyId, result.Dependency.Id); }); }); } @@ -68,10 +68,10 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal(dependencyType, result.Type); - Assert.Equal(dependencyData, result.Data); - Assert.Equal(dependencyName, result.Name); - Assert.Equal(dependencyId, result.Id); + Assert.Equal(dependencyType, result.Dependency.Type); + Assert.Equal(dependencyData, result.Dependency.Data); + Assert.Equal(dependencyName, result.Dependency.Name); + Assert.Equal(dependencyId, result.Dependency.Id); Assert.Equal(isSuccessful, result.Success); Assert.All(telemetryContext, item => Assert.Equal(item.Value.ToString(), Assert.Contains(item.Key, result.CustomDimensions))); }); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomRequestTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomRequestTests.cs index cf9f6bab..672ce8d6 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomRequestTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomRequestTests.cs @@ -39,9 +39,9 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsRequestResult[] requests = await client.GetRequestsAsync(); AssertX.Any(requests, result => { - Assert.Equal(operationName, result.Name); - Assert.Contains(customRequestSource, result.Source); - Assert.True(string.IsNullOrWhiteSpace(result.Url), "request URL should be blank"); + Assert.Equal(operationName, result.Request.Name); + Assert.Contains(customRequestSource, result.Request.Source); + Assert.True(string.IsNullOrWhiteSpace(result.Request.Url), "request URL should be blank"); Assert.Equal(operationName, result.Operation.Name); Assert.Equal(isSuccessful, result.Success); Assert.Equal(componentName, result.RoleName); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsDependencyTests.cs index 553dd37e..b8cb3276 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsDependencyTests.cs @@ -42,12 +42,12 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal(dependencyType, result.Type); - Assert.Equal(eventHubName, result.Target); - Assert.Equal(namespaceName, result.Data); + Assert.Equal(dependencyType, result.Dependency.Type); + Assert.Equal(eventHubName, result.Dependency.Target); + Assert.Equal(namespaceName, result.Dependency.Data); Assert.Equal(componentName, result.RoleName); - Assert.Equal(dependencyName, result.Name); - Assert.Equal(dependencyId, result.Id); + Assert.Equal(dependencyName, result.Dependency.Name); + Assert.Equal(dependencyId, result.Dependency.Id); }); }); } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsRequestTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsRequestTests.cs index 227807b6..6d1ed36e 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsRequestTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsRequestTests.cs @@ -42,10 +42,10 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsRequestResult[] requests = await client.GetRequestsAsync(); AssertX.Any(requests, result => { - Assert.Equal(operationName, result.Name); - Assert.Contains(eventHubsName, result.Source); - Assert.Contains(eventHubsNamespace, result.Source); - Assert.True(string.IsNullOrWhiteSpace(result.Url), "request URL should be blank"); + Assert.Equal(operationName, result.Request.Name); + Assert.Contains(eventHubsName, result.Request.Source); + Assert.Contains(eventHubsNamespace, result.Request.Source); + Assert.True(string.IsNullOrWhiteSpace(result.Request.Url), "request URL should be blank"); Assert.Equal(operationName, result.Operation.Name); Assert.Equal(isSuccessful, result.Success); Assert.Equal(componentName, result.RoleName); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ExceptionTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ExceptionTests.cs index 348a510f..e22dd7c2 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ExceptionTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ExceptionTests.cs @@ -34,7 +34,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsExceptionResult[] results = await client.GetExceptionsAsync(); AssertX.Any(results, result => { - Assert.Equal(exception.Message, result.Message); + Assert.Equal(exception.Message, result.Exception.OuterMessage); Assert.DoesNotContain($"Exception-{nameof(TestException.SpyProperty)}", result.CustomDimensions.Keys); }); }); @@ -58,7 +58,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsExceptionResult[] results = await client.GetExceptionsAsync(); AssertX.Any(results, result => { - Assert.Equal(exception.Message, result.Message); + Assert.Equal(exception.Message, result.Exception.OuterMessage); Assert.Equal(expectedProperty, Assert.Contains($"Exception-{nameof(TestException.SpyProperty)}", result.CustomDimensions)); }); }); @@ -87,7 +87,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { string propertyName = string.Format(propertyFormat, nameof(TestException.SpyProperty)); - Assert.Equal(exception.Message, result.Message); + Assert.Equal(exception.Message, result.Exception.OuterMessage); Assert.Equal(expectedProperty, Assert.Contains(propertyName, result.CustomDimensions)); }); }); @@ -111,7 +111,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsExceptionResult[] results = await client.GetExceptionsAsync(); AssertX.Any(results, result => { - Assert.Equal(exception.Message, result.Message); + Assert.Equal(exception.Message, result.Exception.OuterMessage); Assert.Equal(componentName, result.RoleName); }); }); @@ -141,7 +141,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsExceptionResult[] results = await client.GetExceptionsAsync(); AssertX.Any(results, result => { - Assert.Equal(exception.Message, result.Message); + Assert.Equal(exception.Message, result.Exception.OuterMessage); Assert.Equal(transactionId, result.Operation.Id); Assert.Equal(operationId, result.Operation.ParentId); }); @@ -168,7 +168,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsExceptionResult[] results = await client.GetExceptionsAsync(); AssertX.Any(results, result => { - Assert.Equal(exception.Message, result.Message); + Assert.Equal(exception.Message, result.Exception.OuterMessage); Assert.True(result.CustomDimensions.TryGetValue(key, out string actual), "Should contain custom dimension property"); Assert.Equal(expected, actual); }); @@ -195,7 +195,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsExceptionResult[] results = await client.GetExceptionsAsync(); AssertX.Any(results, result => { - Assert.Equal(exception.Message, result.Message); + Assert.Equal(exception.Message, result.Exception.OuterMessage); Assert.True(result.CustomDimensions.TryGetValue(key, out string actual), "Should contain custom dimension property"); Assert.Equal(expected, actual); }); @@ -222,7 +222,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsExceptionResult[] results = await client.GetExceptionsAsync(); AssertX.Any(results, result => { - Assert.Equal(exception.Message, result.Message); + Assert.Equal(exception.Message, result.Exception.OuterMessage); Assert.True(result.CustomDimensions.TryGetValue(key, out string actual), "Should contain custom dimension property"); Assert.Equal(expected, actual); }); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/ITelemetryQueryClient.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/ITelemetryQueryClient.cs index f6cae167..7a158a20 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/ITelemetryQueryClient.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/ITelemetryQueryClient.cs @@ -133,10 +133,7 @@ public EventsRequestResult( OperationResult operation, IDictionary customDimensions) { - Request = new RequestResult(id); - Name = name; - Source = source; - Url = url; + Request = new RequestResult(id, name, source, url); Success = success; ResultCode = resultCode; RoleName = roleName; @@ -145,9 +142,6 @@ public EventsRequestResult( } public RequestResult Request { get; } - public string Name { get; } - public string Source { get; } - public string Url { get; } public bool Success { get; } public string ResultCode { get; } public string RoleName { get; } @@ -159,11 +153,18 @@ public class RequestResult /// /// Initializes a new instance of the class. /// - public RequestResult(string id) + public RequestResult(string id, string name, string source, string url) { Id = id; + Name = name; + Source = source; + Url = url; } public string Id { get; } + public string Name { get; } + public string Source { get; } + public string Url { get; } + } } @@ -181,28 +182,41 @@ public EventsDependencyResult( OperationResult operation, IDictionary customDimensions) { - Id = id; - Type = type; - Target = target; - Data = data; + Dependency = new DependencyResult(id, name, type, target, data); Success = success; ResultCode = resultCode; - Name = name; RoleName = roleName; Operation = operation; CustomDimensions = customDimensions; } - public string Type { get; } - public string Id { get; } - public string Target { get; } - public string Data { get; } + public DependencyResult Dependency { get; } public bool Success { get; } public int ResultCode { get; } - public string Name { get; } public string RoleName { get; } public OperationResult Operation { get; } public IDictionary CustomDimensions { get; } + + public class DependencyResult + { + /// + /// Initializes a new instance of the class. + /// + public DependencyResult(string id, string name, string type, string target, string data) + { + Id = id; + Name = name; + Type = type; + Target = target; + Data = data; + } + + public string Id { get; } + public string Name { get; } + public string Type { get; } + public string Target { get; } + public string Data { get; } + } } public class EventsExceptionResult @@ -212,16 +226,28 @@ public class EventsExceptionResult /// public EventsExceptionResult(string message, OperationResult operation, string roleName, IDictionary customDimensions) { - Message = message; + Exception = new ExceptionResult(message); Operation = operation; RoleName = roleName; CustomDimensions = customDimensions; } - public string Message { get; } + public ExceptionResult Exception { get; } public OperationResult Operation { get; } public string RoleName { get; } public IDictionary CustomDimensions { get; } + public class ExceptionResult + { + /// + /// Initializes a new instance of the class. + /// + public ExceptionResult(string message) + { + OuterMessage = message; + } + + public string OuterMessage { get; } + } } } \ No newline at end of file diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpDependencyTests.cs index facb17fa..cfea9f7f 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpDependencyTests.cs @@ -53,10 +53,10 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal(DependencyType, result.Type, StringComparer.OrdinalIgnoreCase); - Assert.Equal(requestUri.Host, result.Target); - Assert.Equal($"{httpMethod} {requestUri.AbsolutePath}", result.Name); - Assert.Equal(dependencyId, result.Id); + Assert.Equal(DependencyType, result.Dependency.Type, StringComparer.OrdinalIgnoreCase); + Assert.Equal(requestUri.Host, result.Dependency.Target); + Assert.Equal($"{httpMethod} {requestUri.AbsolutePath}", result.Dependency.Name); + Assert.Equal(dependencyId, result.Dependency.Id); Assert.Equal(componentName, result.RoleName); Assert.Equal(correlation.OperationId, result.Operation.ParentId); @@ -92,10 +92,10 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal(DependencyType, result.Type, StringComparer.OrdinalIgnoreCase); - Assert.Equal(requestUri.Host, result.Target); - Assert.Equal($"{httpMethod} {requestUri.AbsolutePath}", result.Name); - Assert.Equal(dependencyId, result.Id); + Assert.Equal(DependencyType, result.Dependency.Type, StringComparer.OrdinalIgnoreCase); + Assert.Equal(requestUri.Host, result.Dependency.Target); + Assert.Equal($"{httpMethod} {requestUri.AbsolutePath}", result.Dependency.Name); + Assert.Equal(dependencyId, result.Dependency.Id); Assert.Equal(componentName, result.RoleName); }); }); @@ -132,10 +132,10 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal(DependencyType, result.Type, StringComparer.OrdinalIgnoreCase); - Assert.Equal(request.Host.Host, result.Target); - Assert.Equal($"{httpMethod} {request.Path}", result.Name); - Assert.Equal(dependencyId, result.Id); + Assert.Equal(DependencyType, result.Dependency.Type, StringComparer.OrdinalIgnoreCase); + Assert.Equal(request.Host.Host, result.Dependency.Target); + Assert.Equal($"{httpMethod} {request.Path}", result.Dependency.Name); + Assert.Equal(dependencyId, result.Dependency.Id); }); }); } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpRequestDataTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpRequestDataTests.cs index 47760b67..04f0b7e2 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpRequestDataTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpRequestDataTests.cs @@ -49,7 +49,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsRequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { - Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Url); + Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Request.Url); Assert.Equal(((int) statusCode).ToString(), result.ResultCode); Assert.Equal($"{httpMethod.Method} {operationName}", result.Operation.Name); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/IoTHubTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/IoTHubTests.cs index 9c1ac4df..4b7f7f74 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/IoTHubTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/IoTHubTests.cs @@ -40,11 +40,11 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal("Azure IoT Hub", result.Type); - Assert.Equal(iotHubName, result.Target); + Assert.Equal("Azure IoT Hub", result.Dependency.Type); + Assert.Equal(iotHubName, result.Dependency.Target); Assert.Equal(componentName, result.RoleName); - Assert.Equal(dependencyName, result.Name); - Assert.Equal(dependencyId, result.Id); + Assert.Equal(dependencyName, result.Dependency.Name); + Assert.Equal(dependencyId, result.Dependency.Id); }); }); } @@ -75,11 +75,11 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal("Azure IoT Hub", result.Type); - Assert.Equal(hostName, result.Target); + Assert.Equal("Azure IoT Hub", result.Dependency.Type); + Assert.Equal(hostName, result.Dependency.Target); Assert.Equal(componentName, result.RoleName); - Assert.Equal(dependencyName, result.Name); - Assert.Equal(dependencyId, result.Id); + Assert.Equal(dependencyName, result.Dependency.Name); + Assert.Equal(dependencyId, result.Dependency.Id); }); }); } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/RequestTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/RequestTests.cs index d26365ca..755a6bd3 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/RequestTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/RequestTests.cs @@ -50,7 +50,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsRequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { - Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Url); + Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Request.Url); Assert.Equal(((int) statusCode).ToString(), result.ResultCode); Assert.Equal($"{httpMethod.Method} {operationName}", result.Operation.Name); @@ -85,7 +85,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsRequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { - Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Url); + Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Request.Url); Assert.Equal(((int) statusCode).ToString(), result.ResultCode); Assert.Equal($"{httpMethod.Method} {operationName}", result.Operation.Name); }); @@ -120,7 +120,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsRequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { - Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Url); + Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Request.Url); Assert.Equal(((int)statusCode).ToString(), result.ResultCode); Assert.StartsWith(httpMethod.Method, result.Operation.Name); }); @@ -156,7 +156,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsRequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { - Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Url); + Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Request.Url); Assert.Equal(((int)statusCode).ToString(), result.ResultCode); Assert.Equal(requestId, result.Request.Id); }); @@ -191,7 +191,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsRequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { - Assert.Equal(requestUri.ToString(), result.Url); + Assert.Equal(requestUri.ToString(), result.Request.Url); Assert.Equal(((int)statusCode).ToString(), result.ResultCode); Assert.Equal(requestId, result.Request.Id); Assert.Equal($"{httpMethod.Method} {operationName}", result.Operation.Name); @@ -225,7 +225,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsRequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { - Assert.Equal(requestUri.ToString(), result.Url); + Assert.Equal(requestUri.ToString(), result.Request.Url); Assert.Equal(((int)statusCode).ToString(), result.ResultCode); Assert.Equal($"{httpMethod.Method} {operationName}", result.Operation.Name); }); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusDependencyTests.cs index 00848a9a..1453a6e2 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusDependencyTests.cs @@ -47,10 +47,10 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal(dependencyType, result.Type); - Assert.Contains(entityName, result.Target); - Assert.Equal(dependencyName, result.Name); - Assert.Equal(dependencyId, result.Id); + Assert.Equal(dependencyType, result.Dependency.Type); + Assert.Contains(entityName, result.Dependency.Target); + Assert.Equal(dependencyName, result.Dependency.Name); + Assert.Equal(dependencyId, result.Dependency.Id); AssertContainsCustomDimension(result.CustomDimensions, ContextProperties.DependencyTracking.ServiceBus.EntityType, entityType.ToString()); AssertContainsCustomDimension(result.CustomDimensions, ContextProperties.DependencyTracking.ServiceBus.Endpoint, namespaceEndpoint); @@ -86,10 +86,10 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal(dependencyType, result.Type); - Assert.Contains(entityName, result.Target); - Assert.Equal(dependencyName, result.Name); - Assert.Equal(dependencyId, result.Id); + Assert.Equal(dependencyType, result.Dependency.Type); + Assert.Contains(entityName, result.Dependency.Target); + Assert.Equal(dependencyName, result.Dependency.Name); + Assert.Equal(dependencyId, result.Dependency.Id); AssertContainsCustomDimension(result.CustomDimensions, ContextProperties.DependencyTracking.ServiceBus.EntityType, entityType.ToString()); AssertContainsCustomDimension(result.CustomDimensions, ContextProperties.DependencyTracking.ServiceBus.Endpoint, namespaceEndpoint); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusRequestTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusRequestTests.cs index e51a8e55..4dcbbe02 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusRequestTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ServiceBusRequestTests.cs @@ -43,10 +43,10 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsRequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { - Assert.Equal(operationName, result.Name); - Assert.Contains(queueName, result.Source); - Assert.Contains(serviceBusNamespace, result.Source); - Assert.True(string.IsNullOrWhiteSpace(result.Url), "request URL should be blank"); + Assert.Equal(operationName, result.Request.Name); + Assert.Contains(queueName, result.Request.Source); + Assert.Contains(serviceBusNamespace, result.Request.Source); + Assert.True(string.IsNullOrWhiteSpace(result.Request.Url), "request URL should be blank"); Assert.Equal(operationName, result.Operation.Name); Assert.Equal(isSuccessful, result.Success); @@ -82,10 +82,10 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsRequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { - Assert.Equal(operationName, result.Name); - Assert.Contains(queueName, result.Source); - Assert.Contains(serviceBusNamespace, result.Source); - Assert.True(string.IsNullOrWhiteSpace(result.Url), "request URL should be blank"); + Assert.Equal(operationName, result.Request.Name); + Assert.Contains(queueName, result.Request.Source); + Assert.Contains(serviceBusNamespace, result.Request.Source); + Assert.True(string.IsNullOrWhiteSpace(result.Request.Url), "request URL should be blank"); Assert.Equal(operationName, result.Operation.Name); Assert.Equal(isSuccessful, result.Success); @@ -119,11 +119,11 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsRequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { - Assert.Equal(operationName, result.Name); - Assert.Contains(topicName, result.Source); - Assert.Contains(serviceBusNamespace, result.Source); - Assert.Contains(serviceBusNamespaceSuffix, result.Source); - Assert.True(string.IsNullOrWhiteSpace(result.Url), "request URL should be blank"); + Assert.Equal(operationName, result.Request.Name); + Assert.Contains(topicName, result.Request.Source); + Assert.Contains(serviceBusNamespace, result.Request.Source); + Assert.Contains(serviceBusNamespaceSuffix, result.Request.Source); + Assert.True(string.IsNullOrWhiteSpace(result.Request.Url), "request URL should be blank"); Assert.Equal(operationName, result.Operation.Name); Assert.Equal(isSuccessful, result.Success); @@ -159,10 +159,10 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsRequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { - Assert.Equal(operationName, result.Name); - Assert.Contains(entityName, result.Source); - Assert.Contains(serviceBusNamespace, result.Source); - Assert.True(string.IsNullOrWhiteSpace(result.Url), "request URL should be blank"); + Assert.Equal(operationName, result.Request.Name); + Assert.Contains(entityName, result.Request.Source); + Assert.Contains(serviceBusNamespace, result.Request.Source); + Assert.True(string.IsNullOrWhiteSpace(result.Request.Url), "request URL should be blank"); Assert.Equal(operationName, result.Operation.Name); Assert.Equal(isSuccessful, result.Success); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/SqlDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/SqlDependencyTests.cs index f84d4b67..84cc7304 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/SqlDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/SqlDependencyTests.cs @@ -40,11 +40,11 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal(dependencyType, result.Type, StringComparer.OrdinalIgnoreCase); - Assert.Equal(serverName, result.Target); - Assert.Contains(databaseName, result.Name); - Assert.Contains(operationName, result.Name); - Assert.Equal(dependencyId, result.Id); + Assert.Equal(dependencyType, result.Dependency.Type, StringComparer.OrdinalIgnoreCase); + Assert.Equal(serverName, result.Dependency.Target); + Assert.Contains(databaseName, result.Dependency.Name); + Assert.Contains(operationName, result.Dependency.Name); + Assert.Equal(dependencyId, result.Dependency.Id); }); }); } @@ -76,11 +76,11 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal(dependencyType, result.Type, StringComparer.OrdinalIgnoreCase); - Assert.Equal(serverName, result.Target); - Assert.Contains(databaseName, result.Name); - Assert.Contains(operationName, result.Name); - Assert.Equal(dependencyId, result.Id); + Assert.Equal(dependencyType, result.Dependency.Type, StringComparer.OrdinalIgnoreCase); + Assert.Equal(serverName, result.Dependency.Target); + Assert.Contains(databaseName, result.Dependency.Name); + Assert.Contains(operationName, result.Dependency.Name); + Assert.Equal(dependencyId, result.Dependency.Id); }); }); } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TableStorageDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TableStorageDependencyTests.cs index 826de28e..b6a53fcd 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TableStorageDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TableStorageDependencyTests.cs @@ -42,12 +42,12 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsDependencyResult[] results = await client.GetDependenciesAsync(); AssertX.Any(results, result => { - Assert.Equal(dependencyType, result.Type); - Assert.Equal(accountName, result.Target); - Assert.Equal(tableName, result.Data); + Assert.Equal(dependencyType, result.Dependency.Type); + Assert.Equal(accountName, result.Dependency.Target); + Assert.Equal(tableName, result.Dependency.Data); Assert.Equal(componentName, result.RoleName); - Assert.Equal(dependencyName, result.Name); - Assert.Equal(dependencyId, result.Id); + Assert.Equal(dependencyName, result.Dependency.Name); + Assert.Equal(dependencyId, result.Dependency.Id); }); }); } From b7304e26b2db9f39e1eb2dee71e63eacb63b4274 Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 1 Aug 2024 10:37:07 +0200 Subject: [PATCH 85/86] pr-fix: cloud result for lesser changes --- .../BlobStorageDependencyTests.cs | 2 +- .../CosmosSqlDependencyTests.cs | 2 +- .../ApplicationInsights/CustomRequestTests.cs | 2 +- .../EventHubsDependencyTests.cs | 2 +- .../EventHubsRequestTests.cs | 2 +- .../Sinks/ApplicationInsights/EventTests.cs | 2 +- .../ApplicationInsights/ExceptionTests.cs | 2 +- .../Fixture/ITelemetryQueryClient.cs | 71 +++++++++++-------- .../HttpDependencyTests.cs | 4 +- .../Sinks/ApplicationInsights/IoTHubTests.cs | 4 +- .../TableStorageDependencyTests.cs | 2 +- .../Sinks/ApplicationInsights/TraceTests.cs | 1 + 12 files changed, 54 insertions(+), 42 deletions(-) diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/BlobStorageDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/BlobStorageDependencyTests.cs index c51e222d..b4d12f89 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/BlobStorageDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/BlobStorageDependencyTests.cs @@ -45,7 +45,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => Assert.Equal(dependencyType, result.Dependency.Type); Assert.Equal(accountName, result.Dependency.Target); Assert.Equal(containerName, result.Dependency.Data); - Assert.Equal(componentName, result.RoleName); + Assert.Equal(componentName, result.Cloud.RoleName); Assert.Equal(dependencyName, result.Dependency.Name); Assert.Equal(dependencyId, result.Dependency.Id); }); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CosmosSqlDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CosmosSqlDependencyTests.cs index 3d650970..05fbcc0b 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CosmosSqlDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CosmosSqlDependencyTests.cs @@ -47,7 +47,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => Assert.Equal(dependencyType, result.Dependency.Type); Assert.Equal(accountName, result.Dependency.Target); Assert.Equal(dependencyName, result.Dependency.Data); - Assert.Equal(componentName, result.RoleName); + Assert.Equal(componentName, result.Cloud.RoleName); Assert.Equal(dependencyName, result.Dependency.Name); }); }); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomRequestTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomRequestTests.cs index 672ce8d6..147133df 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomRequestTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/CustomRequestTests.cs @@ -44,7 +44,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => Assert.True(string.IsNullOrWhiteSpace(result.Request.Url), "request URL should be blank"); Assert.Equal(operationName, result.Operation.Name); Assert.Equal(isSuccessful, result.Success); - Assert.Equal(componentName, result.RoleName); + Assert.Equal(componentName, result.Cloud.RoleName); }); }); } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsDependencyTests.cs index b8cb3276..d1570dfa 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsDependencyTests.cs @@ -45,7 +45,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => Assert.Equal(dependencyType, result.Dependency.Type); Assert.Equal(eventHubName, result.Dependency.Target); Assert.Equal(namespaceName, result.Dependency.Data); - Assert.Equal(componentName, result.RoleName); + Assert.Equal(componentName, result.Cloud.RoleName); Assert.Equal(dependencyName, result.Dependency.Name); Assert.Equal(dependencyId, result.Dependency.Id); }); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsRequestTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsRequestTests.cs index 6d1ed36e..f481dc99 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsRequestTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventHubsRequestTests.cs @@ -48,7 +48,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => Assert.True(string.IsNullOrWhiteSpace(result.Request.Url), "request URL should be blank"); Assert.Equal(operationName, result.Operation.Name); Assert.Equal(isSuccessful, result.Success); - Assert.Equal(componentName, result.RoleName); + Assert.Equal(componentName, result.Cloud.RoleName); AssertContainsCustomDimension(result.CustomDimensions, EventHubs.Namespace, eventHubsNamespace); AssertContainsCustomDimension(result.CustomDimensions, EventHubs.ConsumerGroup, eventHubsConsumerGroup); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventTests.cs index c693cab2..332a882f 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/EventTests.cs @@ -58,7 +58,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => AssertX.Any(results, trace => { Assert.Equal(message, trace.Trace.Message); - Assert.Equal(componentName, trace.RoleName); + Assert.Equal(componentName, trace.Cloud.RoleName); }); }); } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ExceptionTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ExceptionTests.cs index e22dd7c2..d8848925 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ExceptionTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/ExceptionTests.cs @@ -112,7 +112,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => AssertX.Any(results, result => { Assert.Equal(exception.Message, result.Exception.OuterMessage); - Assert.Equal(componentName, result.RoleName); + Assert.Equal(componentName, result.Cloud.RoleName); }); }); } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/ITelemetryQueryClient.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/ITelemetryQueryClient.cs index 7a158a20..2df55cd9 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/ITelemetryQueryClient.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/ITelemetryQueryClient.cs @@ -2,6 +2,7 @@ using System.Collections.ObjectModel; using System.Threading.Tasks; +// ReSharper disable once CheckNamespace namespace Microsoft.Azure.ApplicationInsights.Query.Models { /// @@ -40,38 +41,18 @@ public interface ITelemetryQueryClient Task GetExceptionsAsync(); } - public class OperationResult - { - public OperationResult(string id, string parentId) - { - Id = id; - ParentId = parentId; - } - - public OperationResult(string id, string parentId, string name) - { - Id = id; - ParentId = parentId; - Name = name; - } - - public string Id { get; } - public string Name { get; } - public string ParentId { get; } - } - public class EventsTraceResult { public EventsTraceResult(string message, string roleName, OperationResult operation, IDictionary customDimensions) { Trace = new TraceResult(message); - RoleName = roleName; + Cloud = new CloudResult(roleName); Operation = operation; CustomDimensions = customDimensions; } public TraceResult Trace { get; } - public string RoleName { get; } + public CloudResult Cloud { get; } public OperationResult Operation { get; } public IDictionary CustomDimensions { get; } @@ -97,12 +78,12 @@ public class EventsCustomEventResult public EventsCustomEventResult(string name, string roleName, IDictionary customDimensions) { Name = name; - RoleName = roleName; + Cloud = new CloudResult(roleName); CustomDimensions = new ReadOnlyDictionary(customDimensions); } public string Name { get; } - public string RoleName { get; } + public CloudResult Cloud { get; } public IReadOnlyDictionary CustomDimensions { get; } } @@ -134,17 +115,17 @@ public EventsRequestResult( IDictionary customDimensions) { Request = new RequestResult(id, name, source, url); + Cloud = new CloudResult(roleName); Success = success; ResultCode = resultCode; - RoleName = roleName; Operation = operation; CustomDimensions = customDimensions; } public RequestResult Request { get; } + public CloudResult Cloud { get; } public bool Success { get; } public string ResultCode { get; } - public string RoleName { get; } public OperationResult Operation { get; } public IDictionary CustomDimensions { get; } @@ -183,17 +164,17 @@ public EventsDependencyResult( IDictionary customDimensions) { Dependency = new DependencyResult(id, name, type, target, data); + Cloud = new CloudResult(roleName); Success = success; ResultCode = resultCode; - RoleName = roleName; Operation = operation; CustomDimensions = customDimensions; } public DependencyResult Dependency { get; } + public CloudResult Cloud { get; } public bool Success { get; } public int ResultCode { get; } - public string RoleName { get; } public OperationResult Operation { get; } public IDictionary CustomDimensions { get; } @@ -227,14 +208,14 @@ public class EventsExceptionResult public EventsExceptionResult(string message, OperationResult operation, string roleName, IDictionary customDimensions) { Exception = new ExceptionResult(message); + Cloud = new CloudResult(roleName); Operation = operation; - RoleName = roleName; CustomDimensions = customDimensions; } public ExceptionResult Exception { get; } public OperationResult Operation { get; } - public string RoleName { get; } + public CloudResult Cloud { get; } public IDictionary CustomDimensions { get; } public class ExceptionResult @@ -250,4 +231,34 @@ public ExceptionResult(string message) public string OuterMessage { get; } } } + + public class CloudResult + { + public CloudResult(string roleName) + { + RoleName = roleName; + } + + public string RoleName { get; } + } + + public class OperationResult + { + public OperationResult(string id, string parentId) + { + Id = id; + ParentId = parentId; + } + + public OperationResult(string id, string parentId, string name) + { + Id = id; + ParentId = parentId; + Name = name; + } + + public string Id { get; } + public string Name { get; } + public string ParentId { get; } + } } \ No newline at end of file diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpDependencyTests.cs index cfea9f7f..f8f51051 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpDependencyTests.cs @@ -57,7 +57,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => Assert.Equal(requestUri.Host, result.Dependency.Target); Assert.Equal($"{httpMethod} {requestUri.AbsolutePath}", result.Dependency.Name); Assert.Equal(dependencyId, result.Dependency.Id); - Assert.Equal(componentName, result.RoleName); + Assert.Equal(componentName, result.Cloud.RoleName); Assert.Equal(correlation.OperationId, result.Operation.ParentId); Assert.Equal(correlation.TransactionId, result.Operation.Id); @@ -96,7 +96,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => Assert.Equal(requestUri.Host, result.Dependency.Target); Assert.Equal($"{httpMethod} {requestUri.AbsolutePath}", result.Dependency.Name); Assert.Equal(dependencyId, result.Dependency.Id); - Assert.Equal(componentName, result.RoleName); + Assert.Equal(componentName, result.Cloud.RoleName); }); }); } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/IoTHubTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/IoTHubTests.cs index 4b7f7f74..853a6e96 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/IoTHubTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/IoTHubTests.cs @@ -42,7 +42,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { Assert.Equal("Azure IoT Hub", result.Dependency.Type); Assert.Equal(iotHubName, result.Dependency.Target); - Assert.Equal(componentName, result.RoleName); + Assert.Equal(componentName, result.Cloud.RoleName); Assert.Equal(dependencyName, result.Dependency.Name); Assert.Equal(dependencyId, result.Dependency.Id); }); @@ -77,7 +77,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => { Assert.Equal("Azure IoT Hub", result.Dependency.Type); Assert.Equal(hostName, result.Dependency.Target); - Assert.Equal(componentName, result.RoleName); + Assert.Equal(componentName, result.Cloud.RoleName); Assert.Equal(dependencyName, result.Dependency.Name); Assert.Equal(dependencyId, result.Dependency.Id); }); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TableStorageDependencyTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TableStorageDependencyTests.cs index b6a53fcd..eb1c2e79 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TableStorageDependencyTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TableStorageDependencyTests.cs @@ -45,7 +45,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => Assert.Equal(dependencyType, result.Dependency.Type); Assert.Equal(accountName, result.Dependency.Target); Assert.Equal(tableName, result.Dependency.Data); - Assert.Equal(componentName, result.RoleName); + Assert.Equal(componentName, result.Cloud.RoleName); Assert.Equal(dependencyName, result.Dependency.Name); Assert.Equal(dependencyId, result.Dependency.Id); }); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TraceTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TraceTests.cs index 47889629..6b407cc8 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TraceTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/TraceTests.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Microsoft.Azure.ApplicationInsights.Query.Models; using Microsoft.Extensions.Logging; +using Serilog.Events; using Xunit; using Xunit.Abstractions; From 4ac4c1bf348f4664b5ba9b84d7e3fa238e938f3b Mon Sep 17 00:00:00 2001 From: stijnmoreels <9039753+stijnmoreels@users.noreply.github.com> Date: Thu, 1 Aug 2024 10:39:38 +0200 Subject: [PATCH 86/86] pr-fix: place resultcode in request --- .../ApplicationInsights/AzureFunctionsDockerTests.cs | 2 +- .../Fixture/ITelemetryQueryClient.cs | 9 ++++----- .../ApplicationInsights/HttpRequestDataTests.cs | 2 +- .../Sinks/ApplicationInsights/RequestTests.cs | 12 ++++++------ 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureFunctionsDockerTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureFunctionsDockerTests.cs index 57eb738a..5a45bfd1 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureFunctionsDockerTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/AzureFunctionsDockerTests.cs @@ -27,7 +27,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => EventsRequestResult[] results = await client.GetRequestsAsync(); AssertX.Any(results, result => { - Assert.Equal("200", result.ResultCode); + Assert.Equal("200", result.Request.ResultCode); Assert.Equal("Timer", result.Request.Source); Assert.Equal("Triggered", result.Operation.Name); }); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/ITelemetryQueryClient.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/ITelemetryQueryClient.cs index 2df55cd9..2f18b6f4 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/ITelemetryQueryClient.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/Fixture/ITelemetryQueryClient.cs @@ -114,10 +114,9 @@ public EventsRequestResult( OperationResult operation, IDictionary customDimensions) { - Request = new RequestResult(id, name, source, url); + Request = new RequestResult(id, name, source, url, resultCode); Cloud = new CloudResult(roleName); Success = success; - ResultCode = resultCode; Operation = operation; CustomDimensions = customDimensions; } @@ -125,7 +124,6 @@ public EventsRequestResult( public RequestResult Request { get; } public CloudResult Cloud { get; } public bool Success { get; } - public string ResultCode { get; } public OperationResult Operation { get; } public IDictionary CustomDimensions { get; } @@ -134,18 +132,19 @@ public class RequestResult /// /// Initializes a new instance of the class. /// - public RequestResult(string id, string name, string source, string url) + public RequestResult(string id, string name, string source, string url, string resultCode) { Id = id; Name = name; Source = source; Url = url; + ResultCode = resultCode; } public string Id { get; } public string Name { get; } public string Source { get; } public string Url { get; } - + public string ResultCode { get; } } } diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpRequestDataTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpRequestDataTests.cs index 04f0b7e2..231ea95f 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpRequestDataTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/HttpRequestDataTests.cs @@ -50,7 +50,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => AssertX.Any(results, result => { Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Request.Url); - Assert.Equal(((int) statusCode).ToString(), result.ResultCode); + Assert.Equal(((int) statusCode).ToString(), result.Request.ResultCode); Assert.Equal($"{httpMethod.Method} {operationName}", result.Operation.Name); Assert.Equal(correlation.OperationId, result.Request.Id); diff --git a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/RequestTests.cs b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/RequestTests.cs index 755a6bd3..32909644 100644 --- a/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/RequestTests.cs +++ b/src/Arcus.Observability.Tests.Integration/Serilog/Sinks/ApplicationInsights/RequestTests.cs @@ -51,7 +51,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => AssertX.Any(results, result => { Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Request.Url); - Assert.Equal(((int) statusCode).ToString(), result.ResultCode); + Assert.Equal(((int) statusCode).ToString(), result.Request.ResultCode); Assert.Equal($"{httpMethod.Method} {operationName}", result.Operation.Name); Assert.Equal(correlation.OperationId, result.Request.Id); @@ -86,7 +86,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => AssertX.Any(results, result => { Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Request.Url); - Assert.Equal(((int) statusCode).ToString(), result.ResultCode); + Assert.Equal(((int) statusCode).ToString(), result.Request.ResultCode); Assert.Equal($"{httpMethod.Method} {operationName}", result.Operation.Name); }); }); @@ -121,7 +121,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => AssertX.Any(results, result => { Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Request.Url); - Assert.Equal(((int)statusCode).ToString(), result.ResultCode); + Assert.Equal(((int)statusCode).ToString(), result.Request.ResultCode); Assert.StartsWith(httpMethod.Method, result.Operation.Name); }); }); @@ -157,7 +157,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => AssertX.Any(results, result => { Assert.Equal($"{requestUri.Scheme}://{requestUri.Host}{requestUri.AbsolutePath}", result.Request.Url); - Assert.Equal(((int)statusCode).ToString(), result.ResultCode); + Assert.Equal(((int)statusCode).ToString(), result.Request.ResultCode); Assert.Equal(requestId, result.Request.Id); }); }); @@ -192,7 +192,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => AssertX.Any(results, result => { Assert.Equal(requestUri.ToString(), result.Request.Url); - Assert.Equal(((int)statusCode).ToString(), result.ResultCode); + Assert.Equal(((int)statusCode).ToString(), result.Request.ResultCode); Assert.Equal(requestId, result.Request.Id); Assert.Equal($"{httpMethod.Method} {operationName}", result.Operation.Name); Assert.Equal(requestId, result.Request.Id); @@ -226,7 +226,7 @@ await RetryAssertUntilTelemetryShouldBeAvailableAsync(async client => AssertX.Any(results, result => { Assert.Equal(requestUri.ToString(), result.Request.Url); - Assert.Equal(((int)statusCode).ToString(), result.ResultCode); + Assert.Equal(((int)statusCode).ToString(), result.Request.ResultCode); Assert.Equal($"{httpMethod.Method} {operationName}", result.Operation.Name); }); });