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

⚗️ enable plugins as a beta feature #2872

Merged
merged 3 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/core/src/tools/experimentalFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export enum ExperimentalFeature {
TOLERANT_RESOURCE_TIMINGS = 'tolerant_resource_timings',
REMOTE_CONFIGURATION = 'remote_configuration',
UPDATE_VIEW_NAME = 'update_view_name',
PLUGINS = 'plugins',
}

const enabledExperimentalFeatures: Set<ExperimentalFeature> = new Set()
Expand Down
8 changes: 2 additions & 6 deletions packages/rum-core/src/boot/preStartRum.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,14 +477,10 @@ describe('preStartRum', () => {
})

describe('plugins', () => {
beforeEach(() => {
mockExperimentalFeatures([ExperimentalFeature.PLUGINS])
})

it('calls the onInit method on provided plugins', () => {
const plugin = { name: 'a', onInit: jasmine.createSpy() }
const strategy = createPreStartStrategy({}, getCommonContextSpy, createTrackingConsentState(), doStartRumSpy)
const initConfiguration = { ...DEFAULT_INIT_CONFIGURATION, plugins: [plugin] }
const initConfiguration: RumInitConfiguration = { ...DEFAULT_INIT_CONFIGURATION, betaPlugins: [plugin] }
strategy.init(initConfiguration, PUBLIC_API)

expect(plugin.onInit).toHaveBeenCalledWith({
Expand All @@ -504,7 +500,7 @@ describe('preStartRum', () => {
const strategy = createPreStartStrategy({}, getCommonContextSpy, createTrackingConsentState(), doStartRumSpy)
strategy.init(
{
plugins: [plugin],
betaPlugins: [plugin],
} as RumInitConfiguration,
PUBLIC_API
)
Expand Down
4 changes: 1 addition & 3 deletions packages/rum-core/src/boot/preStartRum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ export function createPreStartStrategy(
return
}

if (isExperimentalFeatureEnabled(ExperimentalFeature.PLUGINS)) {
callPluginsMethod(initConfiguration.plugins, 'onInit', { initConfiguration, publicApi })
}
callPluginsMethod(initConfiguration.betaPlugins, 'onInit', { initConfiguration, publicApi })

if (
initConfiguration.remoteConfigurationId &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import type { InitConfiguration } from '@datadog/browser-core'
import { DefaultPrivacyLevel, display, ExperimentalFeature, TraceContextInjection } from '@datadog/browser-core'
import {
EXHAUSTIVE_INIT_CONFIGURATION,
mockExperimentalFeatures,
SERIALIZED_EXHAUSTIVE_INIT_CONFIGURATION,
} from '@datadog/browser-core/test'
import { DefaultPrivacyLevel, display, TraceContextInjection } from '@datadog/browser-core'
import { EXHAUSTIVE_INIT_CONFIGURATION, SERIALIZED_EXHAUSTIVE_INIT_CONFIGURATION } from '@datadog/browser-core/test'
import type {
ExtractTelemetryConfiguration,
CamelToSnakeCase,
Expand Down Expand Up @@ -446,29 +442,16 @@ describe('validateAndBuildRumConfiguration', () => {
})

describe('plugins', () => {
it('with `plugins` enabled: should be set in the configuration', () => {
mockExperimentalFeatures([ExperimentalFeature.PLUGINS])

it('should be set in the configuration', () => {
const plugin = {
name: 'foo',
}
const configuration = validateAndBuildRumConfiguration({
...DEFAULT_INIT_CONFIGURATION,
plugins: [plugin],
betaPlugins: [plugin],
})
expect(configuration!.plugins).toEqual([plugin])
})

it('without `plugins` enabled: should not be set in the configuration', () => {
const plugin = {
name: 'foo',
}
const configuration = validateAndBuildRumConfiguration({
...DEFAULT_INIT_CONFIGURATION,
plugins: [plugin],
})
expect(configuration!.plugins).toEqual([])
})
})
})

Expand All @@ -495,7 +478,7 @@ describe('serializeRumConfiguration', () => {
trackResources: true,
trackLongTasks: true,
remoteConfigurationId: '123',
plugins: [{ name: 'foo', getConfigurationTelemetry: () => ({ bar: true }) }],
betaPlugins: [{ name: 'foo', getConfigurationTelemetry: () => ({ bar: true }) }],
}

type MapRumInitConfigurationKey<Key extends string> = Key extends keyof InitConfiguration
Expand All @@ -506,7 +489,9 @@ describe('serializeRumConfiguration', () => {
? 'track_long_task' // oops
: Key extends 'applicationId' | 'subdomain' | 'remoteConfigurationId'
? never
: CamelToSnakeCase<Key>
: Key extends 'betaPlugins' // renamed during public beta
? 'plugins'
: CamelToSnakeCase<Key>

// By specifying the type here, we can ensure that serializeConfiguration is returning an
// object containing all expected properties.
Expand Down
8 changes: 3 additions & 5 deletions packages/rum-core/src/domain/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import {
isPercentage,
objectHasValue,
validateAndBuildConfiguration,
isExperimentalFeatureEnabled,
ExperimentalFeature,
} from '@datadog/browser-core'
import type { RumEventDomainContext } from '../../domainContext.types'
import type { RumEvent } from '../../rumEvent.types'
Expand Down Expand Up @@ -131,7 +129,7 @@ export interface RumInitConfiguration extends InitConfiguration {
* notice. Please use only plugins provided by Datadog matching the version of the SDK you are
* using.
*/
plugins?: RumPlugin[] | undefined
betaPlugins?: RumPlugin[] | undefined
}

export type HybridInitConfiguration = Omit<RumInitConfiguration, 'applicationId' | 'clientToken'>
Expand Down Expand Up @@ -221,7 +219,7 @@ export function validateAndBuildRumConfiguration(
traceContextInjection: objectHasValue(TraceContextInjection, initConfiguration.traceContextInjection)
? initConfiguration.traceContextInjection
: TraceContextInjection.ALL,
plugins: (isExperimentalFeatureEnabled(ExperimentalFeature.PLUGINS) && initConfiguration.plugins) || [],
plugins: initConfiguration.betaPlugins || [],
},
baseConfiguration
)
Expand Down Expand Up @@ -304,7 +302,7 @@ export function serializeRumConfiguration(configuration: RumInitConfiguration) {
track_user_interactions: configuration.trackUserInteractions,
track_resources: configuration.trackResources,
track_long_task: configuration.trackLongTasks,
plugins: configuration.plugins?.map((plugin) =>
plugins: configuration.betaPlugins?.map((plugin) =>
assign({ name: plugin.name }, plugin.getConfigurationTelemetry?.())
),
},
Expand Down
3 changes: 1 addition & 2 deletions sandbox/react-app/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import { reactPlugin, ErrorBoundary } from '@datadog/browser-rum-react'
datadogRum.init({
applicationId: 'xxx',
clientToken: 'xxx',
enableExperimentalFeatures: ['plugins'],
plugins: [reactPlugin({ router: true })],
betaPlugins: [reactPlugin({ router: true })],
})

const router = createBrowserRouter(
Expand Down