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

Collect adaptive cards remote dependency telemetry #1004

Merged
merged 3 commits into from
Jul 6, 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
10 changes: 10 additions & 0 deletions src/app/middleware/telemetryMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
};
Expand Down
33 changes: 12 additions & 21 deletions src/app/services/actions/adaptive-cards-action-creator.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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);
}

2 changes: 1 addition & 1 deletion src/app/services/actions/query-action-creator-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
3 changes: 2 additions & 1 deletion src/app/services/graph-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
9 changes: 7 additions & 2 deletions src/telemetry/filters.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;
}
Expand Down