Skip to content

Commit

Permalink
Task: reactivate app insights (#591)
Browse files Browse the repository at this point in the history
* get instrumentation key from environment config

* track run query events

* add instrumentation key to pipeline

* add check for instrumentation key from window object
  • Loading branch information
thewahome committed Jun 24, 2020
1 parent 9717c8c commit d9b33a1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ steps:
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/dev'))
env:
REACT_APP_CLIENT_ID: $(REACT_APP_STAGING_CLIENT_ID)
REACT_APP_INSTRUMENTATION_KEY: $(REACT_APP_INSTRUMENTATION_KEY)
displayName: 'Build static assets for staging'
- script: |
npm run build
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
env:
REACT_APP_CLIENT_ID: $(REACT_APP_PROD_CLIENT_ID)
REACT_APP_INSTRUMENTATION_KEY: $(REACT_APP_INSTRUMENTATION_KEY)
displayName: 'Build static assets for prod'
- task: PublishCodeCoverageResults@1
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/app/views/query-runner/QueryRunner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { injectIntl } from 'react-intl';
import { connect } from 'react-redux';
import { bindActionCreators, Dispatch } from 'redux';

import { telemetry } from '../../../telemetry';
import { RUN_QUERY_EVENT } from '../../../telemetry/event-types';
import {
IQueryRunnerProps,
IQueryRunnerState,
Expand All @@ -15,7 +17,6 @@ import { parseSampleUrl } from '../../utils/sample-url-generation';
import './query-runner.scss';
import QueryInput from './QueryInput';
import Request from './request/Request';

export class QueryRunner extends Component<
IQueryRunnerProps,
IQueryRunnerState
Expand Down Expand Up @@ -88,6 +89,7 @@ export class QueryRunner extends Component<
if (actions) {
actions.runQuery(sampleQuery);
}
telemetry.trackEvent(RUN_QUERY_EVENT, sampleQuery);
};

private handleOnVersionChange = (urlVersion?: IDropdownOption) => {
Expand Down
3 changes: 3 additions & 0 deletions src/app/views/sidebar/sample-queries/SampleQueries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { connect } from 'react-redux';
import { bindActionCreators, Dispatch } from 'redux';

import { geLocale } from '../../../../appLocale';
import { telemetry } from '../../../../telemetry';
import { RUN_QUERY_EVENT } from '../../../../telemetry/event-types';
import { IQuery, ISampleQueriesProps, ISampleQuery } from '../../../../types/query-runner';
import * as queryActionCreators from '../../../services/actions/query-action-creators';
import * as queryInputActionCreators from '../../../services/actions/query-input-action-creators';
Expand Down Expand Up @@ -296,6 +298,7 @@ export class SampleQueries extends Component<ISampleQueriesProps, any> {
} else {
actions.runQuery(sampleQuery);
}
telemetry.trackEvent(RUN_QUERY_EVENT, sampleQuery);
} else {
sampleQuery.sampleBody = (sampleQuery.sampleBody) ? JSON.parse(sampleQuery.sampleBody) : undefined;
if (selectedQuery.tip) { displayTipMessage(actions, selectedQuery); }
Expand Down
4 changes: 2 additions & 2 deletions src/telemetry/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Telemetry implements ITelemetry {
private reactPlugin: any;

constructor() {
this.reactPlugin = new ReactPlugin();
this.reactPlugin = new ReactPlugin();

this.config = {
instrumentationKey: this.getInstrumentationKey(),
Expand Down Expand Up @@ -57,7 +57,7 @@ class Telemetry implements ITelemetry {
}

private getInstrumentationKey() {
return (window as any).InstrumentationKey || '';
return (window as any).InstrumentationKey || process.env.REACT_APP_INSTRUMENTATION_KEY || '';
}
}

Expand Down

0 comments on commit d9b33a1

Please sign in to comment.