Skip to content

Commit 8e1dc85

Browse files
committed
Inject the app insights key at build time
Uses a github secret. When building the extension, set the APP_INSIGHTS_KEY environment variable to the key and the build process will inject this value as the key to use.
1 parent f8f8732 commit 8e1dc85

8 files changed

Lines changed: 315 additions & 5 deletions

File tree

.github/workflows/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ jobs:
2929
shell: bash
3030

3131
- name: Build
32+
env:
33+
APP_INSIGHTS_KEY: '${{ secrets.APP_INSIGHTS_KEY }}'
3234
run: |
3335
cd extensions/ql-vscode
3436
npm run build
@@ -71,6 +73,8 @@ jobs:
7173
shell: bash
7274

7375
- name: Build
76+
env:
77+
APP_INSIGHTS_KEY: '${{ secrets.APP_INSIGHTS_KEY }}'
7478
run: |
7579
cd extensions/ql-vscode
7680
npm run build

.github/workflows/release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ jobs:
2020
build:
2121
name: Release
2222
runs-on: ubuntu-latest
23-
# TODO Share steps with the main workflow.
23+
env:
24+
APP_INSIGHTS_KEY: '${{ secrets.APP_INSIGHTS_KEY }}'
2425
steps:
2526
- name: Checkout
2627
uses: actions/checkout@v2
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as gulp from 'gulp';
2+
import * as replace from 'gulp-replace';
3+
4+
/** Inject the application insights key into the telemetry file */
5+
export function injectAppInsightsKey() {
6+
if (!process.env.APP_INSIGHTS_KEY) {
7+
// noop
8+
console.log('APP_INSIGHTS_KEY environment variable is not set. So, cannot inject it into the application.');
9+
return Promise.resolve();
10+
}
11+
12+
// replace the key
13+
return gulp.src(['out/telemetry.js'])
14+
.pipe(replace(/REPLACE-APP-INSIGHTS-KEY/, process.env.APP_INSIGHTS_KEY))
15+
.pipe(gulp.dest('out/'));
16+
}

extensions/ql-vscode/gulpfile.ts/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ import { compileTextMateGrammar } from './textmate';
44
import { copyTestData } from './tests';
55
import { compileView } from './webpack';
66
import { packageExtension } from './package';
7+
import { injectAppInsightsKey } from './appInsights';
78

8-
export const buildWithoutPackage = gulp.parallel(compileTypeScript, compileTextMateGrammar, compileView, copyTestData, copyViewCss);
9-
export { compileTextMateGrammar, watchTypeScript, compileTypeScript };
10-
exports.default = gulp.series(exports.buildWithoutPackage, packageExtension);
9+
export const buildWithoutPackage =
10+
gulp.series(
11+
gulp.parallel(
12+
compileTypeScript, compileTextMateGrammar, compileView, copyTestData, copyViewCss
13+
),
14+
injectAppInsightsKey
15+
);
16+
export { compileTextMateGrammar, watchTypeScript, compileTypeScript, injectAppInsightsKey };
17+
exports.default = gulp.series(buildWithoutPackage, packageExtension);

extensions/ql-vscode/package-lock.json

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/ql-vscode/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,7 @@
757757
"@types/glob": "^7.1.1",
758758
"@types/google-protobuf": "^3.2.7",
759759
"@types/gulp": "^4.0.6",
760+
"@types/gulp-replace": "0.0.31",
760761
"@types/gulp-sourcemaps": "0.0.32",
761762
"@types/js-yaml": "^3.12.5",
762763
"@types/jszip": "~3.1.6",
@@ -787,6 +788,7 @@
787788
"eslint-plugin-react": "~7.19.0",
788789
"glob": "^7.1.4",
789790
"gulp": "^4.0.2",
791+
"gulp-replace": "^1.0.0",
790792
"gulp-sourcemaps": "^2.6.5",
791793
"gulp-typescript": "^5.0.1",
792794
"husky": "~4.2.5",

extensions/ql-vscode/src/telemetry.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { logger } from './logging';
66
import { UserCancellationException } from './commandRunner';
77
import { showBinaryChoiceDialog } from './helpers';
88

9-
const key = '6f88c20e-2879-41ed-af73-218b82e1ff44';
9+
// Key is injected at build time through the APP_INSIGHTS_KEY environment variable.
10+
const key = 'REPLACE-APP-INSIGHTS-KEY';
1011

1112
let reporter: TelemetryReporter | undefined;
1213
let listener: Disposable | undefined;

0 commit comments

Comments
 (0)