Skip to content

Commit

Permalink
Makes usage collection methods available on start
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonrhodes committed Jun 24, 2020
1 parent 5e3798c commit 68f1de5
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/plugins/usage_collection/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,17 @@ export interface UsageCollectionSetup {
};
}

export interface UsageCollectionStart {
reportUiStats: Reporter['reportUiStats'];
METRIC_TYPE: typeof METRIC_TYPE;
}

export function isUnauthenticated(http: HttpSetup) {
const { anonymousPaths } = http;
return anonymousPaths.isAnonymous(window.location.pathname);
}

export class UsageCollectionPlugin implements Plugin<UsageCollectionSetup> {
export class UsageCollectionPlugin implements Plugin<UsageCollectionSetup, UsageCollectionStart> {
private readonly legacyAppId$ = new Subject<string>();
private trackUserAgent: boolean = true;
private reporter?: Reporter;
Expand Down Expand Up @@ -90,7 +95,7 @@ export class UsageCollectionPlugin implements Plugin<UsageCollectionSetup> {

public start({ http, application }: CoreStart) {
if (!this.reporter) {
return;
throw new Error('Usage collection reporter not set up correctly');
}

if (this.config.uiMetric.enabled && !isUnauthenticated(http)) {
Expand All @@ -100,7 +105,13 @@ export class UsageCollectionPlugin implements Plugin<UsageCollectionSetup> {
if (this.trackUserAgent) {
this.reporter.reportUserAgent('kibana');
}

reportApplicationUsage(merge(application.currentAppId$, this.legacyAppId$), this.reporter);

return {
reportUiStats: this.reporter.reportUiStats,
METRIC_TYPE,
};
}

public stop() {}
Expand Down

0 comments on commit 68f1de5

Please sign in to comment.