Skip to content

Commit

Permalink
Add app insights to the relevant C#/F# examples (pulumi#756)
Browse files Browse the repository at this point in the history
  • Loading branch information
kane-armstrong committed Aug 17, 2020
1 parent 60b517d commit 3db0fc8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
10 changes: 10 additions & 0 deletions azure-cs-appservice/AppServiceStack.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2016-2020, Pulumi Corporation. All rights reserved.

using Pulumi;
using Pulumi.Azure.AppInsights;
using Pulumi.Azure.AppService;
using Pulumi.Azure.AppService.Inputs;
using Pulumi.Azure.Core;
Expand Down Expand Up @@ -47,6 +48,12 @@ public AppServiceStack()

var codeBlobUrl = SharedAccessSignature.SignedBlobReadUrl(blob, storageAccount);

var appInsights = new Insights("appInsights", new InsightsArgs
{
ApplicationType = "web",
ResourceGroupName = resourceGroup.Name
});

var config = new Config();
var username = config.Get("sqlAdmin") ?? "pulumi";
var password = config.RequireSecret("sqlPassword");
Expand All @@ -72,6 +79,9 @@ public AppServiceStack()
AppSettings =
{
{"WEBSITE_RUN_FROM_PACKAGE", codeBlobUrl},
{"APPINSIGHTS_INSTRUMENTATIONKEY", appInsights.InstrumentationKey},
{"APPLICATIONINSIGHTS_CONNECTION_STRING", appInsights.InstrumentationKey.Apply(key => $"InstrumentationKey={key}")},
{"ApplicationInsightsAgent_EXTENSION_VERSION", "~2"},
},
ConnectionStrings =
{
Expand Down
19 changes: 18 additions & 1 deletion azure-fs-appservice/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

open Pulumi
open Pulumi.FSharp
open Pulumi.Azure.AppInsights
open Pulumi.Azure.AppService
open Pulumi.Azure.AppService.Inputs
open Pulumi.Azure.Core
Expand Down Expand Up @@ -43,6 +44,12 @@ let infra () =

let codeBlobUrl = SharedAccessSignature.SignedBlobReadUrl(blob, storageAccount)

let appInsights =
Insights("appInsights",
InsightsArgs
(ApplicationType = input "web",
ResourceGroupName = io resourceGroup.Name))

let config = Config()
let username = config.Get "sqlAdmin"
let password = config.RequireSecret "sqlPassword"
Expand Down Expand Up @@ -73,13 +80,23 @@ let infra () =
(Name = input "db",
Type = input "SQLAzure",
Value = io connectionString)

let appInsightsConnectionString =
appInsights.InstrumentationKey
|> Outputs.apply(fun (key) ->
sprintf "InstrumentationKey=%s" key)

let app =
AppService("app",
AppServiceArgs
(ResourceGroupName = io resourceGroup.Name,
AppServicePlanId = io appServicePlan.Id,
AppSettings = inputMap ["WEBSITE_RUN_FROM_PACKAGE", io codeBlobUrl],
AppSettings = inputMap
["WEBSITE_RUN_FROM_PACKAGE", io codeBlobUrl;
"APPINSIGHTS_INSTRUMENTATIONKEY", io appInsights.InstrumentationKey;
"APPLICATIONINSIGHTS_CONNECTION_STRING", io appInsightsConnectionString;
"ApplicationInsightsAgent_EXTENSION_VERSION", input "~2"],

ConnectionStrings = inputList [input connectionStringSetting]))

dict [("endpoint", app.DefaultSiteHostname :> obj)]
Expand Down

0 comments on commit 3db0fc8

Please sign in to comment.