utils.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 sliceSecondaryName.slice(-2) + (sliceName ?? '');
  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. metricsOp: string;
  38. mri: string;
  39. metricsQuery?: string;
  40. };
  41. query?: Location['query'];
  42. }): LocationDescriptor {
  43. const {metricsOp, metricsQuery, mri} = metric || {};
  44. const pathname = generateTracesRoute({orgSlug});
  45. return {
  46. pathname,
  47. query: {
  48. ...query,
  49. metricsOp,
  50. metricsQuery,
  51. mri,
  52. },
  53. };
  54. }
  55. export function getShortenedSdkName(sdkName: string | null) {
  56. if (!sdkName) {
  57. return '';
  58. }
  59. const sdkNameParts = sdkName.split('.');
  60. if (sdkNameParts.length <= 1) {
  61. return sdkName;
  62. }
  63. return sdkNameParts[sdkNameParts.length - 1];
  64. }