platforms.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import {Project} from 'sentry/types/project';
  2. const supportedProfilingPlatformSDKs = [
  3. 'android',
  4. 'apple-ios',
  5. 'flutter',
  6. 'dart-flutter',
  7. 'go',
  8. 'node',
  9. 'python',
  10. 'php',
  11. 'php',
  12. 'php-laravel',
  13. 'php-symfony2',
  14. 'ruby',
  15. 'javascript-nextjs',
  16. 'javascript-remix',
  17. 'javascript-sveltekit',
  18. 'javascript',
  19. 'javascript-react',
  20. 'react-native',
  21. ] as const;
  22. export type SupportedProfilingPlatform = (typeof supportedProfilingPlatformSDKs)[number];
  23. export type SupportedProfilingPlatformSDK =
  24. (typeof supportedProfilingPlatformSDKs)[number];
  25. export function getDocsPlatformSDKForPlatform(
  26. platform: string | undefined
  27. ): SupportedProfilingPlatform | null {
  28. if (!platform) {
  29. return null;
  30. }
  31. // Android
  32. if (platform === 'android') {
  33. return 'android';
  34. }
  35. // iOS
  36. if (platform === 'apple-ios') {
  37. return 'apple-ios';
  38. }
  39. // Go
  40. if (platform === 'go') {
  41. return 'go';
  42. }
  43. // Javascript
  44. if (platform.startsWith('node')) {
  45. return 'node';
  46. }
  47. if (platform === 'javascript-nextjs') {
  48. return 'javascript-nextjs';
  49. }
  50. if (platform === 'javascript-remix') {
  51. return 'javascript-remix';
  52. }
  53. if (platform === 'javascript-sveltekit') {
  54. return 'javascript-sveltekit';
  55. }
  56. if (platform === 'javascript') {
  57. return 'javascript';
  58. }
  59. if (platform === 'javascript-react') {
  60. return 'javascript-react';
  61. }
  62. if (platform === 'dart-flutter') {
  63. return 'dart-flutter';
  64. }
  65. if (platform === 'flutter') {
  66. return 'flutter';
  67. }
  68. // Python
  69. if (platform.startsWith('python')) {
  70. return 'python';
  71. }
  72. // PHP
  73. if (platform === 'php-laravel') {
  74. return 'php-laravel';
  75. }
  76. if (platform === 'php-symfony') {
  77. // TODD(aknaus): simplify once we migrate the docs to the sentry repo
  78. // php-symfony2 is the name for php-symfony in the docs
  79. return 'php-symfony2';
  80. }
  81. if (platform.startsWith('php')) {
  82. return 'php';
  83. }
  84. // Ruby
  85. if (platform.startsWith('ruby')) {
  86. return 'ruby';
  87. }
  88. // React native
  89. if (platform === 'react-native') {
  90. return 'react-native';
  91. }
  92. return null;
  93. }
  94. export function isProfilingSupportedOrProjectHasProfiles(project: Project): boolean {
  95. return !!(
  96. (project.platform && getDocsPlatformSDKForPlatform(project.platform)) ||
  97. // If this project somehow managed to send profiles, then profiling is supported for this project.
  98. // Sometimes and for whatever reason, platform can also not be set on a project so the above check alone would fail
  99. project.hasProfiles
  100. );
  101. }
  102. export function getProfilingDocsForPlatform(platform: string | undefined): string | null {
  103. const docsPlatform = getDocsPlatformSDKForPlatform(platform);
  104. if (!docsPlatform) {
  105. return null;
  106. }
  107. return docsPlatform === 'apple-ios'
  108. ? 'https://docs.sentry.io/platforms/apple/guides/ios/profiling/'
  109. : `https://docs.sentry.io/platforms/${docsPlatform}/profiling/`;
  110. }