Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add application insights connection string support - APPLICATIONINSIGHTS_CONNECTION_STRING #19855

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { AzureEndpoint } from 'azure-pipelines-tasks-azure-arm-rest/azureModels'
export async function addReleaseAnnotation(endpoint: AzureEndpoint, azureAppService: AzureAppService, isDeploymentSuccess: boolean): Promise<void> {
try {
var appSettings = await azureAppService.getApplicationSettings();
var instrumentationKey = appSettings && appSettings.properties && appSettings.properties.APPINSIGHTS_INSTRUMENTATIONKEY;
var instrumentationKey = getInstrumentationKey(appSettings);
if(instrumentationKey) {
let appinsightsResources: ApplicationInsightsResources = new ApplicationInsightsResources(endpoint);
var appInsightsResources = await appinsightsResources.list(null, [`$filter=InstrumentationKey eq '${instrumentationKey}'`]);
Expand Down Expand Up @@ -89,4 +89,21 @@ function getPipelineVariable(variableName: string): string | undefined {
let variable = tl.getVariable(variableName);
//we dont want to set a variable to be empty string
return !!variable ? variable : undefined;
}
}

function getInstrumentationKey(appSettings: any): string | undefined {
let connectionString = appSettings?.properties?.APPLICATIONINSIGHTS_CONNECTION_STRING;
if (connectionString){
const FIELDS_SEPARATOR = ";";
const FIELD_KEY_VALUE_SEPARATOR = "=";

const kvPairs = connectionString.split(FIELDS_SEPARATOR);
for (const kvPair of kvPairs) {
const pair = kvPair.split(FIELD_KEY_VALUE_SEPARATOR);
if (pair.length === 2 && pair[0].trim().toLowerCase() === "instrumentationkey") {
return pair[1].trim();
}
}
}
return appSettings?.properties?.APPINSIGHTS_INSTRUMENTATIONKEY;
}
FinVamp1 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var uuidV4 = require("uuid/v4");
export async function addReleaseAnnotation(endpoint: AzureEndpoint, azureAppService: AzureAppService, isDeploymentSuccess: boolean): Promise<void> {
try {
var appSettings = await azureAppService.getApplicationSettings();
var instrumentationKey = appSettings && appSettings.properties && appSettings.properties.APPINSIGHTS_INSTRUMENTATIONKEY;
var instrumentationKey = getInstrumentationKey(appSettings);
if(instrumentationKey) {
let appinsightsResources: ApplicationInsightsResources = new ApplicationInsightsResources(endpoint);
var appInsightsResources = await appinsightsResources.list(null, [`$filter=InstrumentationKey eq '${instrumentationKey}'`]);
Expand Down Expand Up @@ -91,3 +91,20 @@ function getPipelineVariable(variableName: string): string | undefined {
//we dont want to set a variable to be empty string
return !!variable ? variable : undefined;
}

function getInstrumentationKey(appSettings: any): string | undefined {
let connectionString = appSettings?.properties?.APPLICATIONINSIGHTS_CONNECTION_STRING;
if (connectionString){
const FIELDS_SEPARATOR = ";";
const FIELD_KEY_VALUE_SEPARATOR = "=";

const kvPairs = connectionString.split(FIELDS_SEPARATOR);
for (const kvPair of kvPairs) {
const pair = kvPair.split(FIELD_KEY_VALUE_SEPARATOR);
if (pair.length === 2 && pair[0].trim().toLowerCase() === "instrumentationkey") {
return pair[1].trim();
}
}
}
return appSettings?.properties?.APPINSIGHTS_INSTRUMENTATIONKEY;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var uuidV4 = require("uuid/v4");
export async function addReleaseAnnotation(endpoint: AzureEndpoint, azureAppService: AzureAppService, isDeploymentSuccess: boolean): Promise<void> {
try {
var appSettings = await azureAppService.getApplicationSettings();
var instrumentationKey = appSettings && appSettings.properties && appSettings.properties.APPINSIGHTS_INSTRUMENTATIONKEY;
var instrumentationKey = getInstrumentationKey(appSettings);
if(instrumentationKey) {
let appinsightsResources: ApplicationInsightsResources = new ApplicationInsightsResources(endpoint);
var appInsightsResources = await appinsightsResources.list(null, [`$filter=InstrumentationKey eq '${instrumentationKey}'`]);
Expand Down Expand Up @@ -91,3 +91,20 @@ function getPipelineVariable(variableName: string): string | undefined {
//we dont want to set a variable to be empty string
return !!variable ? variable : undefined;
}

function getInstrumentationKey(appSettings: any): string | undefined {
let connectionString = appSettings?.properties?.APPLICATIONINSIGHTS_CONNECTION_STRING;
if (connectionString){
const FIELDS_SEPARATOR = ";";
const FIELD_KEY_VALUE_SEPARATOR = "=";

const kvPairs = connectionString.split(FIELDS_SEPARATOR);
for (const kvPair of kvPairs) {
const pair = kvPair.split(FIELD_KEY_VALUE_SEPARATOR);
if (pair.length === 2 && pair[0].trim().toLowerCase() === "instrumentationkey") {
return pair[1].trim();
}
}
}
return appSettings?.properties?.APPINSIGHTS_INSTRUMENTATIONKEY;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var uuidV4 = require("uuid/v4");
export async function addReleaseAnnotation(endpoint: AzureEndpoint, azureAppService: AzureAppService, isDeploymentSuccess: boolean): Promise<void> {
try {
var appSettings = await azureAppService.getApplicationSettings();
var instrumentationKey = appSettings && appSettings.properties && appSettings.properties.APPINSIGHTS_INSTRUMENTATIONKEY;
var instrumentationKey = getInstrumentationKey(appSettings);
if(instrumentationKey) {
let appinsightsResources: ApplicationInsightsResources = new ApplicationInsightsResources(endpoint);
var appInsightsResources = await appinsightsResources.list(null, [`$filter=InstrumentationKey eq '${instrumentationKey}'`]);
Expand Down Expand Up @@ -90,4 +90,21 @@ function getPipelineVariable(variableName: string): string | undefined {
let variable = tl.getVariable(variableName);
//we dont want to set a variable to be empty string
return !!variable ? variable : undefined;
}
}

function getInstrumentationKey(appSettings: any): string | undefined {
let connectionString = appSettings?.properties?.APPLICATIONINSIGHTS_CONNECTION_STRING;
if (connectionString){
const FIELDS_SEPARATOR = ";";
const FIELD_KEY_VALUE_SEPARATOR = "=";

const kvPairs = connectionString.split(FIELDS_SEPARATOR);
for (const kvPair of kvPairs) {
const pair = kvPair.split(FIELD_KEY_VALUE_SEPARATOR);
if (pair.length === 2 && pair[0].trim().toLowerCase() === "instrumentationkey") {
return pair[1].trim();
}
}
}
return appSettings?.properties?.APPINSIGHTS_INSTRUMENTATIONKEY;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var uuidV4 = require("uuid/v4");
export async function addReleaseAnnotation(endpoint: AzureEndpoint, azureAppService: AzureAppService, isDeploymentSuccess: boolean): Promise<void> {
try {
var appSettings = await azureAppService.getApplicationSettings();
var instrumentationKey = appSettings && appSettings.properties && appSettings.properties.APPINSIGHTS_INSTRUMENTATIONKEY;
var instrumentationKey = getInstrumentationKey(appSettings);
if(instrumentationKey) {
let appinsightsResources: ApplicationInsightsResources = new ApplicationInsightsResources(endpoint);
var appInsightsResources = await appinsightsResources.list(null, [`$filter=InstrumentationKey eq '${instrumentationKey}'`]);
Expand Down Expand Up @@ -90,4 +90,21 @@ function getPipelineVariable(variableName: string): string | undefined {
let variable = tl.getVariable(variableName);
//we dont want to set a variable to be empty string
return !!variable ? variable : undefined;
}

function getInstrumentationKey(appSettings: any): string | undefined {
let connectionString = appSettings?.properties?.APPLICATIONINSIGHTS_CONNECTION_STRING;
if (connectionString){
const FIELDS_SEPARATOR = ";";
const FIELD_KEY_VALUE_SEPARATOR = "=";

const kvPairs = connectionString.split(FIELDS_SEPARATOR);
for (const kvPair of kvPairs) {
const pair = kvPair.split(FIELD_KEY_VALUE_SEPARATOR);
if (pair.length === 2 && pair[0].trim().toLowerCase() === "instrumentationkey") {
return pair[1].trim();
}
}
}
return appSettings?.properties?.APPINSIGHTS_INSTRUMENTATIONKEY;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { AzureEndpoint } from 'azure-pipelines-tasks-azure-arm-rest/azureModels'
export async function addReleaseAnnotation(endpoint: AzureEndpoint, azureAppService: AzureAppService, isDeploymentSuccess: boolean): Promise<void> {
try {
var appSettings = await azureAppService.getApplicationSettings();
var instrumentationKey = appSettings && appSettings.properties && appSettings.properties.APPINSIGHTS_INSTRUMENTATIONKEY;
var instrumentationKey = getInstrumentationKey(appSettings);
if(instrumentationKey) {
let appinsightsResources: ApplicationInsightsResources = new ApplicationInsightsResources(endpoint);
var appInsightsResources = await appinsightsResources.list(null, [`$filter=InstrumentationKey eq '${instrumentationKey}'`]);
Expand Down Expand Up @@ -89,4 +89,21 @@ function getPipelineVariable(variableName: string): string | undefined {
let variable = tl.getVariable(variableName);
//we dont want to set a variable to be empty string
return !!variable ? variable : undefined;
}
}

function getInstrumentationKey(appSettings: any): string | undefined {
let connectionString = appSettings?.properties?.APPLICATIONINSIGHTS_CONNECTION_STRING;
if (connectionString){
const FIELDS_SEPARATOR = ";";
const FIELD_KEY_VALUE_SEPARATOR = "=";

const kvPairs = connectionString.split(FIELDS_SEPARATOR);
for (const kvPair of kvPairs) {
const pair = kvPair.split(FIELD_KEY_VALUE_SEPARATOR);
if (pair.length === 2 && pair[0].trim().toLowerCase() === "instrumentationkey") {
return pair[1].trim();
}
}
}
return appSettings?.properties?.APPINSIGHTS_INSTRUMENTATIONKEY;
}
21 changes: 19 additions & 2 deletions Tasks/AzureWebAppV1/operations/ReleaseAnnotationUtility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var uuidV4 = require("uuid/v4");
export async function addReleaseAnnotation(endpoint: AzureEndpoint, azureAppService: AzureAppService, isDeploymentSuccess: boolean): Promise<void> {
try {
var appSettings = await azureAppService.getApplicationSettings();
var instrumentationKey = appSettings && appSettings.properties && appSettings.properties.APPINSIGHTS_INSTRUMENTATIONKEY;
var instrumentationKey = getInstrumentationKey(appSettings);
if(instrumentationKey) {
let appinsightsResources: ApplicationInsightsResources = new ApplicationInsightsResources(endpoint);
var appInsightsResources = await appinsightsResources.list(null, [`$filter=InstrumentationKey eq '${instrumentationKey}'`]);
Expand Down Expand Up @@ -90,4 +90,21 @@ function getPipelineVariable(variableName: string): string | undefined {
let variable = tl.getVariable(variableName);
//we dont want to set a variable to be empty string
return !!variable ? variable : undefined;
}
}

function getInstrumentationKey(appSettings: any): string | undefined {
let connectionString = appSettings?.properties?.APPLICATIONINSIGHTS_CONNECTION_STRING;
if (connectionString){
const FIELDS_SEPARATOR = ";";
const FIELD_KEY_VALUE_SEPARATOR = "=";

const kvPairs = connectionString.split(FIELDS_SEPARATOR);
for (const kvPair of kvPairs) {
const pair = kvPair.split(FIELD_KEY_VALUE_SEPARATOR);
if (pair.length === 2 && pair[0].trim().toLowerCase() === "instrumentationkey") {
return pair[1].trim();
}
}
}
return appSettings?.properties?.APPINSIGHTS_INSTRUMENTATIONKEY;
}