public static int Main(string[] args) { // Read projectId from args if (args.Length != 1) { Console.WriteLine("Usage: Project ID must be passed as first argument."); Console.WriteLine(); return(1); } string projectId = args[0]; // Create client TraceServiceClient client = TraceServiceClient.Create(); // Initialize request argument(s) string projectId2 = projectId; // Call API method PagedEnumerable <ListTracesResponse, Trace> pagedResponse = client.ListTraces(projectId2); // Show the result foreach (var item in pagedResponse) { Console.WriteLine(item); } // Success Console.WriteLine("Smoke test passed OK"); return(0); }
public void ListTraces() { // Snippet: ListTraces(string,string,int?,CallSettings) // Create client TraceServiceClient traceServiceClient = TraceServiceClient.Create(); // Initialize request argument(s) string projectId = ""; // Make the request IPagedEnumerable <ListTracesResponse, Trace> response = traceServiceClient.ListTraces(projectId); // Iterate over all response items, lazily performing RPCs as required foreach (Trace item in response) { // Do something with each item Console.WriteLine(item); } // Or iterate over fixed-sized pages, lazily performing RPCs as required int pageSize = 10; foreach (FixedSizePage <Trace> page in response.AsPages().WithFixedSize(pageSize)) { // Do something with each page of items Console.WriteLine("A page of results:"); foreach (Trace item in page) { Console.WriteLine(item); } } // End snippet }
/// <summary>Snippet for ListTraces</summary> public void ListTracesRequestObject() { // Snippet: ListTraces(ListTracesRequest, CallSettings) // Create client TraceServiceClient traceServiceClient = TraceServiceClient.Create(); // Initialize request argument(s) ListTracesRequest request = new ListTracesRequest { ProjectId = "", View = ListTracesRequest.Types.ViewType.Unspecified, StartTime = new Timestamp(), EndTime = new Timestamp(), Filter = "", OrderBy = "", }; // Make the request PagedEnumerable <ListTracesResponse, Trace> response = traceServiceClient.ListTraces(request); // Iterate over all response items, lazily performing RPCs as required foreach (Trace item in response) { // Do something with each item Console.WriteLine(item); } // Or iterate over pages (of server-defined size), performing one RPC per page foreach (ListTracesResponse page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); foreach (Trace item in page) { // Do something with each item Console.WriteLine(item); } } // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; Page <Trace> singlePage = response.ReadPage(pageSize); // Do something with the page of items Console.WriteLine($"A page of {pageSize} results (unless it's the final page):"); foreach (Trace item in singlePage) { // Do something with each item Console.WriteLine(item); } // Store the pageToken, for when the next page is required. string nextPageToken = singlePage.NextPageToken; // End snippet }
/// <summary> /// Gets traces containing the giving <paramref name="spanName"/>. /// </summary> /// <param name="spanName"> The name for the traces to get.</param> /// <param name="startTime"> The start time of traces to get.</param> /// <param name="minEntries"> Optional. The minimum number of entries to expect. /// Default value is 1.</param> /// <param name="pageSize"> Optional. The page size to use when making RPC calls. /// Default value is 250.</param> /// <returns></returns> public IEnumerable <TraceProto> GetTraces(string spanName, Timestamp startTime, int minEntries = 1, int pageSize = 250) { var traceList = GetEntries(minEntries, () => { ListTracesRequest request = new ListTracesRequest { ProjectId = _projectId, StartTime = startTime, View = ListTracesRequest.Types.ViewType.Complete, Filter = $"span:\"{spanName}\"", PageSize = pageSize }; return(_client.ListTraces(request)); }); return(traceList); }
public void ListTraces() { string projectId = _fixture.ProjectId; // Snippet: ListTraces TraceServiceClient client = TraceServiceClient.Create(); IPagedEnumerable <ListTracesResponse, Trace> traces = client.ListTraces(projectId); foreach (Trace trace in traces.Take(10)) { Console.WriteLine($"{trace.TraceId}:"); foreach (TraceSpan span in trace.Spans) { Console.WriteLine($" {span.StartTime}-{span.EndTime}: {span.Kind}"); } } // End snippet }
/// <summary> /// Gets a trace that contains a span with the given name. /// </summary> /// <param name="expectTrace">True if the trace is expected to exist. This is used /// to minimize RPC calls.</param> public TraceProto GetTrace(string spanName, Timestamp startTime, bool expectTrace = true) { var minEntries = expectTrace ? 1 : 0; var traceList = GetEntries(minEntries, () => { ListTracesRequest request = new ListTracesRequest { ProjectId = _projectId, StartTime = startTime, View = ListTracesRequest.Types.ViewType.Complete }; var traces = _client.ListTraces(request); return(traces.Where(t => t.Spans.Any(s => s.Name == spanName))); }); return(traceList.FirstOrDefault()); }
/// <summary> /// Gets a trace that contains a span with the given name. /// </summary> /// <param name="expectTrace">True if the trace is expected to exist. This is used /// to minimize RPC calls.</param> public TraceProto GetTrace(string spanName, Timestamp startTime, bool expectTrace = true) { var minEntries = expectTrace ? 1 : 0; var traceList = GetEntries(minEntries, () => { ListTracesRequest request = new ListTracesRequest { ProjectId = _projectId, StartTime = startTime, View = ListTracesRequest.Types.ViewType.Complete, Filter = $"span:\"{spanName}\"", PageSize = 250 }; return(_client.ListTraces(request)); }); return(traceList.FirstOrDefault()); }
/// <summary> /// Gets traces containing the giving <paramref name="spanName"/>. /// </summary> /// <param name="spanName"> The name for the traces to get.</param> /// <param name="startTime"> The start time of traces to get.</param> /// <param name="minEntries"> Optional. The minimum number of entries to expect. /// Default value is 1.</param> /// <param name="pageSize"> Optional. The page size to use when making RPC calls. /// Default value is 250.</param> /// <returns></returns> public IEnumerable <TraceProto> GetTraces(string spanName, DateTimeOffset startTime, int minEntries = 1, int pageSize = 250) { var traceList = GetEntries(minEntries, () => { ListTracesRequest request = new ListTracesRequest { ProjectId = _projectId, // We substract 5 minutes because on ocasion we were polling too fast after startTime // and the backend clock was a little behind, we were getting InvalidArgument. StartTime = Timestamp.FromDateTimeOffset(startTime - TimeSpan.FromMinutes(5)), View = ListTracesRequest.Types.ViewType.Complete, Filter = $"span:\"{spanName}\"", PageSize = pageSize }; return(_client.ListTraces(request)); }); return(traceList); }