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

expose apm instance from framework integrations #799

Open
vigneshshanmugam opened this issue May 27, 2020 · 3 comments
Open

expose apm instance from framework integrations #799

vigneshshanmugam opened this issue May 27, 2020 · 3 comments
Milestone

Comments

@vigneshshanmugam
Copy link
Member

vigneshshanmugam commented May 27, 2020

  • Avoid having to import @elastic/apm-rum for the sole purpose of initialisation and avoid users from download duplicated apm-rum package if multiple packages are imported in different entry points.

Solutions

This is a common problem and we have to deal with it There are couple of options.

1. Exposing apmBase, apm from @elastic/apm-rum-*(react/angular/vue) packages

This would let users to use to initialise the agent from the imports of a single package and would remove the need to import @elastic/apm-rum for initialisation purpose alone. This is already done in VuePlugin and AngularService but react package doesn't expose it.

2. Relying on window.elasticApm in framework integrations

This has huge disadvantages.

  • We expect the users to load apmbase before the framework package which would result in window.elasticApm not being found if any of the modules was downloaded async and we cannot dynamically import if the package isn't found.

Looking at both options, I would say No.1 is an easy solution and best approach.

@hmdhk
Copy link
Contributor

hmdhk commented May 27, 2020

@vigneshshanmugam , the first solution would not address the need to split the bundle (e.g. vendor vs app), we should investigate a bit more to find an optimal solution.

@vigneshshanmugam
Copy link
Member Author

first solution would not address the need to split the bundle (e.g. vendor vs app),

Can you provide an example? With the 1st change, The user shouldn't even need to care about whether vendor or app. Because the bundler takes care of the duplication as its already imported ass part of the first page and not required to be downloaded for subsequent pages.

app.js

import { apm } from '@elastic/apm-rum-react'

apm.init({})

/page/apm.js

import { ApmRoute } from '@elastic/apm-rum-react'

React.render(<App>
    <ApmRoute path="/a" component={}>
</App>)

It is now the bundlers job to use the exported bundles and bundle them in the appropriate bundles. We can do a small setup with this using webpack and test it. Do you have any other case that I missed here?

@hmdhk
Copy link
Contributor

hmdhk commented May 29, 2020

@vigneshshanmugam , I've summarised a 3rd solution here: #804 , that is probably longer term and might require a breaking change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants