예제 #1
0
        public void TestEFInterceptorNonQuery()
        {
            var efInterceptor = RegisterInterceptor(true);

            try
            {
                using (var command = new SQLiteCommand(commandText, connection))
                {
                    DbInterception.Dispatch.Command.NonQuery(command, new DbCommandInterceptionContext()); // calling API from IDbCommandInterceptor
                }
            }
            catch
            {
                // Will throw exception as command text is invalid
            }

            var segment = recorder.GetEntity() as Segment;

            Assert.IsTrue(segment.Subsegments.Count != 0);

            var subsegment = segment.Subsegments[0];

            AssertTraceCollected(subsegment);
            Assert.AreEqual(commandText, subsegment.Sql["sanitized_query"]);

            RemoveInterceptor(efInterceptor);
        }
예제 #2
0
        /// <summary>
        /// Processes Begin request by starting subsegment.
        /// </summary>
        private void ProcessBeginRequest(IExecutionContext executionContext)
        {
            var    request = executionContext.RequestContext.Request;
            Entity entity  = null;

            try
            {
                entity = _recorder.GetEntity();
            }
            catch (EntityNotAvailableException e)
            {
                _recorder.TraceContext.HandleEntityMissing(_recorder, e, "Cannot get entity while processing AWS SDK request");
            }

            var serviceName = RemoveAmazonPrefixFromServiceName(request.ServiceName);

            _recorder.BeginSubsegment(AWSXRaySDKUtils.FormatServiceName(serviceName));
            _recorder.SetNamespace("aws");

            entity = entity == null ? null : _recorder.GetEntity();

            if (TraceHeader.TryParse(entity, out TraceHeader traceHeader))
            {
                request.Headers[TraceHeader.HeaderKey] = traceHeader.ToString();
            }
            else
            {
                _logger.DebugFormat("Failed to inject trace header to AWS SDK request as the segment can't be converted to TraceHeader.");
            }
        }
        /// <summary>
        /// Trace before executing Sql command
        /// </summary>
        private void OnEventStart(EventWrittenEventArgs sqlEventData)
        {
            if (sqlEventData.Payload.Count != 4)
            {
                return;
            }

            // Skip EF request
            if (SqlRequestUtil.IsTraceable())
            {
                SqlRequestUtil.ProcessEventData(sqlEventData);

                try
                {
                    var currentSubsegment = _recorder.GetEntity() as Subsegment;
                    int id = Convert.ToInt32(sqlEventData.Payload[0], CultureInfo.InvariantCulture);
                    if (currentSubsegment != null)
                    {
                        CurrentSqlEvents.TryAdd(id, currentSubsegment);
                    }
                }
                catch (EntityNotAvailableException e)
                {
                    AWSXRayRecorder.Instance.TraceContext.HandleEntityMissing(AWSXRayRecorder.Instance, e, "Subsegment is not available in trace context.");
                }
            }
        }
예제 #4
0
        private void ProcessBeginCommand(CommandEventData eventData)
        {
            Entity entity = null;

            try
            {
                entity = _recorder.GetEntity();
            }
            catch (EntityNotAvailableException e)
            {
                _recorder.TraceContext.HandleEntityMissing(_recorder, e, "Cannot get entity while processing start of Entity Framework command.");
            }

            _recorder.BeginSubsegment(BuildSubsegmentName(eventData.Command));
            _recorder.SetNamespace("remote");
            CollectSqlInformation(eventData);
        }
예제 #5
0
        private void ProcessBeginRequest(IExecutionContext executionContext)
        {
            var    request = executionContext.RequestContext.Request;
            Entity entity  = null;

            try
            {
                entity = _recorder.GetEntity();
            }
            catch (EntityNotAvailableException e)
            {
                _recorder.TraceContext.HandleEntityMissing(_recorder, e, "Cannot get entity while processing AWS SDK request");
            }

            _recorder.BeginSubsegment(RemoveAmazonPrefixFromServiceName(request.ServiceName));
            _recorder.SetNamespace("aws");

            entity = entity == null ? null : _recorder.GetEntity();

            if (TraceHeader.TryParse(entity, out var traceHeader))
            {
                request.Headers[TraceHeader.HeaderKey] = traceHeader.ToString();

                if (request.Parameters.Any(p => p.Value == "AWSTraceHeader"))
                {
                    return;
                }

                var index = request
                            .Parameters
                            .Where(x => x.Key.StartsWith("MessageSystemAttribute"))
                            .Select(x => int.TryParse(x.Value.Split('.')[1], out var idx) ? idx : 0)
                            .Union(new[] { 0 })
                            .Max() + 1;

                request.Parameters.Add("MessageSystemAttribute" + "." + index + "." + "Name",
                                       StringUtils.FromString("AWSTraceHeader"));
                request.Parameters.Add("MessageSystemAttribute" + "." + index + "." + "Value.DataType",
                                       StringUtils.FromString("String"));
                request.Parameters.Add("MessageSystemAttribute" + "." + index + "." + "Value" + "." + "StringValue",
                                       StringUtils.FromString(traceHeader.ToString()));
            }
        }
        /// <summary>
        /// Processes Begin request by starting subsegment.
        /// </summary>
        private void ProcessBeginRequest(IExecutionContext executionContext)
        {
            var request = executionContext.RequestContext.Request;

            if (TraceHeader.TryParse(_recorder.GetEntity(), out TraceHeader traceHeader))
            {
                request.Headers[TraceHeader.HeaderKey] = traceHeader.ToString();
            }
            else
            {
                _logger.DebugFormat("Failed to inject trace header to AWS SDK request as the segment can't be converted to TraceHeader.");
            }

            _recorder.BeginSubsegment(RemoveAmazonPrefixFromServiceName(request.ServiceName));
            _recorder.SetNamespace("aws");
        }
예제 #7
0
        private void BeforeRequestEventHandler(object sender, RequestEventArgs e)
        {
            var args = e as WebServiceRequestEventArgs;

            if (args == null)
            {
                _logger.DebugFormat("Failed to handle BeforeRequestEvent, because e can't be converted to WebServiceRequestEventArgs.");
                return;
            }
            if (TraceHeader.TryParse(_recorder.GetEntity(), out TraceHeader traceHeader))
            {
                args.Headers[TraceHeader.HeaderKey] = traceHeader.ToString();
            }
            else
            {
                _logger.DebugFormat("Failed to inject trace header to AWS SDK request as the segment can't be converted to TraceHeader.");
            }
            _recorder.BeginSubsegment(RemoveAmazonPrefixFromServiceName(args.ServiceName));
            _recorder.SetNamespace("aws");
        }