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

feat: Allow custom app insights instrumentation key #494

Merged
merged 2 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/armTemplates/resources/functionApp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,36 @@ describe("Function App Resource", () => {
});

describe("App Settings", () => {
describe("General", () => {
it("uses custom app insights instrumentation key", () => {
const instrumentationKey = "myInstrumentationKey"
const config = getConfig(FunctionAppOS.LINUX, Runtime.PYTHON36);
config.provider.appInsights = {
instrumentationKey,
}

const resource = new FunctionAppResource();
const { appSettings } = resource.getTemplate(config).resources[0].properties.siteConfig;
expect(appSettings).toEqual([
{
name: "FUNCTIONS_WORKER_RUNTIME",
value: "[parameters('functionAppWorkerRuntime')]"
},
{
name: "FUNCTIONS_EXTENSION_VERSION",
value: "[parameters('functionAppExtensionVersion')]"
},
{
name: "AzureWebJobsStorage",
value: "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageAccountName'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2016-01-01').keys[0].value)]"
},
{
name: "APPINSIGHTS_INSTRUMENTATIONKEY",
value: instrumentationKey
}
]);
});
})
describe("Linux", () => {
it("gets correct app settings - python", () => {
const config = getConfig(FunctionAppOS.LINUX, Runtime.PYTHON36);
Expand Down
7 changes: 5 additions & 2 deletions src/armTemplates/resources/functionApp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { dockerImages, getRuntimeLanguage, getRuntimeVersion, FunctionAppOS, isNodeRuntime, Runtime, RuntimeLanguage, getFunctionWorkerRuntime } from "../../config/runtime";
import { dockerImages, FunctionAppOS, getFunctionWorkerRuntime, getRuntimeVersion, isNodeRuntime } from "../../config/runtime";
import { ArmParameter, ArmParameters, ArmParamType, ArmResourceTemplate, ArmResourceTemplateGenerator, DefaultArmParams } from "../../models/armTemplates";
import { FunctionAppConfig, ServerlessAzureConfig } from "../../models/serverless";
import { AzureNamingService, AzureNamingServiceOptions } from "../../services/namingService";
Expand Down Expand Up @@ -206,6 +206,9 @@ export class FunctionAppResource implements ArmResourceTemplateGenerator {
}

private getFunctionAppSettings(config: ServerlessAzureConfig): FunctionAppSetting[] {
const { appInsights } = config.provider;
const instrumentationKey = appInsights ? appInsights.instrumentationKey : undefined;

let appSettings: FunctionAppSetting[] = [
{
name: "FUNCTIONS_WORKER_RUNTIME",
Expand All @@ -221,7 +224,7 @@ export class FunctionAppResource implements ArmResourceTemplateGenerator {
},
{
name: "APPINSIGHTS_INSTRUMENTATIONKEY",
value: "[reference(concat('microsoft.insights/components/', parameters('appInsightsName'))).InstrumentationKey]"
value: instrumentationKey || "[reference(concat('microsoft.insights/components/', parameters('appInsightsName'))).InstrumentationKey]"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit test to validate this change?

}
];

Expand Down
6 changes: 5 additions & 1 deletion src/models/serverless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export interface FunctionAppConfig extends ResourceConfig {
extensionVersion?;
}

export interface AppInsightsConfig extends ResourceConfig {
instrumentationKey?: string;
}

export interface DeploymentConfig {
rollback?: boolean;
container?: string;
Expand All @@ -49,7 +53,7 @@ export interface ServerlessAzureProvider {
resourceGroup?: string;
apim?: ApiManagementConfig;
functionApp?: FunctionAppConfig;
appInsights?: ResourceConfig;
appInsights?: AppInsightsConfig;
appServicePlan?: AppServicePlanConfig;
storageAccount?: ResourceConfig;
hostingEnvironment?: ResourceConfig;
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/package/azurePackagePlugin.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

import Serverless from "serverless";
import { BuildMode } from "../../config/runtime";
import { ServerlessCliCommand } from "../../models/serverless";
import AzureProvider from "../../provider/azureProvider";
import { CompilerService } from "../../services/compilerService";
import { ConfigService } from "../../services/configService";
import { PackageService } from "../../services/packageService";
import { AzureBasePlugin } from "../azureBasePlugin";
import { isCompiledRuntime, BuildMode, FunctionAppOS } from "../../config/runtime";
import { CompilerService } from "../../services/compilerService"
import { ConfigService } from "../../services/configService";

export class AzurePackagePlugin extends AzureBasePlugin {
private bindingsCreated: boolean = false;
Expand Down