Skip to content

Commit

Permalink
Add application insights for frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
MuhammadUsama-afk-equinor authored and UsamaEquinorAFK committed Jan 9, 2024
1 parent 4f761ba commit 1dcb56c
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/frontend_lint_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
- run: npm test
env:
PORT: 3001
REACT_APP_AI_CONNECTION_STRING: ""
REACT_APP_BACKEND_URL: https://localhost:8000
REACT_APP_BACKEND_API_SCOPE: api://ea4c7b92-47b3-45fb-bd25-a8070f0c495c/user_impersonation
REACT_APP_FRONTEND_URL: http://localhost:3001
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ services:
ports:
- "3001:3001"
environment:
- REACT_APP_AI_CONNECTION_STRING=
- REACT_APP_BACKEND_URL=http://localhost:8000
- REACT_APP_BACKEND_API_SCOPE=api://ea4c7b92-47b3-45fb-bd25-a8070f0c495c/user_impersonation
- REACT_APP_FRONTEND_URL=http://localhost:3001
Expand Down
1 change: 1 addition & 0 deletions frontend/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
PORT=3001
REACT_APP_AI_CONNECTION_STRING=""
REACT_APP_BACKEND_URL=https://localhost:8000
REACT_APP_BACKEND_API_SCOPE=api://ea4c7b92-47b3-45fb-bd25-a8070f0c495c/user_impersonation
REACT_APP_FRONTEND_URL=http://localhost:3001
Expand Down
157 changes: 157 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"@equinor/eds-core-react": "^0.20.4",
"@equinor/eds-icons": "^0.18.0",
"@equinor/eds-tokens": "^0.7.1",
"@microsoft/applicationinsights-web": "^3.0.7",
"@microsoft/signalr": "^7.0.12",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.3.0",
Expand Down
1 change: 1 addition & 0 deletions frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
To create a production bundle, use `npm run build` or `yarn build`.
--></body>
<script>
window.REACT_APP_AI_CONNECTION_STRING = '${REACT_APP_AI_CONNECTION_STRING}'
window.REACT_APP_BACKEND_URL = '${REACT_APP_BACKEND_URL}'
window.REACT_APP_BACKEND_API_SCOPE = '${REACT_APP_BACKEND_API_SCOPE}'
window.REACT_APP_FRONTEND_URL = '${REACT_APP_FRONTEND_URL}'
Expand Down
1 change: 1 addition & 0 deletions frontend/run_nginx.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
# Substitute environment variables in the index.html file using the values in the current container environment
envsubst '
${REACT_APP_AI_CONNECTION_STRING}
${REACT_APP_BACKEND_URL}
${REACT_APP_BACKEND_API_SCOPE}
${REACT_APP_FRONTEND_URL}
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ApplicationInsights } from '@microsoft/applicationinsights-web'
import { AuthenticatedTemplate, UnauthenticatedTemplate } from '@azure/msal-react'
import { AssetSelectionPage } from 'components/Pages/AssetSelectionPage/AssetSelectionPage'
import { FlotillaSite } from 'components/Pages/FlotillaSite'
Expand All @@ -11,6 +12,18 @@ import { InstallationProvider } from 'components/Contexts/InstallationContext'
import { AuthProvider } from 'components/Contexts/AuthProvider'
import { SignalRProvider } from 'components/Contexts/SignalRContext'
import { RobotProvider } from 'components/Contexts/RobotContext'
import { config } from 'config'

const appInsights = new ApplicationInsights({
config: {
connectionString: config.AI_CONNECTION_STRING,
},
})

if (config.AI_CONNECTION_STRING.length > 0) {
appInsights.loadAppInsights()
appInsights.trackPageView()
}

const App = () => (
<InstallationProvider>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const getEnvVariable = (name: string): string => {
}

export const config = {
AI_CONNECTION_STRING: getEnvVariable('REACT_APP_AI_CONNECTION_STRING'),
BACKEND_URL: getEnvVariable('REACT_APP_BACKEND_URL'),
BACKEND_API_SCOPE: getEnvVariable('REACT_APP_BACKEND_API_SCOPE'),
BACKEND_API_SIGNALR_URL: getEnvVariable('REACT_APP_BACKEND_URL') + '/hub',
Expand Down
1 change: 1 addition & 0 deletions radixconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ spec:
environmentConfig:
- environment: dev
variables:
REACT_APP_AI_CONNECTION_STRING: ""
REACT_APP_BACKEND_URL: "https://backend-flotilla-dev.playground.radix.equinor.com"
REACT_APP_BACKEND_API_SCOPE: "api://ea4c7b92-47b3-45fb-bd25-a8070f0c495c/user_impersonation"
REACT_APP_FRONTEND_URL: "https://frontend-flotilla-dev.playground.radix.equinor.com"
Expand Down

0 comments on commit 1dcb56c

Please sign in to comment.