public void AddRange(IAttributeValueCollection fromCollection)
 {
     foreach (var classification in _allClassifications)
     {
         AddRange(fromCollection.GetAttributeValues(classification));
     }
 }
Exemple #2
0
        /// <summary>
        /// Creates a single root span, much like we do for Transaction Traces, since DT requires that there be only one parent-less span per txn (or at least the UI/Backend is expecting that).
        /// </summary>
        private SpanAttributeValueCollection GenerateRootSpan(string rootSpanId, ImmutableTransaction immutableTransaction, string transactionName, IAttributeValueCollection transactionAttribValues)
        {
            var spanAttributes = new SpanAttributeValueCollection();

            spanAttributes.AddRange(transactionAttribValues.GetAttributeValues(AttributeClassification.AgentAttributes));

            _attribDefs.TransactionNameForSpan.TrySetValue(spanAttributes, transactionName);


            spanAttributes.Priority = immutableTransaction.Priority;

            spanAttributes.AddRange(immutableTransaction.CommonSpanAttributes);

            if (immutableTransaction.TracingState != null)
            {
                _attribDefs.ParentId.TrySetValue(spanAttributes, immutableTransaction.TracingState.ParentId ?? immutableTransaction.TracingState.Guid);
                _attribDefs.TrustedParentId.TrySetValue(spanAttributes, immutableTransaction.TracingState.Guid);
                _attribDefs.TracingVendors.TrySetValue(spanAttributes, immutableTransaction.TracingState.VendorStateEntries ?? null);
            }

            if (_configurationService.Configuration.ErrorCollectorEnabled && immutableTransaction.TransactionMetadata.ReadOnlyTransactionErrorState.HasError)
            {
                _attribDefs.SpanErrorClass.TrySetValue(spanAttributes, immutableTransaction.TransactionMetadata.ReadOnlyTransactionErrorState.ErrorData.ErrorTypeName);
                _attribDefs.SpanErrorMessage.TrySetValue(spanAttributes, immutableTransaction.TransactionMetadata.ReadOnlyTransactionErrorState.ErrorData.ErrorMessage);
                if (immutableTransaction.TransactionMetadata.ReadOnlyTransactionErrorState.ErrorData.IsExpected)
                {
                    _attribDefs.SpanIsErrorExpected.TrySetValue(spanAttributes, true);
                }
            }

            _attribDefs.Guid.TrySetValue(spanAttributes, rootSpanId);
            _attribDefs.Timestamp.TrySetValue(spanAttributes, immutableTransaction.StartTime);
            _attribDefs.Duration.TrySetValue(spanAttributes, immutableTransaction.Duration);

            _attribDefs.NameForSpan.TrySetValue(spanAttributes, transactionName);

            _attribDefs.SpanCategory.TrySetValue(spanAttributes, SpanCategory.Generic);
            _attribDefs.NrEntryPoint.TrySetValue(spanAttributes, true);

            spanAttributes.AddRange(transactionAttribValues.GetAttributeValues(AttributeClassification.UserAttributes));

            spanAttributes.MakeImmutable();

            return(spanAttributes);
        }
Exemple #3
0
        public static Dictionary <string, object> ToDictionary(this IAttributeValueCollection attribValueCollection, params AttributeClassification[] classifications)
        {
            if (classifications == null || classifications.Length == 0)
            {
                classifications = new[] { AttributeClassification.Intrinsics, AttributeClassification.AgentAttributes, AttributeClassification.UserAttributes };
            }

            var attribValues = new List <IAttributeValue>();

            foreach (var classification in classifications)
            {
                attribValues.AddRange(attribValueCollection.GetAttributeValues(classification));
            }

            return(attribValues.ToDictionary(x => x.AttributeDefinition.Name, x => x.Value));
        }
        public static Dictionary <string, object> ToDictionary(this IAttributeValueCollection attribValueCollection, params AttributeClassification[] classifications)
        {
            if (classifications == null || classifications.Length == 0)
            {
                classifications = new[] { AttributeClassification.Intrinsics, AttributeClassification.AgentAttributes, AttributeClassification.UserAttributes };
            }

            var attribValues = new Dictionary <string, object>();

            foreach (var classification in classifications)
            {
                foreach (var attribVal in attribValueCollection.GetAttributeValues(classification))
                {
                    attribValues[attribVal.AttributeDefinition.Name] = attribVal.Value;
                }
            }

            return(attribValues);
        }
        public void AttributeClassificationIsCorrect()
        {
            _attribDefs.OriginalUrl.TrySetValue(_attribValues, "banana");
            _attribDefs.GetCustomAttributeForTransaction("pie").TrySetValue(_attribValues, "cake");

            var agentAttribsDic = _attribValues.GetAttributeValuesDic(AttributeClassification.AgentAttributes);
            var userAttribsDic  = _attribValues.GetAttributeValuesDic(AttributeClassification.UserAttributes);
            var allAttribs      = _attribValues.GetAttributeValues(AttributeClassification.Intrinsics)
                                  .Union(_attribValues.GetAttributeValues(AttributeClassification.AgentAttributes))
                                  .Union(_attribValues.GetAttributeValues(AttributeClassification.UserAttributes))
                                  .ToList();

            NrAssert.Multiple
            (
                () => Assert.AreEqual(2, allAttribs.Count),
                () => Assert.AreEqual(1, agentAttribsDic.Count()),
                () => Assert.AreEqual("banana", agentAttribsDic["original_url"]),
                () => Assert.AreEqual(1, userAttribsDic.Count()),
                () => Assert.AreEqual("cake", userAttribsDic["pie"])
            );
        }