docs.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import {AvatarProject} from 'sentry/types';
  2. const platforms = [
  3. 'dotnet',
  4. 'android',
  5. 'apple',
  6. 'dart',
  7. 'elixir',
  8. 'flutter',
  9. 'go',
  10. 'java',
  11. 'javascript',
  12. 'native',
  13. 'node',
  14. 'perl',
  15. 'php',
  16. 'python',
  17. 'react-native',
  18. 'ruby',
  19. 'rust',
  20. 'unity',
  21. ] as const;
  22. export type DocPlatform = typeof platforms[number];
  23. const performancePlatforms: DocPlatform[] = [
  24. 'dotnet',
  25. 'android',
  26. 'apple',
  27. 'go',
  28. 'java',
  29. 'javascript',
  30. 'node',
  31. 'php',
  32. 'python',
  33. 'react-native',
  34. 'ruby',
  35. ];
  36. function validDocPlatform(platform: any): platform is DocPlatform {
  37. return platforms.includes(platform);
  38. }
  39. export function getDocsPlatform(
  40. platform: string,
  41. performanceOnly: boolean
  42. ): DocPlatform | null {
  43. // react-native is the only platform that has a dash, and supports performance so we can skip that check
  44. if (platform === 'react-native') {
  45. return 'react-native';
  46. }
  47. const index = platform.indexOf('-');
  48. const prefix = index >= 0 ? platform.substring(0, index) : platform;
  49. if (validDocPlatform(prefix)) {
  50. const validPerformancePrefix = performancePlatforms.includes(prefix);
  51. if ((performanceOnly && validPerformancePrefix) || !performanceOnly) {
  52. return prefix;
  53. }
  54. }
  55. // can't find a matching docs platform
  56. return null;
  57. }
  58. export function getConfigureTracingDocsLink(
  59. project: AvatarProject | undefined
  60. ): string | null {
  61. const platform = project?.platform ?? null;
  62. const docsPlatform = platform ? getDocsPlatform(platform, true) : null;
  63. return docsPlatform === null
  64. ? null // this platform does not support performance
  65. : `https://docs.sentry.io/platforms/${docsPlatform}/performance/`;
  66. }