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

Usage collection methods should be available during start and not just during setup #69835

Closed
jasonrhodes opened this issue Jun 24, 2020 · 3 comments · Fixed by #69836
Closed
Assignees
Labels
Feature:Telemetry Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc

Comments

@jasonrhodes
Copy link
Member

Currently, the UsageCollection plugin makes some methods available on its plugin setup contract, but doesn't return anything from its start lifecycle method. For other plugins to use these methods on the client, they need to reference a setup dependency from within a mount callback, like so:

setup(core, setupPlugins) {
  core.application.register({
    mount: (params) => {
      return <MyApp core={core} usage={setupPlugins.usageCollection} />
    }
  });
}

This is an anti-pattern because setup APIs should not be called after the setup lifecycle is complete, and the mount method is not called until after the setup method is complete. (@joshdover please make sure I'm not mis-representing this?)

Instead, a callback like mount should use the start contract via core.getStartServices(), like so:

setup(core, setupPlugins) {
  core.application.register({
    mount: async (params) => {
      const startPlugins = await core.getStartServices();
      return <MyApp core={core} usage={startPlugins.usageCollection} />
    }
  });
}

In order for plugins to correctly reference the usageCollection plugin inside mount (or other async callbacks), the setup contract must also be returned from the start lifecycle method inside the UsageCollection plugin.

@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-telemetry (Team:KibanaTelemetry)

@jasonrhodes
Copy link
Member Author

Linked issue: #58014

@lukeelmers lukeelmers added the Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc label Oct 1, 2021
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-core (Team:Core)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Telemetry Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants