/** * Gets a single trace by its ID. * * <p>Sample code: * * <pre><code> * try (TraceServiceClient traceServiceClient = TraceServiceClient.create()) { * String projectId = ""; * String traceId = ""; * Trace response = traceServiceClient.getTrace(projectId, traceId); * } * </code></pre> * * @param projectId ID of the Cloud project where the trace data is stored. * @param traceId ID of the trace to return. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Trace getTrace(String projectId, String traceId) { GetTraceRequest request = GetTraceRequest.newBuilder().setProjectId(projectId).setTraceId(traceId).build(); return getTrace(request); }
@Test @SuppressWarnings("all") public void getTraceExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockTraceService.addException(exception); try { String projectId = "projectId-1969970175"; String traceId = "traceId1270300245"; client.getTrace(projectId, traceId); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } }
@Test @SuppressWarnings("all") public void getTraceTest() { String projectId2 = "projectId2939242356"; String traceId2 = "traceId2987826376"; Trace expectedResponse = Trace.newBuilder().setProjectId(projectId2).setTraceId(traceId2).build(); mockTraceService.addResponse(expectedResponse); String projectId = "projectId-1969970175"; String traceId = "traceId1270300245"; Trace actualResponse = client.getTrace(projectId, traceId); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockTraceService.getRequests(); Assert.assertEquals(1, actualRequests.size()); GetTraceRequest actualRequest = (GetTraceRequest) actualRequests.get(0); Assert.assertEquals(projectId, actualRequest.getProjectId()); Assert.assertEquals(traceId, actualRequest.getTraceId()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }