async def dispatch(self, request: Request, call_next: Callable[[], Any]):
        """Wraps the request chain for a given request.

        Args:
            request: The request being processed
            call_next: A callable to the remaining request call-chain.

        """
        RequestMetricsStore.set_in_request(request)
        try:
            response = await call_next(request)

            # Early exit if opentelemetry is not to be injected into response.
            if not self.telemetry_enabled_for_request(request):
                return response

            data = await self.get_response_json(response)

            # Inject telemetry and fix content-length header
            telemetry = RequestMetricsStore.for_request(request).json()
            if isinstance(data, dict):
                if len(telemetry["timesMs"]) == 0:
                    telemetry.pop("timesMs")
                if len(telemetry["counter"]) == 0:
                    telemetry.pop("counter")
                data["telemetry"] = telemetry
            else:
                get_logger(__name__).warning(
                    f"{self.telemetry_flag} set but response payload is not Dict. telemetry not returned"
                )
                get_logger(__name__).info(
                    f"Telemetry data={orjson.dumps(telemetry).decode()}")

        finally:
            logger.debug('Clearing metrics for request')
            RequestMetricsStore.clear_metrics_for(request)

        body = orjson.dumps(data)
        response.headers["content-length"] = str(len(body))

        return Response(
            content=body,
            status_code=response.status_code,
            headers=dict(response.headers),
            media_type=response.media_type
        )
Wraps the request chain for a given request.

        Args:
            request: The request being processed
            call_next: A callable to the remaining request call-chain.

        
src/marqo/tensor_search/telemetry.py