function spanToJSON(span) {
  if (spanIsSpanClass(span)) {
    return span.getSpanJSON();
  }

  // Fallback: We also check for `.toJSON()` here...
  // eslint-disable-next-line deprecation/deprecation
  if (typeof span.toJSON === 'function') {
    // eslint-disable-next-line deprecation/deprecation
    return span.toJSON();
  }

  return {};
}
Convert a span to a JSON representation.
Note that all fields returned here are optional and need to be guarded against.

Note: Because of this, we currently have a circular type dependency (which we opted out of in package.json).
This is not avoidable as we need `spanToJSON` in `spanUtils.ts`, which in turn is needed by `span.ts` for backwards compatibility.
And `spanToJSON` needs the Span class from `span.ts` to check here.
TODO v8: When we remove the deprecated stuff from `span.ts`, we can remove the circular dependency again.