Skip to content

Commit b4029e1

Browse files
make ApplicationInsights optional (#198)
## Purpose <!-- Describe the intention of the changes being proposed. What problem does it solve or functionality does it add? --> Make ApplicationInsights optional before setting `AZURE_USE_APPLICATION_INSIGHTS` to true ![image](https://github.com/Azure-Samples/azure-search-openai-demo-csharp/assets/16876986/2a9f5b2c-3ec3-4076-966a-1ef3fc4a19ba) after setting `AZURE_USE_APPLICATION_INSIGHTS` to true and run azd up ![image](https://github.com/Azure-Samples/azure-search-openai-demo-csharp/assets/16876986/b2b9fd97-7fc5-461e-b440-439ef54310b8) ## Does this introduce a breaking change? <!-- Mark one with an "x". --> ``` [ ] Yes [ ] No ``` ## Pull Request Type What kind of change does this Pull Request introduce? <!-- Please check the one that applies to this PR using "x". --> ``` [ ] Bugfix [ ] Feature [ ] Code style update (formatting, local variables) [ ] Refactoring (no functional changes, no api changes) [ ] Documentation content changes [ ] Other... Please describe: ``` ## How to Test * Get the code ``` git clone [repo-address] cd [repo-name] git checkout [branch-name] npm install ``` * Test the code <!-- Add steps to run the tests suite and/or manually test --> ``` ``` ## What to Check Verify that the following are valid * ... ## Other Information <!-- Add any other helpful information that may be needed here. -->
1 parent 770e2fe commit b4029e1

File tree

5 files changed

+15
-22
lines changed

5 files changed

+15
-22
lines changed

app/backend/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
});
5353

5454
// set application telemetry
55-
if (GetEnvVar("APPLICATIONINSIGHTS_CONNECTION_STRING") is string appInsightsConnectionString)
55+
if (GetEnvVar("APPLICATIONINSIGHTS_CONNECTION_STRING") is string appInsightsConnectionString && !string.IsNullOrEmpty(appInsightsConnectionString))
5656
{
5757
builder.Services.AddApplicationInsightsTelemetry((option) =>
5858
{

infra/app/web.bicep

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ module app '../core/host/container-app-upsert.bicep' = {
9090
}
9191
{
9292
name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'
93-
value: applicationInsights.properties.ConnectionString
93+
value: !empty(applicationInsightsName) ? applicationInsights.properties.ConnectionString : ''
9494
}
9595
{
9696
name: 'AZURE_KEY_VAULT_ENDPOINT'
@@ -133,7 +133,7 @@ module app '../core/host/container-app-upsert.bicep' = {
133133
}
134134
}
135135

136-
resource applicationInsights 'Microsoft.Insights/components@2020-02-02' existing = {
136+
resource applicationInsights 'Microsoft.Insights/components@2020-02-02' existing = if (!empty(applicationInsightsName)) {
137137
name: applicationInsightsName
138138
}
139139

infra/core/monitor/monitoring.bicep

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
param logAnalyticsName string
2+
param includeApplicationInsights bool = false
23
param applicationInsightsName string
34
param applicationInsightsDashboardName string
45
param location string = resourceGroup().location
@@ -14,7 +15,7 @@ module logAnalytics 'loganalytics.bicep' = {
1415
}
1516
}
1617

17-
module applicationInsights 'applicationinsights.bicep' = {
18+
module applicationInsights 'applicationinsights.bicep' = if (includeApplicationInsights) {
1819
name: 'applicationinsights'
1920
params: {
2021
name: applicationInsightsName
@@ -26,8 +27,8 @@ module applicationInsights 'applicationinsights.bicep' = {
2627
}
2728
}
2829

29-
output applicationInsightsConnectionString string = applicationInsights.outputs.connectionString
30-
output applicationInsightsInstrumentationKey string = applicationInsights.outputs.instrumentationKey
31-
output applicationInsightsName string = applicationInsights.outputs.name
30+
output applicationInsightsConnectionString string = includeApplicationInsights ? applicationInsights.outputs.connectionString : ''
31+
output applicationInsightsInstrumentationKey string = includeApplicationInsights ? applicationInsights.outputs.instrumentationKey : ''
32+
output applicationInsightsName string = includeApplicationInsights ? applicationInsights.outputs.name : ''
3233
output logAnalyticsWorkspaceId string = logAnalytics.outputs.id
3334
output logAnalyticsWorkspaceName string = logAnalytics.outputs.name

infra/main.bicep

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ param webIdentityName string = ''
134134
@description('Name of the web app image')
135135
param webImageName string = ''
136136

137+
@description('Use Application Insights for monitoring and performance tracing')
138+
param useApplicationInsights bool = false
139+
137140
var abbrs = loadJsonContent('./abbreviations.json')
138141
var resourceToken = toLower(uniqueString(subscription().id, environmentName, location))
139142

@@ -256,25 +259,10 @@ module web './app/web.bicep' = {
256259
openAiEndpoint: openAi.outputs.endpoint
257260
openAiChatGptDeployment: chatGptDeploymentName
258261
openAiEmbeddingDeployment: embeddingDeploymentName
259-
// serviceBinds: [ redis.outputs.serviceBind ]
260262
serviceBinds: []
261263
}
262264
}
263265

264-
// this launches a redis instance inside of the ACA env
265-
// module redis 'core/host/container-app.bicep' = {
266-
// name: 'redis'
267-
// scope: resourceGroup
268-
// params: {
269-
// name: 'redis'
270-
// location: location
271-
// tags: updatedTags
272-
// containerAppsEnvironmentName: containerApps.outputs.environmentName
273-
// containerRegistryName: containerApps.outputs.registryName
274-
// serviceType: 'redis'
275-
// }
276-
// }
277-
278266
// Monitor application with Azure Monitor
279267
module monitoring 'core/monitor/monitoring.bicep' = {
280268
name: 'monitoring'
@@ -283,6 +271,7 @@ module monitoring 'core/monitor/monitoring.bicep' = {
283271
location: location
284272
tags: updatedTags
285273
includeDashboard: false
274+
includeApplicationInsights: useApplicationInsights
286275
logAnalyticsName: !empty(logAnalyticsName) ? logAnalyticsName : '${abbrs.operationalInsightsWorkspaces}${resourceToken}'
287276
applicationInsightsName: !empty(applicationInsightsName) ? applicationInsightsName : '${abbrs.insightsComponents}${resourceToken}'
288277
applicationInsightsDashboardName: !empty(applicationInsightsDashboardName) ? applicationInsightsDashboardName : '${abbrs.portalDashboards}${resourceToken}'

infra/main.parameters.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@
7373
},
7474
"webIdentityName": {
7575
"value": "${SERVICE_WEB_IDENTITY_NAME}"
76+
},
77+
"useApplicationInsights": {
78+
"value": "${AZURE_USE_APPLICATION_INSIGHTS=false}"
7679
}
7780
}
7881
}

0 commit comments

Comments
 (0)