123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- import {ProductSolution} from 'sentry/components/onboarding/productSelection';
- type ProductSelectionMap = Record<ProductSolution, boolean>;
- /**
- * Transforms the product selection array into a map of booleans for each product for easier access.
- */
- export const getProductSelectionMap = (
- activeProductSelection: ProductSolution[]
- ): ProductSelectionMap => {
- const productSelectionMap: ProductSelectionMap = {
- [ProductSolution.ERROR_MONITORING]: false,
- [ProductSolution.PROFILING]: false,
- [ProductSolution.PERFORMANCE_MONITORING]: false,
- [ProductSolution.SESSION_REPLAY]: false,
- };
- activeProductSelection.forEach(product => {
- productSelectionMap[product] = true;
- });
- return productSelectionMap;
- };
- /**
- * Joins the given lines with the given indentation using \n as delimiter.
- */
- export function joinWithIndentation(lines: string[], indent = 2) {
- const indentation = ' '.repeat(indent);
- return lines.map(line => `${indentation}${line}`).join('\n');
- }
- export function getInstallSnippet({
- productSelection,
- additionalPackages = [],
- basePackage = '@sentry/node',
- }: {
- productSelection: ProductSelectionMap;
- additionalPackages?: string[];
- basePackage?: string;
- }) {
- let packages = [basePackage];
- if (productSelection.profiling) {
- packages.push('@sentry/profiling-node');
- }
- packages = packages.concat(additionalPackages);
- return `# Using yarn
- yarn add ${packages.join(' ')}
- # Using npm
- npm install --save ${packages.join(' ')}`;
- }
- export function getDefaultNodeImports({
- productSelection,
- }: {
- productSelection: ProductSelectionMap;
- }) {
- const imports: string[] = [
- `// You can also use CommonJS \`require('@sentry/node')\` instead of \`import\``,
- `import * as Sentry from "@sentry/node";`,
- ];
- if (productSelection.profiling) {
- imports.push(`import { ProfilingIntegration } from "@sentry/profiling-node";`);
- }
- return imports;
- }
- export function getDefaulServerlessImports({
- productSelection,
- }: {
- productSelection: ProductSelectionMap;
- }) {
- const imports: string[] = [
- `// You can also use ESM \`import * as Sentry from "@sentry/serverless"\` instead of \`require\``,
- `const Sentry = require("@sentry/serverless");`,
- ];
- if (productSelection.profiling) {
- imports.push(`const { ProfilingIntegration } = require("@sentry/profiling");`);
- }
- return imports;
- }
- export function getProductIntegrations({
- productSelection,
- }: {
- productSelection: ProductSelectionMap;
- }) {
- const integrations: string[] = [];
- if (productSelection.profiling) {
- integrations.push(`new ProfilingIntegration(),`);
- }
- return integrations;
- }
- export function getDefaultInitParams({dsn}: {dsn: string}) {
- return [`dsn: '${dsn}',`];
- }
- export function getProductInitParams({
- productSelection,
- }: {
- productSelection: ProductSelectionMap;
- }) {
- const params: string[] = [];
- if (productSelection['performance-monitoring']) {
- params.push(`// Performance Monitoring`);
- params.push(
- `tracesSampleRate: 1.0, // Capture 100% of the transactions, reduce in production!`
- );
- }
- if (productSelection.profiling) {
- params.push(
- `// Set sampling rate for profiling - this is relative to tracesSampleRate`
- );
- params.push(
- `profilesSampleRate: 1.0, // Capture 100% of the transactions, reduce in production!`
- );
- }
- return params;
- }
|