コード例 #1
0
        /// <summary>
        /// Retrieves a list of traces specified by ID. Each trace is a collection of segment
        /// documents that originates from a single request. Use <code>GetTraceSummaries</code>
        /// to get a list of trace IDs.
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the BatchGetTraces service method.</param>
        ///
        /// <returns>The response from the BatchGetTraces service method, as returned by XRay.</returns>
        /// <exception cref="Amazon.XRay.Model.InvalidRequestException">
        /// The request is missing required parameters or has invalid parameters.
        /// </exception>
        /// <exception cref="Amazon.XRay.Model.ThrottledException">
        /// The request exceeds the maximum number of requests per second.
        /// </exception>
        public virtual BatchGetTracesResponse BatchGetTraces(BatchGetTracesRequest request)
        {
            var marshaller   = BatchGetTracesRequestMarshaller.Instance;
            var unmarshaller = BatchGetTracesResponseUnmarshaller.Instance;

            return(Invoke <BatchGetTracesRequest, BatchGetTracesResponse>(request, marshaller, unmarshaller));
        }
コード例 #2
0
        protected async System.Threading.Tasks.Task <BatchGetTracesResponse> BatchGetTracesAsync(string traceId)
        {
            var request = new BatchGetTracesRequest();

            request.TraceIds = new List <string>()
            {
                traceId
            };

            int retries = 0;
            BatchGetTracesResponse response = null;

            // Retry for 30s
            while (retries < 60)
            {
                response = await XrayClient.BatchGetTracesAsync(request);

                if (response.Traces.Count > 0)
                {
                    break;
                }
                else
                {
                    retries++;
                    Thread.Sleep(500);
                }
            }

            return(response);
        }
コード例 #3
0
        protected BatchGetTracesResponse BatchGetTraces(string traceId)
        {
            var request = new BatchGetTracesRequest();

            request.TraceIds = new List <string>()
            {
                traceId
            };

            int retries = 0;
            BatchGetTracesResponse response = null;

            while (retries < 60)
            {
                response = XrayClient.BatchGetTraces(request);
                if (response.Traces.Count > 0)
                {
                    break;
                }
                else
                {
                    retries++;
                    Thread.Sleep(500);
                }
            }

            return(response);
        }
コード例 #4
0
        internal BatchGetTracesResponse BatchGetTraces(BatchGetTracesRequest request)
        {
            var marshaller   = new BatchGetTracesRequestMarshaller();
            var unmarshaller = BatchGetTracesResponseUnmarshaller.Instance;

            return(Invoke <BatchGetTracesRequest, BatchGetTracesResponse>(request, marshaller, unmarshaller));
        }
コード例 #5
0
        /// <summary>
        /// Initiates the asynchronous execution of the BatchGetTraces operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the BatchGetTraces operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public virtual Task <BatchGetTracesResponse> BatchGetTracesAsync(BatchGetTracesRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = BatchGetTracesRequestMarshaller.Instance;
            var unmarshaller = BatchGetTracesResponseUnmarshaller.Instance;

            return(InvokeAsync <BatchGetTracesRequest, BatchGetTracesResponse>(request, marshaller,
                                                                               unmarshaller, cancellationToken));
        }
コード例 #6
0
        /// <summary>
        /// Initiates the asynchronous execution of the BatchGetTraces operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the BatchGetTraces operation on AmazonXRayClient.</param>
        /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
        /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
        ///          procedure using the AsyncState property.</param>
        ///
        /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndBatchGetTraces
        ///         operation.</returns>
        public virtual IAsyncResult BeginBatchGetTraces(BatchGetTracesRequest request, AsyncCallback callback, object state)
        {
            var marshaller   = new BatchGetTracesRequestMarshaller();
            var unmarshaller = BatchGetTracesResponseUnmarshaller.Instance;

            return(BeginInvoke <BatchGetTracesRequest>(request, marshaller, unmarshaller,
                                                       callback, state));
        }
コード例 #7
0
        /// <summary>
        /// Initiates the asynchronous execution of the BatchGetTraces operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the BatchGetTraces operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public virtual Task <BatchGetTracesResponse> BatchGetTracesAsync(BatchGetTracesRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = BatchGetTracesRequestMarshaller.Instance;
            options.ResponseUnmarshaller = BatchGetTracesResponseUnmarshaller.Instance;

            return(InvokeAsync <BatchGetTracesResponse>(request, options, cancellationToken));
        }
コード例 #8
0
        internal virtual BatchGetTracesResponse BatchGetTraces(BatchGetTracesRequest request)
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = BatchGetTracesRequestMarshaller.Instance;
            options.ResponseUnmarshaller = BatchGetTracesResponseUnmarshaller.Instance;

            return(Invoke <BatchGetTracesResponse>(request, options));
        }
コード例 #9
0
        public async Task <State> CollectMetrics(State state, ILambdaContext context)
        {
            state.EndTimeInEpoch = DateTimeOffset.UtcNow.ToUnixTimeSeconds();

            var client = new AmazonXRayClient(RegionEndpoint.APSoutheast2);
            var getTraceSummariesRequest = new GetTraceSummariesRequest
            {
                StartTime     = DateTimeOffset.FromUnixTimeSeconds(state.StartTimeInEpoch).UtcDateTime,
                EndTime       = DateTimeOffset.FromUnixTimeSeconds(state.EndTimeInEpoch).UtcDateTime,
                TimeRangeType = TimeRangeType.Event
            };

            var getTraceSummariesResponse = await client.GetTraceSummariesAsync(getTraceSummariesRequest);

            var traceIds = getTraceSummariesResponse.TraceSummaries.Select(x => x.Id);
            var traces   = new List <Trace>();

            foreach (var batchIds in Batch(traceIds, XRayBatchSize))
            {
                var request = new BatchGetTracesRequest
                {
                    TraceIds = batchIds.ToList(),
                };
                var response = await client.BatchGetTracesAsync(request);

                traces.AddRange(response.Traces);
            }

            var metrics = new List <LambdaMetric>();

            foreach (var trace in traces)
            {
                foreach (var segment in trace.Segments)
                {
                    var document = JsonConvert.DeserializeObject <XRayLambdaTrace.Document>(segment.Document);
                    Console.WriteLine(segment.Document);
                    if (document.name == state.FunctionName)
                    {
                        if (document.origin == "AWS::Lambda::Function")
                        {
                            metrics.Add(CreateLambdaMetric(document, document.trace_id, document.name, document.origin, "Total"));
                            foreach (var subSegment in document.subsegments)
                            {
                                metrics.Add(CreateLambdaMetric(subSegment, document.trace_id, document.name, document.origin, null));
                            }
                        }
                        else if (document.origin == "AWS::Lambda")
                        {
                            metrics.Add(CreateLambdaMetric(document, document.trace_id, document.name, document.origin, "Total"));
                        }
                    }
                }
            }

            var contentBody = string.Empty;

            using (var writer = new StringWriter())
                using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture, true))
                {
                    csv.WriteRecords(metrics);
                    csv.Flush();
                    contentBody = writer.ToString();
                }

            var bucketName       = System.Environment.GetEnvironmentVariable("MetricS3BucketName");
            var now              = DateTime.Now;
            var putObjectRequest = new PutObjectRequest
            {
                BucketName  = bucketName,
                Key         = $"{now:yyyy-MM-dd}/{state.FunctionName}-{now:HHmmss}.csv",
                ContentType = "text/csv",
                ContentBody = contentBody
            };

            var s3Client = new AmazonS3Client(RegionEndpoint.APSoutheast2);
            await s3Client.PutObjectAsync(putObjectRequest);

            return(state);
        }