Skip to content

Commit 2aae126

Browse files
committed
createBrowserRouter auto instrumentation
1 parent 1a4f72d commit 2aae126

File tree

13 files changed

+30
-58
lines changed

13 files changed

+30
-58
lines changed

packages/core/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export enum InjectPosition {
8585
export type ToInjectItem = {
8686
type: 'file' | 'code';
8787
value: InjectedValue;
88-
position: InjectPosition;
88+
position?: InjectPosition;
8989
fallback?: ToInjectItem;
9090
};
9191

@@ -149,7 +149,7 @@ export interface Options extends BaseOptions {
149149
customPlugins?: GetCustomPlugins;
150150
}
151151

152-
export type GetPluginsOptions = Required<BaseOptions>;
152+
export type GetPluginsOptions = BaseOptions;
153153
export type OptionsWithDefaults = Assign<Options, GetPluginsOptions>;
154154

155155
export type PluginName = `datadog-${Lowercase<string>}-plugin`;

packages/plugins/injection/src/helpers.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
// Copyright 2019-Present Datadog, Inc.
44

55
import { doRequest, truncateString } from '@dd/core/helpers';
6-
import type { InjectPosition, Logger, ToInjectItem } from '@dd/core/types';
6+
import type { Logger, ToInjectItem } from '@dd/core/types';
7+
import { InjectPosition } from '@dd/core/types';
78
import { getAbsolutePath } from '@dd/internal-build-report-plugin/helpers';
89
import { readFile } from 'fs/promises';
910

@@ -86,7 +87,7 @@ export const processInjections = async (
8687
// eslint-disable-next-line no-await-in-loop
8788
const value = await processItem(item, log);
8889
if (value) {
89-
toReturn.set(id, { value, position: item.position });
90+
toReturn.set(id, { value, position: item.position ?? InjectPosition.AFTER });
9091
}
9192
}
9293

packages/plugins/rum/src/index.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ export const getPlugins: GetPlugins<OptionsWithRum> = (
4646
position: InjectPosition.MIDDLE,
4747
value: path.join(__dirname, './rum-react-plugin.js'),
4848
});
49-
context.inject({
50-
type: 'file',
51-
position: InjectPosition.MIDDLE,
52-
value: path.join(__dirname, './rum-react-router-6.js'),
53-
});
5449
}
5550

5651
context.inject({
@@ -90,7 +85,11 @@ export const getPlugins: GetPlugins<OptionsWithRum> = (
9085
return updatedCode;
9186
},
9287
transformInclude(id) {
93-
return id.match(new RegExp(/.*\.(js|jsx|ts|tsx)$/)) !== null;
88+
return (
89+
// @ts-ignore
90+
options?.react?.router === true &&
91+
id.match(new RegExp(/.*\.(js|jsx|ts|tsx)$/)) !== null
92+
);
9493
},
9594
},
9695
];

packages/plugins/rum/src/sdk.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,16 @@ type RumAppResponse = {
1616
};
1717

1818
const getContent = (opts: RumOptionsWithDefaults) => {
19-
const pluginContent = opts.react ? ', plugins: [reactPlugin({ router: true})]' : '';
20-
return `DD_RUM.init({${JSON.stringify(opts.sdk).replace(/(^{|}$)/g, '')}${pluginContent}});
21-
`;
19+
const pluginContent = opts.react
20+
? // @ts-ignore
21+
`, plugins: [reactPlugin({router: ${opts.react.router}})]`
22+
: '';
23+
const sessionReplayStartCommand = opts.startSessionReplayRecording
24+
? 'DD_RUM.startSessionReplayRecording();\n'
25+
: '';
26+
27+
return `DD_RUM.init({${JSON.stringify(opts.sdk).replace(/(^{|}$)/g, '')}${pluginContent}});${sessionReplayStartCommand}
28+
`;
2229
};
2330

2431
export const getInjectionValue = (

packages/plugins/rum/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export type RumOptions = {
1010
disabled?: boolean;
1111
sdk?: SDKOptions;
1212
react?: ReactOptions;
13+
startSessionReplayRecording?: boolean;
1314
};
1415

1516
export type SDKOptions = {
@@ -68,6 +69,7 @@ export type RumOptionsWithDefaults = {
6869
disabled?: boolean;
6970
sdk?: SDKOptionsWithDefaults;
7071
react?: ReactOptionsWithDefaults;
72+
startSessionReplayRecording?: boolean;
7173
};
7274

7375
export type RumOptionsWithSdk = {

packages/published/esbuild-plugin/package.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@
2121
"main": "./dist/src/index.js",
2222
"module": "./dist/src/index.mjs",
2323
"exports": {
24-
"./package.json": "./package.json",
25-
".": {
26-
"import": "./dist/src/index.mjs",
27-
"require": "./dist/src/index.js",
28-
"types": "./dist/src/index.d.ts"
29-
}
24+
".": "./src/index.ts"
3025
},
3126
"publishConfig": {
3227
"access": "public",

packages/published/rollup-plugin/package.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@
2121
"main": "./dist/src/index.js",
2222
"module": "./dist/src/index.mjs",
2323
"exports": {
24-
"./package.json": "./package.json",
25-
".": {
26-
"import": "./dist/src/index.mjs",
27-
"require": "./dist/src/index.js",
28-
"types": "./dist/src/index.d.ts"
29-
}
24+
".": "./src/index.ts"
3025
},
3126
"publishConfig": {
3227
"access": "public",

packages/published/rspack-plugin/package.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@
2121
"main": "./dist/src/index.js",
2222
"module": "./dist/src/index.mjs",
2323
"exports": {
24-
"./package.json": "./package.json",
25-
".": {
26-
"import": "./dist/src/index.mjs",
27-
"require": "./dist/src/index.js",
28-
"types": "./dist/src/index.d.ts"
29-
}
24+
".": "./src/index.ts"
3025
},
3126
"publishConfig": {
3227
"access": "public",

packages/published/vite-plugin/package.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@
2121
"main": "./dist/src/index.js",
2222
"module": "./dist/src/index.mjs",
2323
"exports": {
24-
"./package.json": "./package.json",
25-
".": {
26-
"import": "./dist/src/index.mjs",
27-
"require": "./dist/src/index.js",
28-
"types": "./dist/src/index.d.ts"
29-
}
24+
".": "./src/index.ts"
3025
},
3126
"publishConfig": {
3227
"access": "public",

packages/published/webpack-plugin/package.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@
2121
"main": "./dist/src/index.js",
2222
"module": "./dist/src/index.mjs",
2323
"exports": {
24-
"./package.json": "./package.json",
25-
".": {
26-
"import": "./dist/src/index.mjs",
27-
"require": "./dist/src/index.js",
28-
"types": "./dist/src/index.d.ts"
29-
}
24+
".": "./src/index.ts"
3025
},
3126
"publishConfig": {
3227
"access": "public",

0 commit comments

Comments
 (0)