Skip to content

Instantly share code, notes, and snippets.

@chrisobriensp
Created August 24, 2017 16:57
Show Gist options
  • Select an option

  • Save chrisobriensp/3d4adbe48730e0b6c35f3bae3ea0b77b to your computer and use it in GitHub Desktop.

Select an option

Save chrisobriensp/3d4adbe48730e0b6c35f3bae3ea0b77b to your computer and use it in GitHub Desktop.
Uses Azure App Insights to track that a call to the Graph has occurred (and the duration).
private loadUpcomingMeetings(): void {
this.setState((previousState: IUpcomingMeetingsState, props: IUpcomingMeetingsProps): IUpcomingMeetingsState => {
previousState.loading = true;
return previousState;
});
this.getGraphAccessToken()
.then((accessToken: string): Promise<IMeeting[]> => {
// start timer here..
this._startTime = new Date();
return UpcomingMeetings.getUpcomingMeetings(accessToken, this.props.httpClient);
})
.then((upcomingMeetings: IMeeting[]): void => {
this.setState((prevState: IUpcomingMeetingsState, props: IUpcomingMeetingsProps): IUpcomingMeetingsState => {
prevState.loading = false;
prevState.upcomingMeetings = upcomingMeetings;
// end timer here and log..
this._endTime = new Date();
var timeTaken: number = this._endTime.valueOf() - this._startTime.valueOf();
console.log(`componentWillMount: Took ${ timeTaken } ms to call Graph.`);
AppInsights.trackEvent("Fetch calendar events",
{},
{ timeTaken: timeTaken }
);
return prevState;
});
}, (error: any): void => {
this.setState((prevState: IUpcomingMeetingsState, props: IUpcomingMeetingsProps): IUpcomingMeetingsState => {
prevState.loading = false;
prevState.error = error;
return prevState;
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment