-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Move src/apm.js to @kbn/apm-config-loader #94315
Conversation
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') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super-NIT:
if (payload.context && payload.context.user && typeof payload.context.user === 'object') { | |
if (payload.context?.user && typeof payload.context.user === 'object') { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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, '../..'); |
There was a problem hiding this comment.
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';
💚 Build SucceededMetrics [docs]
History
To update your PR or re-run it, just comment with: |
* Move src/apm.js to @kbn/apm-config-loader * add unit tests for `initApm` * return undefined instead of empty config * use ?.
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