Skip to content

Commit

Permalink
update app insights to version 3 (#1165)
Browse files Browse the repository at this point in the history
* update app insights to version 3

* create temp dir

* removed sender

* use app insights connection string

* Bumping chart version/ fixing aliases

* update chart version

* update setup secret to return connection string

---------

Co-authored-by: hmcts-jenkins-j-to-z <61242337+hmcts-jenkins-j-to-z[bot]@users.noreply.github.com>
  • Loading branch information
sonny-hmcts and hmcts-jenkins-j-to-z[bot] authored Aug 15, 2024
1 parent ba8e9f8 commit 465dd09
Show file tree
Hide file tree
Showing 9 changed files with 2,359 additions and 313 deletions.
1,530 changes: 1,371 additions & 159 deletions .pnp.cjs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions app/components/app-insights.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const appInsights = require('applicationinsights');
const Sender = require('applicationinsights/out/Library/Sender');
const logger = require('app/components/logger')('Init');
const config = require('config');
const path = require('path');
Expand All @@ -10,18 +9,19 @@ const os = require('os');

let client ;
const instrumentationKey = config.get('appInsights.instrumentationKey');
const connectionString = config.get('appInsights.connectionString');
const TEMPDIR_PREFIX = 'appInsights-node';

exports.initAppInsights = function initAppInsights() {
if (instrumentationKey) {
createTempDir();

logger.info('Starting App Insights');

appInsights.setup(instrumentationKey)
appInsights.setup(connectionString)
.setSendLiveMetrics(true)
.setAutoCollectConsole(true, true)
.start();

client = appInsights.defaultClient;
client.context.tags[appInsights.defaultClient.context.keys.cloudRole] = 'pcq-frontend';
client.trackTrace({message: 'App insights activated'});
Expand All @@ -30,7 +30,7 @@ exports.initAppInsights = function initAppInsights() {
}

function createTempDir() {
const tempDir = path.join(os.tmpdir(), Sender.TEMPDIR_PREFIX + instrumentationKey);
const tempDir = path.join(os.tmpdir(), TEMPDIR_PREFIX + instrumentationKey);

if (!fs.existsSync(tempDir)) {
logger.info('Creating App Insights temp dir');
Expand Down
1 change: 1 addition & 0 deletions app/setupSecrets.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const setupSecrets = () => {
setSecret('secrets.pcq.frontend-redis-access-key', 'redis.password');
setSecret('secrets.pcq.jwt-secret', 'auth.jwt.secret');
setSecret('secrets.pcq.AppInsightsInstrumentationKey', 'appInsights.instrumentationKey');
setSecret('secrets.pcq.app-insights-connection-string', 'appInsights.connectionString');
setSecret('secrets.pcq.launchdarkly-key', 'featureToggles.launchDarklyKey');
setSecret('secrets.pcq.launchdarkly-user-key', 'featureToggles.launchDarklyUser.key');
// ------------------------------------------ Token Keys ------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion charts/pcq-frontend/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: pcq-frontend
description: A Helm chart for the HMCTS PCQ product
home: https://github.com/hmcts/pcq-frontend
version: 1.2.120
version: 1.2.121
maintainers:
- name: HMCTS PCQ Team
email: [email protected]
Expand Down
1 change: 1 addition & 0 deletions charts/pcq-frontend/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ nodejs:
resourceGroup: pcq
secrets:
- AppInsightsInstrumentationKey
- app-insights-connection-string
- frontend-redis-access-key
- jwt-secret
- launchdarkly-key
Expand Down
1 change: 1 addition & 0 deletions config/custom-environment-variables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ utils:
retryDelay: RETRY_DELAY
appInsights:
instrumentationKey: APPINSIGHTS_INSTRUMENTATION_KEY
connectionString: app-insights-connection-string
testUrl: TEST_URL
1 change: 1 addition & 0 deletions config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ livenessEndpoint: "/health/liveness"
healthEndpoint: "/health"
appInsights:
instrumentationKey: ''
connectionString: ''
health:
timeout: 5000
deadline: 15000
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "protected-characteristics-frontend",
"description": "Protected Characteristics web app",
"version": "1.2.183",
"version": "1.2.184",
"license": "MIT",
"engines": {
"node": ">=14.18.1"
Expand Down Expand Up @@ -53,7 +53,7 @@
"@hmcts/properties-volume": "^1.0.0",
"ajv": "^6.12.6",
"app": "link:./app",
"applicationinsights": "^2.9.4",
"applicationinsights": "^3.2.1",
"body-parser": "^1.19.0",
"co": "^4.6.0",
"compression": "^1.7.4",
Expand Down
Loading

0 comments on commit 465dd09

Please sign in to comment.