Skip to content

Commit

Permalink
Capture telemetry for Graph Proxy API calls (#1098)
Browse files Browse the repository at this point in the history
* Capture telemetry for Graph Proxy API calls
  • Loading branch information
millicentachieng authored Sep 8, 2021
1 parent acaa326 commit 9ae78fd
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 42 deletions.
46 changes: 13 additions & 33 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,38 +86,21 @@ function getOSTheme(): string {

function applyCurrentSystemTheme(themeToApply: string): void {
loadGETheme(themeToApply);

// @ts-ignore
appState.dispatch(changeTheme(themeToApply));
appStore.dispatch(changeTheme(themeToApply));
}

const appState: any = store({
authToken: { token: false, pending: false },
consentedScopes: [],
isLoadingData: false,
profile: null,
queryRunnerStatus: null,
sampleQuery: {
sampleUrl: 'https://graph.microsoft.com/v1.0/me',
selectedVerb: 'GET',
sampleBody: undefined,
sampleHeaders: [],
selectedVersion: 'v1.0',
},
termsOfUse: true,
theme: currentTheme,
});
const appStore: any = store;

setCurrentSystemTheme();
appState.dispatch(getGraphProxyUrl());
appStore.dispatch(getGraphProxyUrl());

function refreshAccessToken() {
authenticationWrapper.getToken().then((authResponse: AuthenticationResult) => {
if (authResponse && authResponse.accessToken) {
appState.dispatch(getAuthTokenSuccess(true));
appState.dispatch(getConsentedScopesSuccess(authResponse.scopes));
}
})
if (authResponse && authResponse.accessToken) {
appStore.dispatch(getAuthTokenSuccess(true));
appStore.dispatch(getConsentedScopesSuccess(authResponse.scopes));
}
})
.catch(() => {
// ignore the error as it means that a User login is required
});
Expand All @@ -132,11 +115,8 @@ const theme = new URLSearchParams(location.search).get('theme');

if (theme) {
loadGETheme(theme);
appState.dispatch(changeThemeSuccess(theme));
}

if (theme) {
appState.dispatch(setGraphExplorerMode(Mode.TryIt));
appStore.dispatch(changeThemeSuccess(theme));
appStore.dispatch(setGraphExplorerMode(Mode.TryIt));
}

const devxApiUrl = new URLSearchParams(location.search).get('devx-api');
Expand All @@ -153,13 +133,13 @@ if (devxApiUrl && isValidHttpsUrl(devxApiUrl)) {
if (org && branchName) {
devxApi.parameters = `org=${org}&branchName=${branchName}`;
}
appState.dispatch(setDevxApiUrl(devxApi));
appStore.dispatch(setDevxApiUrl(devxApi));
}

readHistoryData().then((data: any) => {
if (data.length > 0) {
data.forEach((element: IHistoryItem) => {
appState.dispatch(addHistoryItem(element));
appStore.dispatch(addHistoryItem(element));
});
}
});
Expand Down Expand Up @@ -195,7 +175,7 @@ telemetryProvider.initialize();

const Root = () => {
return (
<Provider store={appState}>
<Provider store={appStore}>
<IntlProvider
locale={geLocale}
messages={(messages as { [key: string]: object })[geLocale]}
Expand Down
4 changes: 2 additions & 2 deletions src/messages/GE_de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@
"Signing you out...": "Sie werden abgemeldet...",
"Admin consent not required": "Administratorzustimmung nicht erforderlich",
"Navigation help": "Navigieren mit der NACH-RECHTS-TASTE für den Zugriff",
"Actions menu": " Menü \„Aktionen\“",
"Actions menu": " Menü Aktionen",
"user_cancelled": "Bitte warten Sie, bis der Authentifizierungsprozess abgeschlossen ist.",
"popup_window_error": "Bitte überprüfen Sie, ob Popups aktiviert sind, und versuchen Sie es erneut.",
"invalid_client": "Bitten Sie Ihren App-Administrator, die App-Anmeldeinformationen (Anwendungsclient-ID) bei Azure-App-Registrierungen zu überprüfen.",
Expand All @@ -379,4 +379,4 @@
"interaction_required_consent": "Bitte warten Sie, bis der Zustimmungsprozess abgeschlossen ist, und überprüfen Sie, ob Popups aktiviert sind.",
"user_cancelled_consent": "Bitte warten Sie, bis der Zustimmungsprozess abgeschlossen ist.",
"access_denied_consent": "Ihre Zustimmung zu dieser Berechtigung wurde von Ihrem Mandantenadministrator blockiert. Bitten Sie Ihren Administrator, Ihnen Zugriff zu gewähren, und versuchen Sie es dann erneut."
}
}
22 changes: 20 additions & 2 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ if (NODE_ENV === 'development') {
middlewares.push(loggerMiddleware);
}

export const store = (initialState: object): Store => {
return createStore(reducers, initialState, applyMiddleware(...middlewares));
const initialState: any = {
authToken: { token: false, pending: false },
consentedScopes: [],
isLoadingData: false,
profile: null,
queryRunnerStatus: null,
sampleQuery: {
sampleUrl: 'https://graph.microsoft.com/v1.0/me',
selectedVerb: 'GET',
sampleBody: undefined,
sampleHeaders: [],
selectedVersion: 'v1.0',
},
termsOfUse: true,
};

export const store = createStore(
reducers,
initialState,
applyMiddleware(...middlewares)
);
14 changes: 9 additions & 5 deletions src/telemetry/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { errorTypes } from '.';
import {
ADAPTIVE_CARD_URL,
DEVX_API_URL,
GRAPH_API_SANDBOX_ENDPOINT_URL,
GRAPH_API_SANDBOX_URL,
GRAPH_URL,
HOME_ACCOUNT_KEY
HOME_ACCOUNT_KEY,
} from '../app/services/graph-constants';
import {
sanitizeGraphAPISandboxUrl,
sanitizeQueryUrl
sanitizeQueryUrl,
} from '../app/utils/query-url-sanitization';
import { store } from '../store';

export function filterTelemetryTypes(envelope: ITelemetryItem) {
const baseType = envelope.baseType || '';
Expand All @@ -28,12 +28,16 @@ export function filterTelemetryTypes(envelope: ITelemetryItem) {
export function filterRemoteDependencyData(envelope: ITelemetryItem): boolean {
if (envelope.baseType === 'RemoteDependencyData') {
const baseData = envelope.baseData || {};

const urlObject = new URL(baseData.target || '');

const graphProxyUrl = store.getState()?.proxyUrl;

const targetsToInclude = [
GRAPH_URL, DEVX_API_URL, GRAPH_API_SANDBOX_URL, GRAPH_API_SANDBOX_ENDPOINT_URL,
GRAPH_URL,
DEVX_API_URL,
new URL(GRAPH_API_SANDBOX_URL).origin,
GRAPH_API_SANDBOX_URL,
new URL(graphProxyUrl).origin,
new URL(ADAPTIVE_CARD_URL).origin,
];
if (!targetsToInclude.includes(urlObject.origin)) {
Expand Down

0 comments on commit 9ae78fd

Please sign in to comment.