private void GenerateAndCollectTransactionEvent(ImmutableTransaction immutableTransaction, Func <IAttributeValueCollection> attributes)
        {
            if (!_configurationService.Configuration.TransactionEventsEnabled)
            {
                return;
            }

            if (!_configurationService.Configuration.TransactionEventsTransactionsEnabled)
            {
                return;
            }

            var transactionEvent = _transactionEventMaker.GetTransactionEvent(immutableTransaction, attributes.Invoke());

            using (_agentTimerService.StartNew("CollectTransactionEvent"))
            {
                _transactionEventAggregator.Collect(transactionEvent);
            }
        }
Example #2
0
        public void RootSpanAttribFiltering_SpanFiltersIndependentOfTransactionFilters()
        {
            _localConfig.transactionEvents.attributes.exclude = new List <string> {
                "filterOnTrx*"
            };
            _localConfig.spanEvents.attributes.exclude = new List <string> {
                "filterOnSpan*"
            };

            PublishConfig();

            var segments = new List <Segment>()
            {
                _baseDatastoreSegment.CreateSimilar(TimeSpan.FromMilliseconds(1), TimeSpan.FromMilliseconds(5), new List <KeyValuePair <string, object> >()),
            };

            var immutableTransaction = BuildTestTransaction(segments, true, false);

            var transactionMetricName = _transactionMetricNameMaker.GetTransactionMetricName(immutableTransaction.TransactionName);
            var metricStatsCollection = new TransactionMetricStatsCollection(transactionMetricName);
            var transactionAttribs    = _transactionAttribMaker.GetAttributes(immutableTransaction, transactionMetricName, TimeSpan.FromSeconds(1), immutableTransaction.Duration, metricStatsCollection);

            _attribDefs.GetCustomAttributeForTransaction("filterOnTrx").TrySetValue(transactionAttribs, "trxCustomAttribValue1");
            _attribDefs.GetCustomAttributeForTransaction("filterOnSpan").TrySetValue(transactionAttribs, "trxCustomAttribValue2");

            var trxEvent   = _transactionEventMaker.GetTransactionEvent(immutableTransaction, transactionAttribs);
            var spanEvents = _spanEventMaker.GetSpanEvents(immutableTransaction, TransactionName, transactionAttribs);

            var rootSpan = spanEvents.ToList()[0];

            var rootSpanUserAttribDic = rootSpan.GetAttributeValuesDic(AttributeClassification.UserAttributes);
            var trxUserAttribDic      = trxEvent.AttributeValues.GetAttributeValuesDic(AttributeClassification.UserAttributes);

            NrAssert.Multiple
            (
                () => Assert.IsFalse(trxUserAttribDic.ContainsKey("filterOnTrx")),
                () => Assert.IsTrue(trxUserAttribDic.ContainsKey("filterOnSpan")),

                () => Assert.IsTrue(rootSpanUserAttribDic.ContainsKey("filterOnTrx")),
                () => Assert.IsFalse(rootSpanUserAttribDic.ContainsKey("filterOnSpan"))
            );
        }