def test_get_paginated_record_ids_otel(self):
        """Test that _get_paginated_record_ids_otel correctly paginates and filters record IDs."""
        # Load example spans from test_otel_spans
        event_files = [
            "record_root_span.json",
            "generation_span.json",
            "retrieval_span.json",
        ]
        events = self._load_events_from_json(event_files)

        # Create a second app with multiple records
        second_app_name = "second_app"
        second_app_version = "1.0.0"
        second_record_ids = [
            "second_record_1",
            "second_record_2",
            "second_record_3",
        ]

        # Create events for the second app using the template
        for i in range(len(second_record_ids)):
            event = self._create_event_from_template(
                event_id=f"event_{second_record_ids[i]}",
                record_id=second_record_ids[i],
                app_name=second_app_name,
                app_version=second_app_version,
                app_id=AppDefinition._compute_app_id(
                    second_app_name, second_app_version
                ),
                start_timestamp=f"2025-04-11 10:19:5{i}.993997",
                timestamp="2025-04-11 10:20:30.50",
            )
            events.append(event)

        # Insert all Events into the database
        for event in events:
            self.db.insert_event(event)

        with self.db.session.begin() as session:
            # Test without pagination or filtering - should get all record IDs
            stmt = self.db._get_paginated_record_ids_otel()
            results = session.execute(stmt).all()
            self.assertEqual(
                len(results), 4
            )  # 1 from first app + 3 from second app
            # Verify all record IDs are present
            record_ids = {r.record_id for r in results}
            self.assertEqual(
                record_ids, {self.STATIC_RECORD_ID, *second_record_ids}
            )

            # Test with first app_name filtering
            stmt = self.db._get_paginated_record_ids_otel(
                app_name=self.STATIC_APP_NAME
            )
            results = session.execute(stmt).all()
            self.assertEqual(
                len(results), 1
            )  # Should get only first app's record
            self.assertEqual(results[0].record_id, self.STATIC_RECORD_ID)

            # Test with second app_name filtering
            stmt = self.db._get_paginated_record_ids_otel(
                app_name=second_app_name
            )
            results = session.execute(stmt).all()
            self.assertEqual(
                len(results), 3
            )  # Should get all second app's records
            record_ids = {r.record_id for r in results}
            self.assertEqual(record_ids, set(second_record_ids))

            # Test with non-matching app_name
            stmt = self.db._get_paginated_record_ids_otel(
                app_name="non_existent_app"
            )
            results = session.execute(stmt).all()
            self.assertEqual(len(results), 0)  # Should get no results

            # Test with limit
            stmt = self.db._get_paginated_record_ids_otel(limit=2)
            results = session.execute(stmt).all()
            self.assertEqual(len(results), 2)  # Should respect limit

            # Test with offset
            stmt = self.db._get_paginated_record_ids_otel(offset=2)
            results = session.execute(stmt).all()
            self.assertEqual(len(results), 2)  # Should skip first 2 records

            # Test with both limit and offset
            stmt = self.db._get_paginated_record_ids_otel(limit=2, offset=1)
            results = session.execute(stmt).all()
            self.assertEqual(
                len(results), 2
            )  # Should get 2 records after skipping 1

            # Test ordering by timestamp
            stmt = self.db._get_paginated_record_ids_otel()
            results = session.execute(stmt).all()
            # Verify that results are ordered by start_timestamp in ascending order
            timestamps = [r.min_start_timestamp for r in results]
            self.assertEqual(timestamps, sorted(timestamps))
Test that _get_paginated_record_ids_otel correctly paginates and filters record IDs.
tests/unit/test_otel_get_records_and_feedback.py