Skip to content

Commit 5cf6504

Browse files
authored
[8.19] chore(fullstory): serve the snippet as an asset (#220368) (#220482)
# Backport This will backport the following commits from `main` to `8.19`: - [chore(fullstory): serve the snippet as an asset (#220368)](#220368) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Alejandro Fernández Haro","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-05-07T21:06:24Z","message":"chore(fullstory): serve the snippet as an asset (#220368)","sha":"10d46e5f5e8d331fb61e83eb52494e47d28ca5b6","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Core","Team:Operations","release_note:skip","backport:version","v9.1.0","v8.19.0"],"title":"chore(fullstory): serve the snippet as an asset","number":220368,"url":"https://github.com/elastic/kibana/pull/220368","mergeCommit":{"message":"chore(fullstory): serve the snippet as an asset (#220368)","sha":"10d46e5f5e8d331fb61e83eb52494e47d28ca5b6"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/220368","number":220368,"mergeCommit":{"message":"chore(fullstory): serve the snippet as an asset (#220368)","sha":"10d46e5f5e8d331fb61e83eb52494e47d28ca5b6"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT-->
1 parent ef4fe75 commit 5cf6504

File tree

11 files changed

+24
-231
lines changed

11 files changed

+24
-231
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ snapshots.js
2626
/x-pack/platform/plugins/private/canvas/storybook/build
2727
/x-pack/platform/plugins/private/reporting/server/export_types/printable_pdf/server/lib/pdf/assets/**
2828
/x-pack/platform/plugins/private/reporting/server/export_types/printable_pdf_v2/server/lib/pdf/assets/**
29-
/x-pack/platform/plugins/private/cloud_integrations/cloud_full_story/server/assets/**
29+
/x-pack/platform/plugins/private/cloud_integrations/cloud_full_story/public/assets/**
3030

3131
# package overrides
3232
/packages/kbn-eslint-config

x-pack/platform/plugins/private/cloud_integrations/cloud_full_story/public/plugin.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ describe('Cloud Plugin', () => {
3131
const plugin = new CloudFullStoryPlugin(initContext);
3232

3333
const coreSetup = coreMock.createSetup();
34+
jest
35+
.spyOn(coreSetup.http.staticAssets, 'getPluginAssetHref')
36+
.mockReturnValue('/cloudFullStory/assets/fs.js');
3437

3538
const cloud = { ...cloudMock.createSetup(), isCloudEnabled, isElasticStaffOwned };
3639

@@ -50,7 +53,7 @@ describe('Cloud Plugin', () => {
5053
expect(coreSetup.analytics.registerShipper).toHaveBeenCalled();
5154
expect(coreSetup.analytics.registerShipper).toHaveBeenCalledWith(expect.anything(), {
5255
fullStoryOrgId: 'foo',
53-
scriptUrl: '/internal/cloud/100/fullstory.js',
56+
scriptUrl: '/cloudFullStory/assets/fs.js',
5457
namespace: 'FSKibana',
5558
captureOnStartup: false,
5659
});
@@ -65,7 +68,7 @@ describe('Cloud Plugin', () => {
6568
expect(coreSetup.analytics.registerShipper).toHaveBeenCalledWith(expect.anything(), {
6669
fullStoryOrgId: 'foo',
6770
pageVarsDebounceTimeMs: 500,
68-
scriptUrl: '/internal/cloud/100/fullstory.js',
71+
scriptUrl: '/cloudFullStory/assets/fs.js',
6972
namespace: 'FSKibana',
7073
captureOnStartup: false,
7174
});

x-pack/platform/plugins/private/cloud_integrations/cloud_full_story/public/plugin.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import type {
99
AnalyticsServiceSetup,
10-
IBasePath,
10+
IStaticAssets,
1111
PluginInitializerContext,
1212
CoreSetup,
1313
Plugin,
@@ -17,7 +17,7 @@ import { duration } from 'moment';
1717

1818
interface SetupFullStoryDeps {
1919
analytics: AnalyticsServiceSetup;
20-
basePath: IBasePath;
20+
staticAssets: IStaticAssets;
2121
}
2222

2323
export interface CloudFullStoryConfig {
@@ -45,10 +45,14 @@ export class CloudFullStoryPlugin implements Plugin {
4545
.info('Skipping FullStory setup for a Elastic-owned deployments');
4646
return;
4747
}
48-
this.setupFullStory({ analytics: core.analytics, basePath: core.http.basePath }).catch((e) =>
49-
// eslint-disable-next-line no-console
50-
console.debug(`Error setting up FullStory: ${e.toString()}`)
51-
);
48+
this.setupFullStory({
49+
analytics: core.analytics,
50+
staticAssets: core.http.staticAssets,
51+
}).catch((e) => {
52+
this.initializerContext.logger
53+
.get()
54+
.debug(`Error setting up FullStory: ${e.toString()}`, { error: e });
55+
});
5256
}
5357
}
5458

@@ -59,10 +63,10 @@ export class CloudFullStoryPlugin implements Plugin {
5963
/**
6064
* If the right config is provided, register the FullStory shipper to the analytics client.
6165
* @param analytics Core's Analytics service's setup contract.
62-
* @param basePath Core's http.basePath helper.
66+
* @param staticAssets Core's http.staticAssets helper.
6367
* @private
6468
*/
65-
private async setupFullStory({ analytics, basePath }: SetupFullStoryDeps) {
69+
private async setupFullStory({ analytics, staticAssets }: SetupFullStoryDeps) {
6670
const { org_id: fullStoryOrgId, eventTypesAllowlist, pageVarsDebounceTime } = this.config;
6771
if (!fullStoryOrgId) {
6872
return; // do not load any FullStory code in the browser if not enabled
@@ -77,15 +81,9 @@ export class CloudFullStoryPlugin implements Plugin {
7781
...(pageVarsDebounceTime
7882
? { pageVarsDebounceTimeMs: duration(pageVarsDebounceTime).asMilliseconds() }
7983
: {}),
80-
/**
81-
* FIXME: this should use the {@link IStaticAssets['getPluginAssetHref']}
82-
* function. Then we can avoid registering our own endpoint in this plugin.
83-
*/
84-
scriptUrl: basePath.prepend(
85-
`/internal/cloud/${this.initializerContext.env.packageInfo.buildNum}/fullstory.js`
86-
),
84+
scriptUrl: staticAssets.getPluginAssetHref('fs.js'),
8785
namespace: 'FSKibana',
88-
// Tell FullStory to not capture from the start, and wait for the opt-in confirmation
86+
// Tell FullStory to not capture from the start and wait for the opt-in confirmation
8987
captureOnStartup: false,
9088
});
9189
}

x-pack/platform/plugins/private/cloud_integrations/cloud_full_story/server/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
* 2.0.
66
*/
77

8-
import { PluginInitializerContext } from '@kbn/core/server';
9-
108
export { config } from './config';
119

12-
export async function plugin(initializerContext: PluginInitializerContext) {
10+
export async function plugin() {
1311
const { CloudFullStoryPlugin } = await import('./plugin');
14-
return new CloudFullStoryPlugin(initializerContext);
12+
return new CloudFullStoryPlugin();
1513
}

x-pack/platform/plugins/private/cloud_integrations/cloud_full_story/server/plugin.test.mock.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

x-pack/platform/plugins/private/cloud_integrations/cloud_full_story/server/plugin.test.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

x-pack/platform/plugins/private/cloud_integrations/cloud_full_story/server/plugin.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,10 @@
55
* 2.0.
66
*/
77

8-
import type { PluginInitializerContext, CoreSetup, Plugin } from '@kbn/core/server';
9-
import type { CloudSetup } from '@kbn/cloud-plugin/server';
10-
11-
import { registerFullStoryRoute } from './routes';
12-
13-
interface CloudFullStorySetupDeps {
14-
cloud: CloudSetup;
15-
}
8+
import type { Plugin } from '@kbn/core/server';
169

1710
export class CloudFullStoryPlugin implements Plugin {
18-
constructor(private readonly initializerContext: PluginInitializerContext) {}
19-
20-
public setup(core: CoreSetup, { cloud }: CloudFullStorySetupDeps) {
21-
if (cloud.isCloudEnabled) {
22-
registerFullStoryRoute({
23-
httpResources: core.http.resources,
24-
packageInfo: this.initializerContext.env.packageInfo,
25-
});
26-
}
27-
}
11+
public setup() {}
2812

2913
public start() {}
3014

x-pack/platform/plugins/private/cloud_integrations/cloud_full_story/server/routes/fullstory.test.ts

Lines changed: 0 additions & 62 deletions
This file was deleted.

x-pack/platform/plugins/private/cloud_integrations/cloud_full_story/server/routes/fullstory.ts

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)