diff --git a/src/platform/packages/shared/content-management/content_insights/content_insights_public/src/client.ts b/src/platform/packages/shared/content-management/content_insights/content_insights_public/src/client.ts index a46b01c01ac99..46fe68cece353 100644 --- a/src/platform/packages/shared/content-management/content_insights/content_insights_public/src/client.ts +++ b/src/platform/packages/shared/content-management/content_insights/content_insights_public/src/client.ts @@ -7,6 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ +import type { Logger } from '@kbn/logging'; import type { HttpStart } from '@kbn/core-http-browser'; import type { ContentInsightsStats, @@ -27,17 +28,21 @@ export interface ContentInsightsClientPublic { * Client for the Content Management Insights service. */ export class ContentInsightsClient implements ContentInsightsClientPublic { + private logger: Logger; constructor( - private readonly deps: { http: HttpStart }, + private readonly deps: { http: HttpStart; logger: Logger }, private readonly config: { domainId: string } - ) {} + ) { + this.logger = deps.logger.get('content_insights_client'); + } track(id: string, eventType: ContentInsightsEventTypes) { this.deps.http .post(`/internal/content_management/insights/${this.config.domainId}/${id}/${eventType}`) .catch((e) => { - // eslint-disable-next-line no-console - console.warn(`Could not track ${eventType} event for ${id}`, e); + this.logger.warn(`Could not track ${eventType} event for ${id}. Error: ${e?.message}`, { + error: e, + }); }); } diff --git a/src/platform/packages/shared/content-management/content_insights/content_insights_public/tsconfig.json b/src/platform/packages/shared/content-management/content_insights/content_insights_public/tsconfig.json index f93cc610ca877..b2953a0439776 100644 --- a/src/platform/packages/shared/content-management/content_insights/content_insights_public/tsconfig.json +++ b/src/platform/packages/shared/content-management/content_insights/content_insights_public/tsconfig.json @@ -29,5 +29,6 @@ "@kbn/content-management-content-insights-server", "@kbn/content-management-table-list-view-common", "@kbn/charts-theme", + "@kbn/logging", ] } diff --git a/src/platform/plugins/shared/dashboard/jest_setup.ts b/src/platform/plugins/shared/dashboard/jest_setup.ts index 1b0de7854d3ac..a86dc47ab043d 100644 --- a/src/platform/plugins/shared/dashboard/jest_setup.ts +++ b/src/platform/plugins/shared/dashboard/jest_setup.ts @@ -19,8 +19,10 @@ import { mockDashboardContentManagementCache, mockDashboardContentManagementService, setStubKibanaServices, + setStubLogger, } from './public/services/mocks'; +setStubLogger(); // Start the kibana services with stubs setStubKibanaServices(); diff --git a/src/platform/plugins/shared/dashboard/public/dashboard_api/load_dashboard_api.ts b/src/platform/plugins/shared/dashboard/public/dashboard_api/load_dashboard_api.ts index 0bd2da734ba8d..eb110bfdd56f4 100644 --- a/src/platform/plugins/shared/dashboard/public/dashboard_api/load_dashboard_api.ts +++ b/src/platform/plugins/shared/dashboard/public/dashboard_api/load_dashboard_api.ts @@ -14,6 +14,7 @@ import { DashboardCreationOptions, DashboardState } from './types'; import { getDashboardApi } from './get_dashboard_api'; import { startQueryPerformanceTracking } from '../dashboard_container/embeddable/create/performance/query_performance_tracking'; import { coreServices } from '../services/kibana_services'; +import { logger } from '../services/logger'; import { PANELS_CONTROL_GROUP_KEY, getDashboardBackupService, @@ -123,7 +124,7 @@ export async function loadDashboardApi({ // however, there is an edge case that we now count a new view when a user is editing a dashboard and is returning from an editor by canceling // TODO: this should be revisited by making embeddable transfer support canceling logic https://github.com/elastic/kibana/issues/190485 const contentInsightsClient = new ContentInsightsClient( - { http: coreServices.http }, + { http: coreServices.http, logger }, { domainId: 'dashboard' } ); contentInsightsClient.track(savedObjectId, 'viewed'); diff --git a/src/platform/plugins/shared/dashboard/public/dashboard_listing/hooks/use_dashboard_listing_table.tsx b/src/platform/plugins/shared/dashboard/public/dashboard_listing/hooks/use_dashboard_listing_table.tsx index d7b72263bb93f..3422cd23c67c1 100644 --- a/src/platform/plugins/shared/dashboard/public/dashboard_listing/hooks/use_dashboard_listing_table.tsx +++ b/src/platform/plugins/shared/dashboard/public/dashboard_listing/hooks/use_dashboard_listing_table.tsx @@ -26,6 +26,7 @@ import { getDashboardBackupService } from '../../services/dashboard_backup_servi import { getDashboardContentManagementService } from '../../services/dashboard_content_management_service'; import { getDashboardRecentlyAccessedService } from '../../services/dashboard_recently_accessed_service'; import { coreServices } from '../../services/kibana_services'; +import { logger } from '../../services/logger'; import { getDashboardCapabilities } from '../../utils/get_dashboard_capabilities'; import { dashboardListingErrorStrings, @@ -341,7 +342,7 @@ export const useDashboardListingTable = ({ ); const contentInsightsClient = useMemo( - () => new ContentInsightsClient({ http: coreServices.http }, { domainId: 'dashboard' }), + () => new ContentInsightsClient({ http: coreServices.http, logger }, { domainId: 'dashboard' }), [] ); diff --git a/src/platform/plugins/shared/dashboard/public/plugin.tsx b/src/platform/plugins/shared/dashboard/public/plugin.tsx index 2755c443ca083..caa8eec5d770f 100644 --- a/src/platform/plugins/shared/dashboard/public/plugin.tsx +++ b/src/platform/plugins/shared/dashboard/public/plugin.tsx @@ -79,6 +79,7 @@ import { } from './dashboard_container/panel_placement'; import type { FindDashboardsService } from './services/dashboard_content_management_service/types'; import { setKibanaServices, untilPluginStartServicesReady } from './services/kibana_services'; +import { setLogger } from './services/logger'; import { registerActions } from './dashboard_actions/register_actions'; export interface DashboardFeatureFlagConfig { @@ -156,7 +157,9 @@ export class DashboardPlugin implements Plugin { - constructor(private initializerContext: PluginInitializerContext) {} + constructor(private initializerContext: PluginInitializerContext) { + setLogger(initializerContext.logger.get('dashboard')); + } private appStateUpdater = new BehaviorSubject(() => ({})); private stopUrlTracking: (() => void) | undefined = undefined; diff --git a/src/platform/plugins/shared/dashboard/public/services/logger.ts b/src/platform/plugins/shared/dashboard/public/services/logger.ts new file mode 100644 index 0000000000000..46bdfcab5000f --- /dev/null +++ b/src/platform/plugins/shared/dashboard/public/services/logger.ts @@ -0,0 +1,16 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the "Elastic License + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +import type { Logger } from '@kbn/logging'; + +export let logger: Logger; + +export const setLogger = (_logger: Logger) => { + logger = _logger; +}; diff --git a/src/platform/plugins/shared/dashboard/public/services/mocks.ts b/src/platform/plugins/shared/dashboard/public/services/mocks.ts index c39c665ed55da..57ed1a4d0ce61 100644 --- a/src/platform/plugins/shared/dashboard/public/services/mocks.ts +++ b/src/platform/plugins/shared/dashboard/public/services/mocks.ts @@ -32,6 +32,7 @@ import { urlForwardingPluginMock } from '@kbn/url-forwarding-plugin/public/mocks import { visualizationsPluginMock } from '@kbn/visualizations-plugin/public/mocks'; import { setKibanaServices } from './kibana_services'; +import { setLogger } from './logger'; import { DashboardAttributes } from '../../server/content_management'; import { DashboardCapabilities } from '../../common'; import { LoadDashboardReturn } from './dashboard_content_management_service/types'; @@ -76,6 +77,10 @@ export const setStubKibanaServices = () => { }); }; +export const setStubLogger = () => { + setLogger(coreMock.createCoreContext().logger); +}; + export const mockDashboardContentManagementService = { loadDashboardState: jest.fn().mockImplementation(() => Promise.resolve({