-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathsentryTanstackStart.ts
More file actions
94 lines (87 loc) · 2.76 KB
/
Copy pathsentryTanstackStart.ts
File metadata and controls
94 lines (87 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import type { BuildTimeOptionsBase } from '@sentry/core';
import type { Plugin } from 'vite';
import { makeAutoInstrumentMiddlewarePlugin } from './autoInstrumentMiddleware';
import { makeAddSentryVitePlugin, makeEnableSourceMapsVitePlugin } from './sourceMaps';
/**
* Build-time options for the Sentry TanStack Start SDK.
*/
export interface SentryTanstackStartOptions extends BuildTimeOptionsBase {
/**
* Configure automatic middleware instrumentation.
*
* - Set to `false` to disable automatic middleware instrumentation entirely.
* - Set to `true` (default) to enable for all middleware files.
* - Set to an object with `exclude` to enable but exclude specific files.
*
* The `exclude` option takes an array of strings or regular expressions matched
* against the full file path. String patterns match as substrings.
*
* @default true
*
* @example
* // Disable completely
* sentryTanstackStart({ autoInstrumentMiddleware: false })
*
* @example
* // Enable with exclusions
* sentryTanstackStart({
* autoInstrumentMiddleware: {
* exclude: ['/routes/admin/', /\.test\.ts$/],
* },
* })
*/
autoInstrumentMiddleware?:
| boolean
| {
exclude?: Array<string | RegExp>;
};
}
/**
* Vite plugins for the Sentry TanStack Start SDK.
*
* @example
* ```typescript
* // vite.config.ts
* import { defineConfig } from 'vite';
* import { sentryTanstackStart } from '@sentry/tanstackstart-react';
* import { tanstackStart } from '@tanstack/react-start/plugin/vite';
*
* export default defineConfig({
* plugins: [
* tanstackStart(),
* sentryTanstackStart({
* org: 'your-org',
* project: 'your-project',
* }),
* ],
* });
* ```
*
* @param options - Options to configure the Sentry Vite plugins
* @returns An array of Vite plugins
*/
export function sentryTanstackStart(options: SentryTanstackStartOptions = {}): Plugin[] {
// only add plugins in production builds
if (process.env.NODE_ENV === 'development') {
return [];
}
const plugins: Plugin[] = [...makeAddSentryVitePlugin(options)];
// middleware auto-instrumentation
const autoInstrumentConfig = options.autoInstrumentMiddleware;
const isDisabled = autoInstrumentConfig === false;
const excludePatterns = typeof autoInstrumentConfig === 'object' ? autoInstrumentConfig.exclude : undefined;
if (!isDisabled) {
plugins.push(
makeAutoInstrumentMiddlewarePlugin({
debug: options.debug,
exclude: excludePatterns,
}),
);
}
// source maps
const sourceMapsDisabled = options.sourcemaps?.disable === true || options.sourcemaps?.disable === 'disable-upload';
if (!sourceMapsDisabled) {
plugins.push(...makeEnableSourceMapsVitePlugin(options));
}
return plugins;
}