예제 #1
0
async def test_patch_traces_async(transport: str = "grpc_asyncio"):
    client = TraceServiceAsyncClient(
        credentials=credentials.AnonymousCredentials(),
        transport=transport,
    )

    # Everything is optional in proto3 as far as the runtime is concerned,
    # and we are mocking out the actual API, so just send an empty request.
    request = trace.PatchTracesRequest()

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client._client._transport.patch_traces),
                           "__call__") as call:
        # Designate an appropriate return value for the call.
        call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None)

        response = await client.patch_traces(request)

        # Establish that the underlying gRPC stub method was called.
        assert len(call.mock_calls)
        _, args, _ = call.mock_calls[0]

        assert args[0] == request

    # Establish that the response is the type that we expect.
    assert response is None
예제 #2
0
async def test_patch_traces_flattened_error_async():
    client = TraceServiceAsyncClient(
        credentials=credentials.AnonymousCredentials(), )

    # Attempting to call a method with both a request object and flattened
    # fields is an error.
    with pytest.raises(ValueError):
        await client.patch_traces(
            trace.PatchTracesRequest(),
            project_id="project_id_value",
            traces=trace.Traces(
                traces=[trace.Trace(project_id="project_id_value")]),
        )
예제 #3
0
    def patch_traces(
            self,
            request: trace.PatchTracesRequest = None,
            *,
            project_id: str = None,
            traces: trace.Traces = None,
            retry: retries.Retry = gapic_v1.method.DEFAULT,
            timeout: float = None,
            metadata: Sequence[Tuple[str, str]] = (),
    ) -> None:
        r"""Sends new traces to Stackdriver Trace or updates
        existing traces. If the ID of a trace that you send
        matches that of an existing trace, any fields in the
        existing trace and its spans are overwritten by the
        provided values, and any new fields provided are merged
        with the existing trace data. If the ID does not match,
        a new trace is created.

        Args:
            request (:class:`~.trace.PatchTracesRequest`):
                The request object. The request message for the
                `PatchTraces` method.
            project_id (:class:`str`):
                Required. ID of the Cloud project
                where the trace data is stored.
                This corresponds to the ``project_id`` field
                on the ``request`` instance; if ``request`` is provided, this
                should not be set.
            traces (:class:`~.trace.Traces`):
                Required. The body of the message.
                This corresponds to the ``traces`` field
                on the ``request`` instance; if ``request`` is provided, this
                should not be set.

            retry (google.api_core.retry.Retry): Designation of what errors, if any,
                should be retried.
            timeout (float): The timeout for this request.
            metadata (Sequence[Tuple[str, str]]): Strings which should be
                sent along with the request as metadata.
        """
        # Create or coerce a protobuf request object.
        # Sanity check: If we got a request object, we should *not* have
        # gotten any keyword arguments that map to the request.
        has_flattened_params = any([project_id, traces])
        if request is not None and has_flattened_params:
            raise ValueError("If the `request` argument is set, then none of "
                             "the individual field arguments should be set.")

        # Minor optimization to avoid making a copy if the user passes
        # in a trace.PatchTracesRequest.
        # There's no risk of modifying the input as we've already verified
        # there are no flattened fields.
        if not isinstance(request, trace.PatchTracesRequest):
            request = trace.PatchTracesRequest(request)

            # If we have keyword arguments corresponding to fields on the
            # request, apply these.

            if project_id is not None:
                request.project_id = project_id
            if traces is not None:
                request.traces = traces

        # Wrap the RPC method; this adds retry and timeout information,
        # and friendly error handling.
        rpc = self._transport._wrapped_methods[self._transport.patch_traces]

        # Send the request.
        rpc(
            request,
            retry=retry,
            timeout=timeout,
            metadata=metadata,
        )
예제 #4
0
    async def patch_traces(
            self,
            request: trace.PatchTracesRequest = None,
            *,
            project_id: str = None,
            traces: trace.Traces = None,
            retry: retries.Retry = gapic_v1.method.DEFAULT,
            timeout: float = None,
            metadata: Sequence[Tuple[str, str]] = (),
    ) -> None:
        r"""Sends new traces to Stackdriver Trace or updates
        existing traces. If the ID of a trace that you send
        matches that of an existing trace, any fields in the
        existing trace and its spans are overwritten by the
        provided values, and any new fields provided are merged
        with the existing trace data. If the ID does not match,
        a new trace is created.

        Args:
            request (:class:`google.cloud.trace_v1.types.PatchTracesRequest`):
                The request object. The request message for the
                `PatchTraces` method.
            project_id (:class:`str`):
                Required. ID of the Cloud project
                where the trace data is stored.

                This corresponds to the ``project_id`` field
                on the ``request`` instance; if ``request`` is provided, this
                should not be set.
            traces (:class:`google.cloud.trace_v1.types.Traces`):
                Required. The body of the message.
                This corresponds to the ``traces`` field
                on the ``request`` instance; if ``request`` is provided, this
                should not be set.
            retry (google.api_core.retry.Retry): Designation of what errors, if any,
                should be retried.
            timeout (float): The timeout for this request.
            metadata (Sequence[Tuple[str, str]]): Strings which should be
                sent along with the request as metadata.
        """
        # Create or coerce a protobuf request object.
        # Sanity check: If we got a request object, we should *not* have
        # gotten any keyword arguments that map to the request.
        has_flattened_params = any([project_id, traces])
        if request is not None and has_flattened_params:
            raise ValueError("If the `request` argument is set, then none of "
                             "the individual field arguments should be set.")

        request = trace.PatchTracesRequest(request)

        # If we have keyword arguments corresponding to fields on the
        # request, apply these.
        if project_id is not None:
            request.project_id = project_id
        if traces is not None:
            request.traces = traces

        # Wrap the RPC method; this adds retry and timeout information,
        # and friendly error handling.
        rpc = gapic_v1.method_async.wrap_method(
            self._client._transport.patch_traces,
            default_retry=retries.Retry(
                initial=0.1,
                maximum=1.0,
                multiplier=1.2,
                predicate=retries.if_exception_type(
                    core_exceptions.DeadlineExceeded,
                    core_exceptions.ServiceUnavailable,
                ),
                deadline=45.0,
            ),
            default_timeout=45.0,
            client_info=DEFAULT_CLIENT_INFO,
        )

        # Send the request.
        await rpc(
            request,
            retry=retry,
            timeout=timeout,
            metadata=metadata,
        )