public void Transform(ErrorData errorData, float priority)
        {
            if (!_configurationService.Configuration.ErrorCollectorEnabled)
            {
                return;
            }

            var attribValues = new AttributeValueCollection(AttributeDestinations.ErrorEvent, AttributeDestinations.ErrorTrace);

            if (errorData.CustomAttributes != null && _configurationService.Configuration.CaptureCustomParameters)
            {
                foreach (var customAttrib in errorData.CustomAttributes)
                {
                    _attribDefs.GetCustomAttributeForError(customAttrib.Key).TrySetValue(attribValues, customAttrib.Value);
                }
            }

            // For Custom Errors (occurring outside a transaction), UI Error Analytics page co-opts the
            // 'transactionName' attribute to find the corresponding Error Trace (matching it to 'Path')
            // so it can display the stack trace.
            _attribDefs.TransactionNameForError.TrySetValue(attribValues, errorData.Path);

            //We have to do the filtering here b/c these methods further update
            var errorTrace = _errorTraceMaker.GetErrorTrace(new AttributeValueCollection(attribValues, AttributeDestinations.ErrorTrace), errorData);
            var errorEvent = _errorEventMaker.GetErrorEvent(errorData, new AttributeValueCollection(attribValues, AttributeDestinations.ErrorEvent), priority);

            _errorTraceAggregator.Collect(errorTrace);
            _errorEventAggregator.Collect(errorEvent);
        }
        private ErrorTraceWireModel GenerateErrorTrace(ImmutableTransaction immutableTransaction, IAttributeValueCollection attributes, TransactionMetricName transactionMetricName)
        {
            if (!ErrorCollectionEnabled())
            {
                return(null);
            }

            return(_errorTraceMaker.GetErrorTrace(immutableTransaction, attributes, transactionMetricName));
        }
示例#3
0
        public void Transform_FiltersAttributesBeforeSendingThemToErrorTraceMaker()
        {
            // ARRANGE
            var attribValues = new AttributeValueCollection(AttributeDestinations.TransactionEvent, AttributeDestinations.ErrorEvent, AttributeDestinations.ErrorTrace, AttributeDestinations.JavaScriptAgent);;

            _attribDefs.GetCustomAttributeForCustomEvent("CustomEventAttrib").TrySetValue(attribValues, "CustomEventValue");        //CustomEvent
            _attribDefs.GetCustomAttributeForError("ErrorEventAttrib").TrySetValue(attribValues, "ErrorEventValue");                //Error Event and Trace
            _attribDefs.GetCustomAttributeForSpan("SpanEventAttrib").TrySetValue(attribValues, "SpanEventValue");                   //Span only
            _attribDefs.GetCustomAttributeForTransaction("TrxEventAttrib").TrySetValue(attribValues, "TrxEventValue");              //All Destiantions

            var errorCustomParameters = new ReadOnlyDictionary <string, object>(new Dictionary <string, object>()
            {
                { "ErrorCustomAttrib", "ErrorCustomValue" }
            });
            var errorNoticedAt = DateTime.Now;
            var errorMsg       = "ErrorMessage";
            var errorType      = "ErrorType";
            var stackTrace     = "StackTrace";

            var errorData = new ErrorData(errorMsg, errorType, stackTrace, errorNoticedAt, errorCustomParameters, false);

            // ACT
            var errorTrace = _errorTraceMaker.GetErrorTrace(attribValues, errorData);

            //CAPTURE
            var userAttribs = errorTrace.Attributes.UserAttributes;

            //ASSERT
            NrAssert.Multiple
            (
                () => Assert.AreEqual(errorType, errorTrace.ExceptionClassName),
                () => Assert.AreEqual(errorMsg, errorTrace.Message),
                () => Assert.AreEqual(errorNoticedAt, errorTrace.TimeStamp),

                () => Assert.AreEqual(2, userAttribs.Count),
                () => Assert.AreEqual("TrxEventValue", userAttribs["TrxEventAttrib"]),
                () => Assert.AreEqual("ErrorEventValue", userAttribs["ErrorEventAttrib"])
            );
        }