Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture telemetry for Graph Proxy API calls #1098

Merged
merged 5 commits into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 10 additions & 30 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,36 +86,19 @@ 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));
appStore.dispatch(getAuthTokenSuccess(true));
appStore.dispatch(getConsentedScopesSuccess(authResponse.scopes));
}
})
.catch(() => {
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]}>
<App />
</IntlProvider>
Expand Down
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