function getComponentName(elem) {
  // @ts-expect-error WINDOW has HTMLElement
  if (!WINDOW.HTMLElement) {
    return null;
  }

  let currentElem = elem ;
  const MAX_TRAVERSE_HEIGHT = 5;
  for (let i = 0; i < MAX_TRAVERSE_HEIGHT; i++) {
    if (!currentElem) {
      return null;
    }

    if (currentElem instanceof HTMLElement && currentElem.dataset['sentryComponent']) {
      return currentElem.dataset['sentryComponent'];
    }

    currentElem = currentElem.parentNode;
  }

  return null;
}
Given a DOM element, traverses up the tree until it finds the first ancestor node
that has the `data-sentry-component` attribute. This attribute is added at build-time
by projects that have the component name annotation plugin installed.

@returns a string representation of the component for the provided DOM element, or `null` if not found