utils.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. for (const performanceIssue of event.performance_issues ?? []) {
  30. accumulator.errors.add(performanceIssue.event_id);
  31. }
  32. accumulator.transactions.add(event.event_id);
  33. accumulator.projects.add(event.project_slug);
  34. accumulator.startTimestamp = Math.min(
  35. accumulator.startTimestamp,
  36. event.start_timestamp
  37. );
  38. accumulator.endTimestamp = Math.max(accumulator.endTimestamp, event.timestamp);
  39. accumulator.maxGeneration = Math.max(accumulator.maxGeneration, event.generation);
  40. return accumulator;
  41. };
  42. }
  43. export function getTraceInfo(traces: TraceFullDetailed[]) {
  44. const initial = {
  45. projects: new Set<string>(),
  46. errors: new Set<string>(),
  47. performanceIssues: new Set<string>(),
  48. transactions: new Set<string>(),
  49. startTimestamp: Number.MAX_SAFE_INTEGER,
  50. endTimestamp: 0,
  51. maxGeneration: 0,
  52. };
  53. return traces.reduce(
  54. (info: TraceInfo, trace: TraceFullDetailed) =>
  55. reduceTrace<TraceInfo>(trace, traceVisitor(), info),
  56. initial
  57. );
  58. }
  59. export function isRootTransaction(trace: TraceFullDetailed): boolean {
  60. // Root transactions has no parent_span_id
  61. return trace.parent_span_id === null;
  62. }