This commit is contained in:
Ying Zhao 2018-02-05 13:21:33 -08:00
Родитель 788ba873e0
Коммит 57330f9e80
17 изменённых файлов: 66 добавлений и 16 удалений

Просмотреть файл

@ -15,13 +15,14 @@ const srcPath = path.join(__dirname, '/../src')
const publicPath = '/assets/'
const config = {
entry: [
'babel-polyfill'
],
entry: {
app: ['babel-polyfill'],
appInsights: path.join(srcPath, 'appInsights')
},
devtool: 'eval',
output: {
path: path.join(__dirname, '/../dist/assets'),
filename: 'app.js',
filename: '[name].js',
publicPath: publicPath
},
devServer: {

Просмотреть файл

@ -39,5 +39,7 @@ module.exports = {
ticketUriPrefix: 'http://example2/ticketId=',
ticketUriSuffix: '&edit=false'
}
}
},
instrumentationKey: 'APP INSIGHT GOES HERE'
}

Просмотреть файл

@ -8,7 +8,7 @@ const config = Object.assign({}, baseConfig, {
devtool: 'eval-source-map'
})
config.entry.push(...[
config.entry.app.push(...[
'react-hot-loader/patch',
'webpack-hot-middleware/client?path=/__webpack_hmr&timeout=20000',
path.join(__dirname, '../src/index')

Просмотреть файл

@ -9,7 +9,7 @@ const config = Object.assign({}, baseConfig, {
devtool: 'sourcemap'
})
config.entry.push(path.join(__dirname, '../src/index'))
config.entry.app.push(path.join(__dirname, '../src/index'))
config.plugins.push(...[
new UglifyJSPlugin({ sourceMap: true }),

Просмотреть файл

@ -8,7 +8,7 @@ const config = Object.assign({}, baseConfig, {
devtool: 'eval-source-map'
})
config.entry.push(...[
config.entry.app.push(...[
'react-hot-loader/patch',
'webpack-hot-middleware/client?path=/__webpack_hmr&timeout=20000',
path.join(__dirname, '../src/index')

Просмотреть файл

@ -15,7 +15,7 @@ const config = Object.assign({}, baseConfig, {
}
})
config.entry.push('./test/loadtests.js')
config.entry.app.push('./test/loadtests.js')
config.plugins.push(new WebpackShellPlugin({
onBuildExit: 'mocha --colors temp/testBundle.js'

2
dist/assets/app.js поставляемый Normal file

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

2
dist/assets/app.js.map поставляемый

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

2
dist/assets/appInsights.js поставляемый Normal file

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

1
dist/assets/appInsights.js.map поставляемый Normal file

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

8
dist/index.html поставляемый
Просмотреть файл

@ -1,5 +1,13 @@
<!doctype html>
<html>
<!--
To collect end-user usage analytics about your application,
insert the following script into each page you want to track.
Place this code immediately before the closing </head> tag,
and before any other scripts. Your first data will appear
automatically in just a few seconds.
-->
<script type="text/javascript" src="/assets/appInsights.js"></script>
<head>
<meta charset="utf-8">
<title>SRE Incident Assistant</title>

Просмотреть файл

@ -3,14 +3,22 @@ export const USER_LOGGED_IN = 'USER_LOGGED_IN'
export const USER_LOGGED_OUT = 'USER_LOGGED_OUT'
export const USER_LOGIN_ERROR = 'USER_LOGIN_ERROR'
var registerAuthenticatedId = (signInId) => {
var validatedId = signInId.replace(/[,;=| ]+/g, "_");
appInsights.setAuthenticatedUserContext(validatedId, null, true);
}
export const loginInProgress = () => ({
type: LOGIN_IN_PROGRESS
})
export const userLoggedIn = (user) => ({
type: USER_LOGGED_IN,
user
})
export const userLoggedIn = (user) =>{
registerAuthenticatedId(user.userName)
return ({
type: USER_LOGGED_IN,
user
})
}
export const userLoggedOut = () => ({
type: USER_LOGGED_OUT

9
src/appInsights.js Normal file
Просмотреть файл

@ -0,0 +1,9 @@
import config from 'config'
var appInsights=window.appInsights||function(a){
function b(a){c[a]=function(){var b=arguments;c.queue.push(function(){c[a].apply(c,b)})}}var c={config:a},d=document,e=window;setTimeout(function(){var b=d.createElement("script");b.src=a.url||"https://az416426.vo.msecnd.net/scripts/a/ai.0.js",d.getElementsByTagName("script")[0].parentNode.appendChild(b)});try{c.cookie=d.cookie}catch(a){}c.queue=[];for(var f=["Event","Exception","Metric","PageView","Trace","Dependency"];f.length;)b("track"+f.pop());if(b("setAuthenticatedUserContext"),b("clearAuthenticatedUserContext"),b("startTrackEvent"),b("stopTrackEvent"),b("startTrackPage"),b("stopTrackPage"),b("flush"),!a.disableExceptionTracking){f="onerror",b("_"+f);var g=e[f];e[f]=function(a,b,d,e,h){var i=g&&g(a,b,d,e,h);return!0!==i&&c["_"+f](a,b,d,e,h),i}}return c
}({
instrumentationKey: config.instrumentationKey
});
window.appInsights=appInsights,appInsights.queue&&0===appInsights.queue.length&&appInsights.trackPageView()&&appInsights.trackDependency()&&appInsights.setAuthenticatedUserContext();

Просмотреть файл

@ -1,5 +1,13 @@
<!doctype html>
<html>
<!--
To collect end-user usage analytics about your application,
insert the following script into each page you want to track.
Place this code immediately before the closing </head> tag,
and before any other scripts. Your first data will appear
automatically in just a few seconds.
-->
<script type="text/javascript" src="/assets/appInsights.js"></script>
<head>
<meta charset="utf-8">
<title>SRE Incident Assistant</title>

Просмотреть файл

@ -5,6 +5,7 @@ import { AppContainer as HotContainer } from 'react-hot-loader'
import { store, persistor } from 'configureStore'
import MainComponent from 'components/MainComponent'
import 'appInsights'
require('./styles/App.css')

Просмотреть файл

@ -26,12 +26,15 @@ export const getAuthContext = (dispatch) => {
export const login = (dispatch) => {
if (typeof window !== 'undefined' && !!window) {
getAuthContext(dispatch).login()
appInsights.trackEvent("SIA Login")
} else {
dispatch(authActions.userLoginError('Window is undefined, so ADAL cannot function!'))
}
}
export const logOut = (dispatch) => {
appInsights.trackEvent("SIA Logout")
getAuthContext(dispatch).logOut()
dispatch(authActions.userLoggedOut())
}

Просмотреть файл

@ -2,6 +2,7 @@ import { rawHttpResponse, jsonResult } from 'actions/debugActions'
import PromiseRetry from 'promise-retry'
import { getToken } from 'services/authNService'
import config from 'config'
import { isUndefined } from 'util';
export const clientId = config.clientId
@ -15,12 +16,15 @@ const defaultOptions = {
const defaultScopes = [clientId]
const tryFetch = (dispatch, relativeUrl, init, returnJson = true, baseUrl = defaultBasePath) => (retry, number) => {
var startTime = new Date().getTime()
return fetch(baseUrl + relativeUrl, init)
.then(response => {
var timeUsed = new Date() - startTime
appInsights.trackDependency("myAjaxCall", init.method? init.method: "GET", [baseUrl + relativeUrl], relativeUrl, timeUsed, response.ok, response.status)
const localResponse = response
dispatch(rawHttpResponse(response))
dispatch(rawHttpResponse(response))
if (httpResponseNeedsRetry(response)) {
retry(`HTTP Response Needs Retry (retry ${number})`)
retry(`HTTP Response Needs Retry (retry ${number})`)
} else {
if (returnJson) {
return response
@ -45,6 +49,7 @@ export const authenticatedFetch = (dispatch, relativeUrl, init, returnJson = tru
defaultOptions
).then(token => {
const authenticatedInit = initWithAuth(init, token)
return PromiseRetry(
tryFetch(dispatch, relativeUrl, authenticatedInit, returnJson, baseUrl),
defaultOptions