# This file was auto-generated by Fern from our API Definition.

import typing
from json.decoder import JSONDecodeError

from ..core.api_error import ApiError
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.http_response import AsyncHttpResponse, HttpResponse
from ..core.jsonable_encoder import jsonable_encoder
from ..core.pydantic_utilities import parse_obj_as
from ..core.request_options import RequestOptions
from ..core.serialization import convert_and_respect_annotation_metadata
from ..errors.unprocessable_entity_error import UnprocessableEntityError
from ..types.focus import Focus
from ..types.format import Format
from ..types.http_validation_error import HttpValidationError
from ..types.o_tel_flat_span import OTelFlatSpan
from ..types.o_tel_links_response import OTelLinksResponse
from ..types.o_tel_spans_tree import OTelSpansTree
from ..types.o_tel_tracing_response import OTelTracingResponse
from .types.fetch_trace_request_trace_id import FetchTraceRequestTraceId
from .types.remove_trace_request_trace_id import RemoveTraceRequestTraceId

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class RawTracingClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._client_wrapper = client_wrapper

    def add_trace(
        self,
        *,
        spans: typing.Optional[typing.Sequence[OTelFlatSpan]] = OMIT,
        traces: typing.Optional[
            typing.Dict[str, typing.Optional[OTelSpansTree]]
        ] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[OTelLinksResponse]:
        """
        Parameters
        ----------
        spans : typing.Optional[typing.Sequence[OTelFlatSpan]]

        traces : typing.Optional[typing.Dict[str, typing.Optional[OTelSpansTree]]]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[OTelLinksResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "preview/tracing/traces/",
            method="POST",
            json={
                "spans": convert_and_respect_annotation_metadata(
                    object_=spans,
                    annotation=typing.Sequence[OTelFlatSpan],
                    direction="write",
                ),
                "traces": convert_and_respect_annotation_metadata(
                    object_=traces,
                    annotation=typing.Dict[str, typing.Optional[OTelSpansTree]],
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    OTelLinksResponse,
                    parse_obj_as(
                        type_=OTelLinksResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    def edit_trace(
        self,
        *,
        spans: typing.Optional[typing.Sequence[OTelFlatSpan]] = OMIT,
        traces: typing.Optional[
            typing.Dict[str, typing.Optional[OTelSpansTree]]
        ] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[OTelLinksResponse]:
        """
        Parameters
        ----------
        spans : typing.Optional[typing.Sequence[OTelFlatSpan]]

        traces : typing.Optional[typing.Dict[str, typing.Optional[OTelSpansTree]]]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[OTelLinksResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "preview/tracing/traces/",
            method="PUT",
            json={
                "spans": convert_and_respect_annotation_metadata(
                    object_=spans,
                    annotation=typing.Sequence[OTelFlatSpan],
                    direction="write",
                ),
                "traces": convert_and_respect_annotation_metadata(
                    object_=traces,
                    annotation=typing.Dict[str, typing.Optional[OTelSpansTree]],
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    OTelLinksResponse,
                    parse_obj_as(
                        type_=OTelLinksResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    def fetch_trace(
        self,
        trace_id: FetchTraceRequestTraceId,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[OTelTracingResponse]:
        """
        Parameters
        ----------
        trace_id : FetchTraceRequestTraceId

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[OTelTracingResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"preview/tracing/traces/{jsonable_encoder(trace_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    OTelTracingResponse,
                    parse_obj_as(
                        type_=OTelTracingResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    def remove_trace(
        self,
        trace_id: RemoveTraceRequestTraceId,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[OTelLinksResponse]:
        """
        Parameters
        ----------
        trace_id : RemoveTraceRequestTraceId

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[OTelLinksResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"preview/tracing/traces/{jsonable_encoder(trace_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    OTelLinksResponse,
                    parse_obj_as(
                        type_=OTelLinksResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    def query_spans(
        self,
        *,
        filter: str,
        focus: typing.Optional[Focus] = None,
        format: typing.Optional[Format] = None,
        oldest: typing.Optional[str] = None,
        newest: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[OTelTracingResponse]:
        """
        Parameters
        ----------
        filter : str

        focus : typing.Optional[Focus]

        format : typing.Optional[Format]

        oldest : typing.Optional[str]

        newest : typing.Optional[str]

        limit : typing.Optional[int]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[OTelTracingResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "preview/tracing/spans/",
            method="GET",
            params={
                "focus": focus,
                "format": format,
                "oldest": oldest,
                "newest": newest,
                "limit": limit,
                "filter": filter,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    OTelTracingResponse,
                    parse_obj_as(
                        type_=OTelTracingResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    def ingest_spans(
        self,
        *,
        spans: typing.Optional[typing.Sequence[OTelFlatSpan]] = OMIT,
        traces: typing.Optional[
            typing.Dict[str, typing.Optional[OTelSpansTree]]
        ] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[OTelLinksResponse]:
        """
        Parameters
        ----------
        spans : typing.Optional[typing.Sequence[OTelFlatSpan]]

        traces : typing.Optional[typing.Dict[str, typing.Optional[OTelSpansTree]]]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[OTelLinksResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "preview/tracing/spans/",
            method="POST",
            json={
                "spans": convert_and_respect_annotation_metadata(
                    object_=spans,
                    annotation=typing.Sequence[OTelFlatSpan],
                    direction="write",
                ),
                "traces": convert_and_respect_annotation_metadata(
                    object_=traces,
                    annotation=typing.Dict[str, typing.Optional[OTelSpansTree]],
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    OTelLinksResponse,
                    parse_obj_as(
                        type_=OTelLinksResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    def ingest_spans_rpc(
        self,
        *,
        spans: typing.Optional[typing.Sequence[OTelFlatSpan]] = OMIT,
        traces: typing.Optional[
            typing.Dict[str, typing.Optional[OTelSpansTree]]
        ] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[OTelLinksResponse]:
        """
        Parameters
        ----------
        spans : typing.Optional[typing.Sequence[OTelFlatSpan]]

        traces : typing.Optional[typing.Dict[str, typing.Optional[OTelSpansTree]]]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[OTelLinksResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "preview/tracing/spans/ingest",
            method="POST",
            json={
                "spans": convert_and_respect_annotation_metadata(
                    object_=spans,
                    annotation=typing.Sequence[OTelFlatSpan],
                    direction="write",
                ),
                "traces": convert_and_respect_annotation_metadata(
                    object_=traces,
                    annotation=typing.Dict[str, typing.Optional[OTelSpansTree]],
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    OTelLinksResponse,
                    parse_obj_as(
                        type_=OTelLinksResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    def query_spans_rpc(
        self,
        *,
        filter: str,
        focus: typing.Optional[Focus] = None,
        format: typing.Optional[Format] = None,
        oldest: typing.Optional[str] = None,
        newest: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[OTelTracingResponse]:
        """
        Parameters
        ----------
        filter : str

        focus : typing.Optional[Focus]

        format : typing.Optional[Format]

        oldest : typing.Optional[str]

        newest : typing.Optional[str]

        limit : typing.Optional[int]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[OTelTracingResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "preview/tracing/spans/query",
            method="POST",
            params={
                "focus": focus,
                "format": format,
                "oldest": oldest,
                "newest": newest,
                "limit": limit,
                "filter": filter,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    OTelTracingResponse,
                    parse_obj_as(
                        type_=OTelTracingResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )


class AsyncRawTracingClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def add_trace(
        self,
        *,
        spans: typing.Optional[typing.Sequence[OTelFlatSpan]] = OMIT,
        traces: typing.Optional[
            typing.Dict[str, typing.Optional[OTelSpansTree]]
        ] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[OTelLinksResponse]:
        """
        Parameters
        ----------
        spans : typing.Optional[typing.Sequence[OTelFlatSpan]]

        traces : typing.Optional[typing.Dict[str, typing.Optional[OTelSpansTree]]]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[OTelLinksResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "preview/tracing/traces/",
            method="POST",
            json={
                "spans": convert_and_respect_annotation_metadata(
                    object_=spans,
                    annotation=typing.Sequence[OTelFlatSpan],
                    direction="write",
                ),
                "traces": convert_and_respect_annotation_metadata(
                    object_=traces,
                    annotation=typing.Dict[str, typing.Optional[OTelSpansTree]],
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    OTelLinksResponse,
                    parse_obj_as(
                        type_=OTelLinksResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    async def edit_trace(
        self,
        *,
        spans: typing.Optional[typing.Sequence[OTelFlatSpan]] = OMIT,
        traces: typing.Optional[
            typing.Dict[str, typing.Optional[OTelSpansTree]]
        ] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[OTelLinksResponse]:
        """
        Parameters
        ----------
        spans : typing.Optional[typing.Sequence[OTelFlatSpan]]

        traces : typing.Optional[typing.Dict[str, typing.Optional[OTelSpansTree]]]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[OTelLinksResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "preview/tracing/traces/",
            method="PUT",
            json={
                "spans": convert_and_respect_annotation_metadata(
                    object_=spans,
                    annotation=typing.Sequence[OTelFlatSpan],
                    direction="write",
                ),
                "traces": convert_and_respect_annotation_metadata(
                    object_=traces,
                    annotation=typing.Dict[str, typing.Optional[OTelSpansTree]],
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    OTelLinksResponse,
                    parse_obj_as(
                        type_=OTelLinksResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    async def fetch_trace(
        self,
        trace_id: FetchTraceRequestTraceId,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[OTelTracingResponse]:
        """
        Parameters
        ----------
        trace_id : FetchTraceRequestTraceId

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[OTelTracingResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"preview/tracing/traces/{jsonable_encoder(trace_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    OTelTracingResponse,
                    parse_obj_as(
                        type_=OTelTracingResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    async def remove_trace(
        self,
        trace_id: RemoveTraceRequestTraceId,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[OTelLinksResponse]:
        """
        Parameters
        ----------
        trace_id : RemoveTraceRequestTraceId

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[OTelLinksResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"preview/tracing/traces/{jsonable_encoder(trace_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    OTelLinksResponse,
                    parse_obj_as(
                        type_=OTelLinksResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    async def query_spans(
        self,
        *,
        filter: str,
        focus: typing.Optional[Focus] = None,
        format: typing.Optional[Format] = None,
        oldest: typing.Optional[str] = None,
        newest: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[OTelTracingResponse]:
        """
        Parameters
        ----------
        filter : str

        focus : typing.Optional[Focus]

        format : typing.Optional[Format]

        oldest : typing.Optional[str]

        newest : typing.Optional[str]

        limit : typing.Optional[int]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[OTelTracingResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "preview/tracing/spans/",
            method="GET",
            params={
                "focus": focus,
                "format": format,
                "oldest": oldest,
                "newest": newest,
                "limit": limit,
                "filter": filter,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    OTelTracingResponse,
                    parse_obj_as(
                        type_=OTelTracingResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    async def ingest_spans(
        self,
        *,
        spans: typing.Optional[typing.Sequence[OTelFlatSpan]] = OMIT,
        traces: typing.Optional[
            typing.Dict[str, typing.Optional[OTelSpansTree]]
        ] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[OTelLinksResponse]:
        """
        Parameters
        ----------
        spans : typing.Optional[typing.Sequence[OTelFlatSpan]]

        traces : typing.Optional[typing.Dict[str, typing.Optional[OTelSpansTree]]]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[OTelLinksResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "preview/tracing/spans/",
            method="POST",
            json={
                "spans": convert_and_respect_annotation_metadata(
                    object_=spans,
                    annotation=typing.Sequence[OTelFlatSpan],
                    direction="write",
                ),
                "traces": convert_and_respect_annotation_metadata(
                    object_=traces,
                    annotation=typing.Dict[str, typing.Optional[OTelSpansTree]],
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    OTelLinksResponse,
                    parse_obj_as(
                        type_=OTelLinksResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    async def ingest_spans_rpc(
        self,
        *,
        spans: typing.Optional[typing.Sequence[OTelFlatSpan]] = OMIT,
        traces: typing.Optional[
            typing.Dict[str, typing.Optional[OTelSpansTree]]
        ] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[OTelLinksResponse]:
        """
        Parameters
        ----------
        spans : typing.Optional[typing.Sequence[OTelFlatSpan]]

        traces : typing.Optional[typing.Dict[str, typing.Optional[OTelSpansTree]]]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[OTelLinksResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "preview/tracing/spans/ingest",
            method="POST",
            json={
                "spans": convert_and_respect_annotation_metadata(
                    object_=spans,
                    annotation=typing.Sequence[OTelFlatSpan],
                    direction="write",
                ),
                "traces": convert_and_respect_annotation_metadata(
                    object_=traces,
                    annotation=typing.Dict[str, typing.Optional[OTelSpansTree]],
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    OTelLinksResponse,
                    parse_obj_as(
                        type_=OTelLinksResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    async def query_spans_rpc(
        self,
        *,
        filter: str,
        focus: typing.Optional[Focus] = None,
        format: typing.Optional[Format] = None,
        oldest: typing.Optional[str] = None,
        newest: typing.Optional[str] = None,
        limit: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[OTelTracingResponse]:
        """
        Parameters
        ----------
        filter : str

        focus : typing.Optional[Focus]

        format : typing.Optional[Format]

        oldest : typing.Optional[str]

        newest : typing.Optional[str]

        limit : typing.Optional[int]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[OTelTracingResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "preview/tracing/spans/query",
            method="POST",
            params={
                "focus": focus,
                "format": format,
                "oldest": oldest,
                "newest": newest,
                "limit": limit,
                "filter": filter,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    OTelTracingResponse,
                    parse_obj_as(
                        type_=OTelTracingResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )
