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

Move src/apm.js to @kbn/apm-config-loader #94315

Merged
merged 6 commits into from
Mar 14, 2021

Conversation

pgayvallet
Copy link
Contributor

@pgayvallet pgayvallet commented Mar 10, 2021

Summary

Fix #93823
Part of #94141

PR removes the dependency from core to /src/apm.js by moving the apm script to the @kbn/apm-config-loader package.

Checklist

@pgayvallet pgayvallet added v7.13.0 Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc release_note:skip Skip the PR/issue when compiling release notes labels Mar 10, 2021
@pgayvallet pgayvallet marked this pull request as ready for review March 10, 2021 19:27
@pgayvallet pgayvallet requested review from vigneshshanmugam and a team as code owners March 10, 2021 19:27
@elasticmachine
Copy link
Contributor

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

// Filter out all user PII
apm.addFilter((payload: Record<string, any>) => {
try {
if (payload.context && payload.context.user && typeof payload.context.user === 'object') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super-NIT:

Suggested change
if (payload.context && payload.context.user && typeof payload.context.user === 'object') {
if (payload.context?.user && typeof payload.context.user === 'object') {

Copy link
Contributor Author

@pgayvallet pgayvallet Mar 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't use ? operator in packages code. Not sure why (well, we're not using babel for packages, only tsc, so it's probably that), but we can't.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. What an error did you see?
Optional chaining is supported natively in node.js v14.
We also use it in other packages

const isEnabled = validatedConfig?.enabled ?? config.get(enabledPath);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, may be a while back then. Did the change


// we want to only load the module when effectively used
// eslint-disable-next-line @typescript-eslint/no-var-requires
const apm = require('elastic-apm-node');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understood correctly, we use this same agent for the UI. However, this is the elastic-apm-node package, which is different from the @elastic/apm-rum used on the UI.

Are we sure that we can reuse the same agent initialization for both: server and public?

Copy link
Contributor Author

@pgayvallet pgayvallet Mar 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is only executed on the server-side.

We're not using the same agent on server and browser (apm agent vs rum agent), we're just sharing the same configuration and factorizing the configuration loading logic (the RUM config is then sent to the client in the injected metadatas).

Note that nothing changed in this PR in term of design/architecture, we just moved the script to a package to resolve the cyclic dependency between core and cli.

const { name, build } = require('../../package.json');
const { initApm } = require('@kbn/apm-config-loader');

const rootDir = join(__dirname, '../..');
Copy link
Contributor

@mshustov mshustov Mar 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: we have a package for everything:

import { REPO_ROOT, kibanaPackageJson } from '@kbn/utils';

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@pgayvallet pgayvallet merged commit ed5bbda into elastic:master Mar 14, 2021
pgayvallet added a commit to pgayvallet/kibana that referenced this pull request Mar 14, 2021
* Move src/apm.js to @kbn/apm-config-loader

* add unit tests for `initApm`

* return undefined instead of empty config

* use ?.
pgayvallet added a commit that referenced this pull request Mar 15, 2021
* Move src/apm.js to @kbn/apm-config-loader

* add unit tests for `initApm`

* return undefined instead of empty config

* use ?.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move /src/apm.js to its own package
5 participants