utils.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import type {Location, LocationDescriptor} from 'history';
  2. import type {Organization} from 'sentry/types/organization';
  3. import type {SpanResult, TraceResult} from './content';
  4. import type {Field} from './data';
  5. export function normalizeTraces(traces: TraceResult<string>[] | undefined) {
  6. if (!traces) {
  7. return traces;
  8. }
  9. return traces.sort(
  10. // Only sort name == null to the end, the rest leave in the original order.
  11. (t1, t2) => (t1.name ? '0' : '1').localeCompare(t2.name ? '0' : '1')
  12. );
  13. }
  14. export function getStylingSliceName(
  15. sliceName: string | null,
  16. sliceSecondaryName: string | null
  17. ) {
  18. if (sliceSecondaryName) {
  19. // 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.
  20. return (sliceName ?? '').slice(0, 1) + sliceSecondaryName.slice(-4);
  21. }
  22. return sliceName;
  23. }
  24. export function getSecondaryNameFromSpan(span: SpanResult<Field>) {
  25. return span['sdk.name'];
  26. }
  27. export function generateTracesRoute({orgSlug}: {orgSlug: Organization['slug']}): string {
  28. return `/organizations/${orgSlug}/performance/traces/`;
  29. }
  30. export function generateTracesRouteWithQuery({
  31. orgSlug,
  32. metric,
  33. query,
  34. }: {
  35. orgSlug: Organization['slug'];
  36. metric?: {
  37. mri: string;
  38. op: string;
  39. max?: number;
  40. min?: number;
  41. query?: string;
  42. };
  43. query?: Location['query'];
  44. }): LocationDescriptor {
  45. const {
  46. mri,
  47. op: metricsOp,
  48. query: metricsQuery,
  49. max: metricsMax,
  50. min: metricsMin,
  51. } = metric || {};
  52. const pathname = generateTracesRoute({orgSlug});
  53. return {
  54. pathname,
  55. query: {
  56. ...query,
  57. metricsMax,
  58. metricsMin,
  59. metricsOp,
  60. metricsQuery,
  61. mri,
  62. },
  63. };
  64. }
  65. export function getShortenedSdkName(sdkName: string | null) {
  66. if (!sdkName) {
  67. return '';
  68. }
  69. const sdkNameParts = sdkName.split('.');
  70. if (sdkNameParts.length <= 1) {
  71. return sdkName;
  72. }
  73. return sdkNameParts[sdkNameParts.length - 1];
  74. }