Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit e89fdd6

Browse files
authored
feat: Allow custom app insights instrumentation key (#494)
1 parent 37cecf6 commit e89fdd6

File tree

4 files changed

+43
-6
lines changed

4 files changed

+43
-6
lines changed

src/armTemplates/resources/functionApp.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,36 @@ describe("Function App Resource", () => {
4545
});
4646

4747
describe("App Settings", () => {
48+
describe("General", () => {
49+
it("uses custom app insights instrumentation key", () => {
50+
const instrumentationKey = "myInstrumentationKey"
51+
const config = getConfig(FunctionAppOS.LINUX, Runtime.PYTHON36);
52+
config.provider.appInsights = {
53+
instrumentationKey,
54+
}
55+
56+
const resource = new FunctionAppResource();
57+
const { appSettings } = resource.getTemplate(config).resources[0].properties.siteConfig;
58+
expect(appSettings).toEqual([
59+
{
60+
name: "FUNCTIONS_WORKER_RUNTIME",
61+
value: "[parameters('functionAppWorkerRuntime')]"
62+
},
63+
{
64+
name: "FUNCTIONS_EXTENSION_VERSION",
65+
value: "[parameters('functionAppExtensionVersion')]"
66+
},
67+
{
68+
name: "AzureWebJobsStorage",
69+
value: "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageAccountName'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2016-01-01').keys[0].value)]"
70+
},
71+
{
72+
name: "APPINSIGHTS_INSTRUMENTATIONKEY",
73+
value: instrumentationKey
74+
}
75+
]);
76+
});
77+
})
4878
describe("Linux", () => {
4979
it("gets correct app settings - python", () => {
5080
const config = getConfig(FunctionAppOS.LINUX, Runtime.PYTHON36);

src/armTemplates/resources/functionApp.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { dockerImages, getRuntimeLanguage, getRuntimeVersion, FunctionAppOS, isNodeRuntime, Runtime, RuntimeLanguage, getFunctionWorkerRuntime } from "../../config/runtime";
1+
import { dockerImages, FunctionAppOS, getFunctionWorkerRuntime, getRuntimeVersion, isNodeRuntime } from "../../config/runtime";
22
import { ArmParameter, ArmParameters, ArmParamType, ArmResourceTemplate, ArmResourceTemplateGenerator, DefaultArmParams } from "../../models/armTemplates";
33
import { FunctionAppConfig, ServerlessAzureConfig } from "../../models/serverless";
44
import { AzureNamingService, AzureNamingServiceOptions } from "../../services/namingService";
@@ -206,6 +206,9 @@ export class FunctionAppResource implements ArmResourceTemplateGenerator {
206206
}
207207

208208
private getFunctionAppSettings(config: ServerlessAzureConfig): FunctionAppSetting[] {
209+
const { appInsights } = config.provider;
210+
const instrumentationKey = appInsights ? appInsights.instrumentationKey : undefined;
211+
209212
let appSettings: FunctionAppSetting[] = [
210213
{
211214
name: "FUNCTIONS_WORKER_RUNTIME",
@@ -221,7 +224,7 @@ export class FunctionAppResource implements ArmResourceTemplateGenerator {
221224
},
222225
{
223226
name: "APPINSIGHTS_INSTRUMENTATIONKEY",
224-
value: "[reference(concat('microsoft.insights/components/', parameters('appInsightsName'))).InstrumentationKey]"
227+
value: instrumentationKey || "[reference(concat('microsoft.insights/components/', parameters('appInsightsName'))).InstrumentationKey]"
225228
}
226229
];
227230

src/models/serverless.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ export interface FunctionAppConfig extends ResourceConfig {
2323
extensionVersion?;
2424
}
2525

26+
export interface AppInsightsConfig extends ResourceConfig {
27+
instrumentationKey?: string;
28+
}
29+
2630
export interface DeploymentConfig {
2731
rollback?: boolean;
2832
container?: string;
@@ -49,7 +53,7 @@ export interface ServerlessAzureProvider {
4953
resourceGroup?: string;
5054
apim?: ApiManagementConfig;
5155
functionApp?: FunctionAppConfig;
52-
appInsights?: ResourceConfig;
56+
appInsights?: AppInsightsConfig;
5357
appServicePlan?: AppServicePlanConfig;
5458
storageAccount?: ResourceConfig;
5559
hostingEnvironment?: ResourceConfig;

src/plugins/package/azurePackagePlugin.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

22
import Serverless from "serverless";
3+
import { BuildMode } from "../../config/runtime";
34
import { ServerlessCliCommand } from "../../models/serverless";
45
import AzureProvider from "../../provider/azureProvider";
6+
import { CompilerService } from "../../services/compilerService";
7+
import { ConfigService } from "../../services/configService";
58
import { PackageService } from "../../services/packageService";
69
import { AzureBasePlugin } from "../azureBasePlugin";
7-
import { isCompiledRuntime, BuildMode, FunctionAppOS } from "../../config/runtime";
8-
import { CompilerService } from "../../services/compilerService"
9-
import { ConfigService } from "../../services/configService";
1010

1111
export class AzurePackagePlugin extends AzureBasePlugin {
1212
private bindingsCreated: boolean = false;

0 commit comments

Comments
 (0)