Skip to content

Commit 28b8f9a

Browse files
Add application insights for frontend
1 parent 4f761ba commit 28b8f9a

File tree

10 files changed

+178
-0
lines changed

10 files changed

+178
-0
lines changed

.github/workflows/frontend_lint_and_test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ jobs:
3333
- run: npm test
3434
env:
3535
PORT: 3001
36+
REACT_APP_AI_CONNECTION_STRING: ""
3637
REACT_APP_BACKEND_URL: https://localhost:8000
3738
REACT_APP_BACKEND_API_SCOPE: api://ea4c7b92-47b3-45fb-bd25-a8070f0c495c/user_impersonation
3839
REACT_APP_FRONTEND_URL: http://localhost:3001

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ services:
66
ports:
77
- "3001:3001"
88
environment:
9+
- REACT_APP_AI_CONNECTION_STRING=
910
- REACT_APP_BACKEND_URL=http://localhost:8000
1011
- REACT_APP_BACKEND_API_SCOPE=api://ea4c7b92-47b3-45fb-bd25-a8070f0c495c/user_impersonation
1112
- REACT_APP_FRONTEND_URL=http://localhost:3001

frontend/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
PORT=3001
2+
REACT_APP_AI_CONNECTION_STRING=""
23
REACT_APP_BACKEND_URL=https://localhost:8000
34
REACT_APP_BACKEND_API_SCOPE=api://ea4c7b92-47b3-45fb-bd25-a8070f0c495c/user_impersonation
45
REACT_APP_FRONTEND_URL=http://localhost:3001

frontend/package-lock.json

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

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"@equinor/eds-core-react": "^0.20.4",
1010
"@equinor/eds-icons": "^0.18.0",
1111
"@equinor/eds-tokens": "^0.7.1",
12+
"@microsoft/applicationinsights-web": "^3.0.7",
1213
"@microsoft/signalr": "^7.0.12",
1314
"@testing-library/jest-dom": "^5.16.4",
1415
"@testing-library/react": "^13.3.0",

frontend/public/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
To create a production bundle, use `npm run build` or `yarn build`.
4040
--></body>
4141
<script>
42+
window.REACT_APP_AI_CONNECTION_STRING = '${REACT_APP_AI_CONNECTION_STRING}'
4243
window.REACT_APP_BACKEND_URL = '${REACT_APP_BACKEND_URL}'
4344
window.REACT_APP_BACKEND_API_SCOPE = '${REACT_APP_BACKEND_API_SCOPE}'
4445
window.REACT_APP_FRONTEND_URL = '${REACT_APP_FRONTEND_URL}'

frontend/run_nginx.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
22
# Substitute environment variables in the index.html file using the values in the current container environment
33
envsubst '
4+
${REACT_APP_AI_CONNECTION_STRING}
45
${REACT_APP_BACKEND_URL}
56
${REACT_APP_BACKEND_API_SCOPE}
67
${REACT_APP_FRONTEND_URL}

frontend/src/App.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ApplicationInsights } from '@microsoft/applicationinsights-web'
12
import { AuthenticatedTemplate, UnauthenticatedTemplate } from '@azure/msal-react'
23
import { AssetSelectionPage } from 'components/Pages/AssetSelectionPage/AssetSelectionPage'
34
import { FlotillaSite } from 'components/Pages/FlotillaSite'
@@ -11,6 +12,18 @@ import { InstallationProvider } from 'components/Contexts/InstallationContext'
1112
import { AuthProvider } from 'components/Contexts/AuthProvider'
1213
import { SignalRProvider } from 'components/Contexts/SignalRContext'
1314
import { RobotProvider } from 'components/Contexts/RobotContext'
15+
import { config } from 'config'
16+
17+
const appInsights = new ApplicationInsights({
18+
config: {
19+
connectionString: config.AI_CONNECTION_STRING,
20+
},
21+
})
22+
23+
if (config.AI_CONNECTION_STRING.length > 0) {
24+
appInsights.loadAppInsights()
25+
appInsights.trackPageView()
26+
}
1427

1528
const App = () => (
1629
<InstallationProvider>

frontend/src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const getEnvVariable = (name: string): string => {
1818
}
1919

2020
export const config = {
21+
AI_CONNECTION_STRING: getEnvVariable('REACT_APP_AI_CONNECTION_STRING'),
2122
BACKEND_URL: getEnvVariable('REACT_APP_BACKEND_URL'),
2223
BACKEND_API_SCOPE: getEnvVariable('REACT_APP_BACKEND_API_SCOPE'),
2324
BACKEND_API_SIGNALR_URL: getEnvVariable('REACT_APP_BACKEND_URL') + '/hub',

radixconfig.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ spec:
2222
environmentConfig:
2323
- environment: dev
2424
variables:
25+
REACT_APP_AI_CONNECTION_STRING: ""
2526
REACT_APP_BACKEND_URL: "https://backend-flotilla-dev.playground.radix.equinor.com"
2627
REACT_APP_BACKEND_API_SCOPE: "api://ea4c7b92-47b3-45fb-bd25-a8070f0c495c/user_impersonation"
2728
REACT_APP_FRONTEND_URL: "https://frontend-flotilla-dev.playground.radix.equinor.com"

0 commit comments

Comments
 (0)