utils.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import {LocationDescriptor, Query} from 'history';
  2. import {PAGE_URL_PARAM} from 'sentry/constants/pageFilters';
  3. import {OrganizationSummary} from 'sentry/types';
  4. import {TraceFullDetailed} from 'sentry/utils/performance/quickTrace/types';
  5. import {reduceTrace} from 'sentry/utils/performance/quickTrace/utils';
  6. import {TraceInfo} from './types';
  7. export function getTraceDetailsUrl(
  8. organization: OrganizationSummary,
  9. traceSlug: string,
  10. dateSelection,
  11. query: Query
  12. ): LocationDescriptor {
  13. const {start, end, statsPeriod} = dateSelection;
  14. return {
  15. pathname: `/organizations/${organization.slug}/performance/trace/${traceSlug}/`,
  16. query: {
  17. ...query,
  18. statsPeriod,
  19. [PAGE_URL_PARAM.PAGE_START]: start,
  20. [PAGE_URL_PARAM.PAGE_END]: end,
  21. },
  22. };
  23. }
  24. function traceVisitor() {
  25. return (accumulator: TraceInfo, event: TraceFullDetailed) => {
  26. for (const error of event.errors ?? []) {
  27. accumulator.errors.add(error.event_id);
  28. }
  29. accumulator.transactions.add(event.event_id);
  30. accumulator.projects.add(event.project_slug);
  31. accumulator.startTimestamp = Math.min(
  32. accumulator.startTimestamp,
  33. event.start_timestamp
  34. );
  35. accumulator.endTimestamp = Math.max(accumulator.endTimestamp, event.timestamp);
  36. accumulator.maxGeneration = Math.max(accumulator.maxGeneration, event.generation);
  37. return accumulator;
  38. };
  39. }
  40. export function getTraceInfo(traces: TraceFullDetailed[]) {
  41. const initial = {
  42. projects: new Set<string>(),
  43. errors: new Set<string>(),
  44. transactions: new Set<string>(),
  45. startTimestamp: Number.MAX_SAFE_INTEGER,
  46. endTimestamp: 0,
  47. maxGeneration: 0,
  48. };
  49. return traces.reduce(
  50. (info: TraceInfo, trace: TraceFullDetailed) =>
  51. reduceTrace<TraceInfo>(trace, traceVisitor(), info),
  52. initial
  53. );
  54. }
  55. export function isRootTransaction(trace: TraceFullDetailed): boolean {
  56. // Root transactions has no parent_span_id
  57. return trace.parent_span_id === null;
  58. }