-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Instrument Kibana with APM RUM agent #44281
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
Changes from all commits
588fa90
e7fa67c
0a1f473
f13e53b
2f6cda7
7bddbef
793882b
cb4b3fa
2a15ae9
41cb72a
1b27050
a7ff3b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,6 +80,9 @@ export interface InjectedMetadataParams { | |
| user?: Record<string, UserProvidedValues>; | ||
| }; | ||
| }; | ||
| apm: { | ||
| [key: string]: unknown; | ||
| }; | ||
|
Comment on lines
+83
to
+85
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quick note on this: injectedMetadata are more or less already deprecated and might be removed at some point in NP. You have to keep in mind that you need to migrate this to an asynchronous way to access and use this data at some point. |
||
| }; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| import { getConfig, isKibanaDistributable } from '../../../apm'; | ||
| import agent from 'elastic-apm-node'; | ||
|
|
||
| const apmEnabled = !isKibanaDistributable && process.env.ELASTIC_APM_ACTIVE === 'true'; | ||
|
|
||
| export function apmImport() { | ||
| return apmEnabled ? 'import { init } from "@elastic/apm-rum"' : ''; | ||
| } | ||
|
|
||
| export function apmInit(config) { | ||
| return apmEnabled ? `init(${config})` : ''; | ||
| } | ||
|
|
||
| export function getApmConfig(appMetadata) { | ||
| if (!apmEnabled) { | ||
| return {}; | ||
| } | ||
| /** | ||
| * we use the injected app metadata from the server to extract the | ||
| * app URL path to be used for page-load transaction | ||
| */ | ||
| const navLink = appMetadata.getNavLink(); | ||
| const pageUrl = navLink ? navLink.toJSON().url : appMetadata._url; | ||
|
|
||
| const config = { | ||
| ...getConfig('kibana-frontend'), | ||
| ...{ | ||
| active: true, | ||
| pageLoadTransactionName: pageUrl, | ||
| }, | ||
| }; | ||
| /** | ||
| * Get current active backend transaction to make distrubuted tracing | ||
| * work for rendering the app | ||
| */ | ||
| const backendTransaction = agent.currentTransaction; | ||
|
|
||
| if (backendTransaction) { | ||
| const { sampled, traceId } = backendTransaction; | ||
| return { | ||
| ...config, | ||
| ...{ | ||
| pageLoadTraceId: traceId, | ||
| pageLoadSampled: sampled, | ||
| pageLoadSpanId: backendTransaction.ensureParentId(), | ||
| }, | ||
| }; | ||
| } | ||
| return config; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,7 +56,23 @@ export default function RouteManager() { | |
| } | ||
| }; | ||
|
|
||
| self.run = function($location, $route, $injector) { | ||
| self.run = function($location, $route, $injector, $rootScope) { | ||
| if (window.elasticApm && typeof window.elasticApm.startTransaction === 'function') { | ||
| /** | ||
| * capture route-change events as transactions which happens after | ||
| * the browser's on load event. | ||
| * | ||
| * In Kibana app, this logic would run after the boostrap js files gets | ||
| * downloaded and get associated with the page-load transaction | ||
| */ | ||
| $rootScope.$on('$routeChangeStart', (_, nextRoute) => { | ||
|
||
| if (nextRoute.$$route) { | ||
| const name = nextRoute.$$route.originalPath; | ||
| window.elasticApm.startTransaction(name, 'route-change'); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| self.getBreadcrumbs = () => { | ||
| const breadcrumbs = parsePathToBreadcrumbs($location.path()); | ||
| const map = $route.current.mapBreadcrumbs; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ import { AppBootstrap } from './bootstrap'; | |
| import { mergeVariables } from './lib'; | ||
| // eslint-disable-next-line @kbn/eslint/no-restricted-paths | ||
| import { fromRoot } from '../../../core/server/utils'; | ||
| import { getApmConfig } from '../apm'; | ||
|
|
||
| export function uiRenderMixin(kbnServer, server, config) { | ||
| function replaceInjectedVars(request, injectedVars) { | ||
|
|
@@ -282,6 +283,8 @@ export function uiRenderMixin(kbnServer, server, config) { | |
| uiPlugins, | ||
|
|
||
| legacyMetadata, | ||
|
|
||
| apm: getApmConfig(legacyMetadata.app), | ||
|
Comment on lines
+286
to
+287
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ping @eliperelman Will need to reintegrate this in renderer PR |
||
| }, | ||
| }); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| declare module '@elastic/apm-rum-react'; |
Uh oh!
There was an error while loading. Please reload this page.