public static void executeNoCatch(String projectId) throws Exception { try (TraceServiceClient client = TraceServiceClient.create()) { String projectId2 = projectId; ListTracesPagedResponse pagedResponse = client.listTraces(projectId2); } }
@After public void tearDown() throws Exception { client.close(); }
/** * Constructs an instance of TraceServiceClient, using the given settings. The channels are * created based on the settings passed in, or defaults for any settings that are not set. */ public static final TraceServiceClient create(TraceServiceSettings settings) throws IOException { return new TraceServiceClient(settings); }
/** * 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. * * <p>Sample code: * * <pre><code> * try (TraceServiceClient traceServiceClient = TraceServiceClient.create()) { * String projectId = ""; * Traces traces = Traces.newBuilder().build(); * traceServiceClient.patchTraces(projectId, traces); * } * </code></pre> * * @param projectId ID of the Cloud project where the trace data is stored. * @param traces The body of the message. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final void patchTraces(String projectId, Traces traces) { PatchTracesRequest request = PatchTracesRequest.newBuilder().setProjectId(projectId).setTraces(traces).build(); patchTraces(request); }
/** Constructs an instance of TraceServiceClient with default settings. */ public static final TraceServiceClient create() throws IOException { return create(TraceServiceSettings.newBuilder().build()); }
/** * 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); }
/** * Returns of a list of traces that match the specified filter conditions. * * <p>Sample code: * * <pre><code> * try (TraceServiceClient traceServiceClient = TraceServiceClient.create()) { * String projectId = ""; * for (Trace element : traceServiceClient.listTraces(projectId).iterateAll()) { * // doThingsWith(element); * } * } * </code></pre> * * @param projectId ID of the Cloud project where the trace data is stored. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final ListTracesPagedResponse listTraces(String projectId) { ListTracesRequest request = ListTracesRequest.newBuilder().setProjectId(projectId).build(); return listTraces(request); }
/** * Gets a single trace by its ID. * * <p>Sample code: * * <pre><code> * try (TraceServiceClient traceServiceClient = TraceServiceClient.create()) { * String projectId = ""; * String traceId = ""; * GetTraceRequest request = GetTraceRequest.newBuilder() * .setProjectId(projectId) * .setTraceId(traceId) * .build(); * Trace response = traceServiceClient.getTrace(request); * } * </code></pre> * * @param request The request object containing all of the parameters for the API call. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Trace getTrace(GetTraceRequest request) { return getTraceCallable().call(request); }
@Test @SuppressWarnings("all") public void patchTracesExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockTraceService.addException(exception); try { String projectId = "projectId-1969970175"; Traces traces = Traces.newBuilder().build(); client.patchTraces(projectId, traces); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } }
@Before public void setUp() throws IOException { serviceHelper.reset(); channelProvider = serviceHelper.createChannelProvider(); TraceServiceSettings settings = TraceServiceSettings.newBuilder() .setTransportChannelProvider(channelProvider) .setCredentialsProvider(NoCredentialsProvider.create()) .build(); client = TraceServiceClient.create(settings); }
@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 listTracesExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockTraceService.addException(exception); try { String projectId = "projectId-1969970175"; client.listTraces(projectId); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } } }
@Test @SuppressWarnings("all") public void patchTracesTest() { Empty expectedResponse = Empty.newBuilder().build(); mockTraceService.addResponse(expectedResponse); String projectId = "projectId-1969970175"; Traces traces = Traces.newBuilder().build(); client.patchTraces(projectId, traces); List<GeneratedMessageV3> actualRequests = mockTraceService.getRequests(); Assert.assertEquals(1, actualRequests.size()); PatchTracesRequest actualRequest = (PatchTracesRequest) actualRequests.get(0); Assert.assertEquals(projectId, actualRequest.getProjectId()); Assert.assertEquals(traces, actualRequest.getTraces()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
/** * Creates a trace consumer that sends trace messages to the Stackdriver Trace API via gRPC. */ public static GrpcTraceConsumer create() throws IOException { return new GrpcTraceConsumer(TraceServiceClient.create()); } }
@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())); }
@Test @SuppressWarnings("all") public void listTracesTest() { String nextPageToken = ""; Trace tracesElement = Trace.newBuilder().build(); List<Trace> traces = Arrays.asList(tracesElement); ListTracesResponse expectedResponse = ListTracesResponse.newBuilder() .setNextPageToken(nextPageToken) .addAllTraces(traces) .build(); mockTraceService.addResponse(expectedResponse); String projectId = "projectId-1969970175"; ListTracesPagedResponse pagedListResponse = client.listTraces(projectId); List<Trace> resources = Lists.newArrayList(pagedListResponse.iterateAll()); Assert.assertEquals(1, resources.size()); Assert.assertEquals(expectedResponse.getTracesList().get(0), resources.get(0)); List<GeneratedMessageV3> actualRequests = mockTraceService.getRequests(); Assert.assertEquals(1, actualRequests.size()); ListTracesRequest actualRequest = (ListTracesRequest) actualRequests.get(0); Assert.assertEquals(projectId, actualRequest.getProjectId()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
@Override public void close() throws IOException { try { this.client.close(); } catch (Exception e) { throw new IOException(e); } } }
/** * Constructs an instance of TraceServiceClient, using the given stub for making calls. This is * for advanced usage - prefer to use TraceServiceSettings}. */ @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public static final TraceServiceClient create(TraceServiceStub stub) { return new TraceServiceClient(stub); }
@Override public void receive(Traces traces) { this.client.patchTraces(this.projectId, traces); }
/** * Creates a trace consumer that sends trace messages to the Stackdriver Trace API via gRPC. * * @param credentials a credentials used to authenticate API calls. */ public static GrpcTraceConsumer createWithCredentials(Credentials credentials) throws IOException { TraceServiceSettings traceServiceSettings = TraceServiceSettings.newBuilder() .setCredentialsProvider(FixedCredentialsProvider.create(credentials)) .build(); return new GrpcTraceConsumer(TraceServiceClient.create(traceServiceSettings)); }