Skip to content

Commit

Permalink
Add telemetry hook (#282)
Browse files Browse the repository at this point in the history
* publish

* telemetry hook

* address comment
  • Loading branch information
rihorn2 committed Jul 9, 2020
1 parent a6b72e5 commit e82fc09
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 0 deletions.
Expand Up @@ -58,6 +58,7 @@ import { ModelExplanationUtils } from './ModelExplanationUtils';
import { IBarChartConfig } from './SharedComponents/IBarChartConfig';
import { EbmExplanation } from './Controls/EbmExplanation';
import { JointDataset } from './JointDataset';
import { TelemetryLevels } from './Interfaces/ITelemetryMessage';

const s = require('./ExplanationDashboard.css');
const RowIndex = 'rowIndex';
Expand Down Expand Up @@ -130,6 +131,13 @@ export class ExplanationDashboard extends React.Component<IExplanationDashboardP
const modelMetadata = ExplanationDashboard.buildModelMetadata(props);
const errorMessage = ExplanationDashboard.validateInputs(props, modelMetadata);
if (errorMessage !== undefined) {
if (props.telemetryHook !== undefined) {
props.telemetryHook({
message: "Invalid inputs",
level: TelemetryLevels.error,
context: errorMessage
});
}
return {
modelMetadata,
explanationGenerators,
Expand Down
@@ -1,4 +1,5 @@
import IStringsParam from './IStringsParam';
import { ITelemetryMessage } from './ITelemetryMessage';

// This is the interface of the data to be provided by any glue code, be it the ModelExplanationController, the Jupyter widget,
// or some future extension. The Explanation Dashboard opperates on this data object, and an optional chart config that specifies
Expand Down Expand Up @@ -29,6 +30,7 @@ export interface IExplanationDashboardProps {
shouldInitializeIcons?: boolean;
iconUrl?: string;
explanationMethod?: string;
telemetryHook?: (message: ITelemetryMessage) => void;
requestPredictions?: (request: any[], abortSignal: AbortSignal) => Promise<any[]>;
requestLocalFeatureExplanations?: (
request: any[],
Expand Down
@@ -0,0 +1,18 @@
export enum TelemetryLevels {
error = 'Error',
warning = 'Warning',
info = 'Info',
trace = 'Trace'
}

export type TelemetryLevel =
TelemetryLevels.error |
TelemetryLevels.warning |
TelemetryLevels.info |
TelemetryLevels.trace;

export interface ITelemetryMessage {
level: TelemetryLevel;
message?: string;
context?: any;
}
@@ -1,2 +1,3 @@
export * from './IExplanationDashboardProps';
export * from './IStringsParam';
export * from './ITelemetryMessage'
Expand Up @@ -3,6 +3,7 @@ import {
IExplanationDashboardProps,
IMultiClassLocalFeatureImportance,
ISingleClassLocalFeatureImportance,
TelemetryLevels,
} from './Interfaces';
import { JointDataset } from './JointDataset';
import { ModelMetadata } from 'mlchartlib';
Expand Down Expand Up @@ -287,6 +288,13 @@ export class NewExplanationDashboard extends React.PureComponent<
const globalProps = NewExplanationDashboard.buildGlobalProperties(props);
// consider taking filters in as param arg for programatic users
const cohorts = [new Cohort(localization.Cohort.defaultLabel, jointDataset, [])];
if (validationCheck.errorStrings.length !== 0 && props.telemetryHook !== undefined) {
props.telemetryHook({
message: "Invalid inputs",
level: TelemetryLevels.error,
context: validationCheck.errorStrings.length
});
}
return {
cohorts,
validationWarnings: validationCheck.errorStrings,
Expand Down
2 changes: 2 additions & 0 deletions visualization/test/test-page/App.jsx
Expand Up @@ -251,6 +251,7 @@ import { createTheme } from "@uifabric/styling";
this.generateRandomScore :
this.generateRandomProbs.bind(this, classDimension)}
stringParams={{contextualHelp: this.messages}}
telemetryHook={(er) => {console.error(er.message)}}
theme={theme}
explanationMethod="mimic"
locale={this.state.language}
Expand All @@ -270,6 +271,7 @@ import { createTheme } from "@uifabric/styling";
}}
requestPredictions={this.generateRandomProbs.bind(this, classDimension)}
stringParams={{contextualHelp: this.messages}}
telemetryHook={(er) => {console.error(er.message)}}
theme={theme}
locale={this.state.language}
key={new Date()}
Expand Down

0 comments on commit e82fc09

Please sign in to comment.