utils.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import type {Location, LocationDescriptor} from 'history';
  2. import {ALL_ACCESS_PROJECTS} from 'sentry/constants/pageFilters';
  3. import type {Organization} from 'sentry/types/organization';
  4. import type {SpanResult, TraceResult} from './content';
  5. import type {Field} from './data';
  6. export function normalizeTraces(traces: TraceResult[] | undefined) {
  7. if (!traces) {
  8. return traces;
  9. }
  10. return traces.sort(
  11. // Only sort name == null to the end, the rest leave in the original order.
  12. (t1, t2) => (t1.name ? '0' : '1').localeCompare(t2.name ? '0' : '1')
  13. );
  14. }
  15. export function getStylingSliceName(
  16. sliceName: string | null,
  17. sliceSecondaryName: string | null
  18. ) {
  19. if (sliceSecondaryName) {
  20. // Our color picking relies on the first 4 letters. Since we want to differentiate sdknames and project names we have to include part of the sdk name.
  21. return (sliceName ?? '').slice(0, 1) + sliceSecondaryName.slice(-4);
  22. }
  23. return sliceName;
  24. }
  25. export function areQueriesEmpty(queries: string[]): boolean {
  26. if (queries.length > 1) {
  27. return false;
  28. }
  29. if (queries.length === 0) {
  30. return true;
  31. }
  32. if (queries.length === 1) {
  33. return queries[0].length === 0;
  34. }
  35. return false;
  36. }
  37. export function getSecondaryNameFromSpan(span: SpanResult<Field>) {
  38. return span['sdk.name'];
  39. }
  40. export function generateTracesRoute({orgSlug}: {orgSlug: Organization['slug']}): string {
  41. return `/organizations/${orgSlug}/traces/`;
  42. }
  43. export function generateTracesRouteWithQuery({
  44. orgSlug,
  45. metric,
  46. query,
  47. }: {
  48. orgSlug: Organization['slug'];
  49. metric?: {
  50. mri: string;
  51. op: string;
  52. max?: number;
  53. min?: number;
  54. query?: string;
  55. };
  56. query?: Location['query'];
  57. }): LocationDescriptor {
  58. const {
  59. mri,
  60. op: metricsOp,
  61. query: metricsQuery,
  62. max: metricsMax,
  63. min: metricsMin,
  64. } = metric || {};
  65. const pathname = generateTracesRoute({orgSlug});
  66. return {
  67. pathname,
  68. query: {
  69. ...query,
  70. metricsMax,
  71. metricsMin,
  72. metricsOp,
  73. metricsQuery,
  74. mri,
  75. },
  76. };
  77. }
  78. export function getShortenedSdkName(sdkName: string | null) {
  79. if (!sdkName) {
  80. return '';
  81. }
  82. const sdkNameParts = sdkName.split('.');
  83. if (sdkNameParts.length <= 1) {
  84. return sdkName;
  85. }
  86. return sdkNameParts[sdkNameParts.length - 1];
  87. }
  88. export const ALL_PROJECTS = [ALL_ACCESS_PROJECTS];