utils.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import type {Location} from 'history';
  2. import {normalizeDateTimeParams} from 'sentry/components/organizations/pageFilters/parse';
  3. import {ALL_ACCESS_PROJECTS} from 'sentry/constants/pageFilters';
  4. import type {EventTransaction} from 'sentry/types/event';
  5. import type {Organization} from 'sentry/types/organization';
  6. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  7. import normalizeUrl from 'sentry/utils/url/normalizeUrl';
  8. export function getProfileMeta(event: EventTransaction | null) {
  9. const profileId = event?.contexts?.profile?.profile_id;
  10. if (profileId) {
  11. return profileId;
  12. }
  13. const profilerId = event?.contexts?.profile?.profiler_id;
  14. if (profilerId) {
  15. const start = new Date(event.startTimestamp * 1000);
  16. const end = new Date(event.endTimestamp * 1000);
  17. return {
  18. profiler_id: profilerId,
  19. start: start.toISOString(),
  20. end: end.toISOString(),
  21. };
  22. }
  23. return null;
  24. }
  25. export enum TraceDrawerActionValueKind {
  26. TAG = 'tag',
  27. MEASUREMENT = 'measurement',
  28. ADDITIONAL_DATA = 'additional_data',
  29. SENTRY_TAG = 'sentry_tag',
  30. }
  31. export enum TraceDrawerActionKind {
  32. INCLUDE = 'include',
  33. EXCLUDE = 'exclude',
  34. GREATER_THAN = 'greater_than',
  35. LESS_THAN = 'less_than',
  36. }
  37. export function getSearchInExploreTarget(
  38. organization: Organization,
  39. location: Location,
  40. key: string,
  41. value: string,
  42. kind: TraceDrawerActionKind
  43. ) {
  44. const {start, end, statsPeriod} = normalizeDateTimeParams(location.query);
  45. const search = new MutableSearch('');
  46. if (kind === TraceDrawerActionKind.INCLUDE) {
  47. search.setFilterValues(key, [value]);
  48. } else if (kind === TraceDrawerActionKind.EXCLUDE) {
  49. search.setFilterValues(`!${key}`, [`${value}`]);
  50. } else if (kind === TraceDrawerActionKind.GREATER_THAN) {
  51. search.setFilterValues(key, [`>${value}`]);
  52. } else {
  53. search.setFilterValues(key, [`<${value}`]);
  54. }
  55. return {
  56. pathname: normalizeUrl(`/organizations/${organization.slug}/traces/`),
  57. query: {
  58. start,
  59. end,
  60. statsPeriod,
  61. query: search.formatString(),
  62. project: ALL_ACCESS_PROJECTS,
  63. },
  64. };
  65. }