diff --git a/src/app/middleware/telemetryMiddleware.ts b/src/app/middleware/telemetryMiddleware.ts index 7504eae93..6148dbb96 100644 --- a/src/app/middleware/telemetryMiddleware.ts +++ b/src/app/middleware/telemetryMiddleware.ts @@ -4,6 +4,7 @@ import { IAction } from '../../types/action'; import { IQuery } from '../../types/query-runner'; import { IRootState } from '../../types/root'; import { + FETCH_ADAPTIVE_CARD_ERROR, FETCH_SCOPES_ERROR, GET_SNIPPET_ERROR, SAMPLES_FETCH_ERROR, @@ -45,6 +46,15 @@ const telemetryMiddleware = ); break; } + case FETCH_ADAPTIVE_CARD_ERROR: { + trackException( + componentNames.GET_ADAPTIVE_CARD_ACTION, + state.sampleQuery, + action.response, + {} + ); + break; + } } return next(action); }; diff --git a/src/app/services/actions/adaptive-cards-action-creator.ts b/src/app/services/actions/adaptive-cards-action-creator.ts index 393b762bc..ba9307939 100644 --- a/src/app/services/actions/adaptive-cards-action-creator.ts +++ b/src/app/services/actions/adaptive-cards-action-creator.ts @@ -1,11 +1,9 @@ -import { SeverityLevel } from '@microsoft/applicationinsights-web'; import * as AdaptiveCardsTemplateAPI from 'adaptivecards-templating'; -import { componentNames, errorTypes, telemetry } from '../../../telemetry'; import { IAction } from '../../../types/action'; import { IAdaptiveCardContent } from '../../../types/adaptivecard'; import { IQuery } from '../../../types/query-runner'; import { lookupTemplate } from '../../utils/adaptive-cards-lookup'; -import { sanitizeQueryUrl } from '../../utils/query-url-sanitization'; +import { ADAPTIVE_CARD_URL } from '../graph-constants'; import { FETCH_ADAPTIVE_CARD_ERROR, FETCH_ADAPTIVE_CARD_PENDING, @@ -56,37 +54,30 @@ export function getAdaptiveCard( dispatch(getAdaptiveCardPending()); try { - const response = await fetch(`https://templates.adaptivecards.io/graph.microsoft.com/${templateFileName}`); + const response = await fetch(`${ADAPTIVE_CARD_URL}/${templateFileName}`); const templatePayload = await response.json(); const card = createCardFromTemplate(templatePayload, payload); - const adaptiveCardContent: IAdaptiveCardContent = { card, template: templatePayload }; + const adaptiveCardContent: IAdaptiveCardContent = { + card, + template: templatePayload, + }; return dispatch(getAdaptiveCardSuccess(adaptiveCardContent)); - } catch (error) { // something wrong happened - const sanitizedUrl = sanitizeQueryUrl(sampleQuery.sampleUrl); - telemetry.trackException( - new Error(errorTypes.NETWORK_ERROR), - SeverityLevel.Error, - { - ComponentName: componentNames.GET_ADAPTIVE_CARD_ACTION, - QuerySignature: `${sampleQuery.selectedVerb} ${sanitizedUrl}`, - Message: `${error}` - } - ); return dispatch(getAdaptiveCardError(error)); } }; } -function createCardFromTemplate(templatePayload: any, payload: string): AdaptiveCardsTemplateAPI.Template { +function createCardFromTemplate( + templatePayload: any, + payload: string +): AdaptiveCardsTemplateAPI.Template { const template = new AdaptiveCardsTemplateAPI.Template(templatePayload); const context: AdaptiveCardsTemplateAPI.IEvaluationContext = { $root: payload, }; - AdaptiveCardsTemplateAPI.GlobalSettings.getUndefinedFieldValueSubstitutionString = ( - _path: string - ) => ' '; + AdaptiveCardsTemplateAPI.GlobalSettings.getUndefinedFieldValueSubstitutionString = + (_path: string) => ' '; return template.expand(context); } - diff --git a/src/app/services/actions/query-action-creator-util.ts b/src/app/services/actions/query-action-creator-util.ts index 41bef322d..fcbcd51c8 100644 --- a/src/app/services/actions/query-action-creator-util.ts +++ b/src/app/services/actions/query-action-creator-util.ts @@ -22,7 +22,7 @@ export function queryResponse(response: object): IAction { export async function anonymousRequest(dispatch: Function, query: IQuery) { const authToken = '{token:https://graph.microsoft.com/}'; const escapedUrl = encodeURIComponent(query.sampleUrl); - const graphUrl = `${GRAPH_API_SANDBOX_URL}/svc?url=${escapedUrl}`; + const graphUrl = `${GRAPH_API_SANDBOX_URL}?url=${escapedUrl}`; const sampleHeaders: any = {}; if (query.sampleHeaders && query.sampleHeaders.length > 0) { query.sampleHeaders.forEach((header) => { diff --git a/src/app/services/graph-constants.ts b/src/app/services/graph-constants.ts index 8820c2430..e2782f3dd 100644 --- a/src/app/services/graph-constants.ts +++ b/src/app/services/graph-constants.ts @@ -4,5 +4,6 @@ export const USER_PICTURE_URL = `${GRAPH_URL}/beta/me/photo/$value`; export const AUTH_URL = 'https://login.microsoftonline.com'; export const DEFAULT_USER_SCOPES = 'openid profile User.Read'; export const DEVX_API_URL = 'https://graphexplorerapi.azurewebsites.net'; -export const GRAPH_API_SANDBOX_URL = 'https://proxy.apisandbox.msdn.microsoft.com'; +export const GRAPH_API_SANDBOX_URL = 'https://proxy.apisandbox.msdn.microsoft.com/svc'; export const HOME_ACCOUNT_KEY = 'fbf1ecbe-27ab-42d7-96d4-3e6b03682ee4'; +export const ADAPTIVE_CARD_URL = 'https://templates.adaptivecards.io/graph.microsoft.com'; diff --git a/src/telemetry/filters.ts b/src/telemetry/filters.ts index 7f13d9335..7139e33f7 100644 --- a/src/telemetry/filters.ts +++ b/src/telemetry/filters.ts @@ -1,11 +1,11 @@ import { ITelemetryItem } from '@microsoft/applicationinsights-web'; -import { exception } from 'console'; import { errorTypes } from '.'; import { DEVX_API_URL, GRAPH_API_SANDBOX_URL, GRAPH_URL, HOME_ACCOUNT_KEY, + ADAPTIVE_CARD_URL, } from '../app/services/graph-constants'; import { sanitizeGraphAPISandboxUrl, @@ -29,7 +29,12 @@ export function filterRemoteDependencyData(envelope: ITelemetryItem): boolean { const baseData = envelope.baseData || {}; const urlObject = new URL(baseData.target || ''); - const targetsToInclude = [GRAPH_URL, DEVX_API_URL, GRAPH_API_SANDBOX_URL]; + const targetsToInclude = [ + GRAPH_URL, + DEVX_API_URL, + new URL(GRAPH_API_SANDBOX_URL).origin, + new URL(ADAPTIVE_CARD_URL).origin, + ]; if (!targetsToInclude.includes(urlObject.origin)) { return false; }