public TransactionTraceWireModel GetTransactionTrace(ImmutableTransaction immutableTransaction, IEnumerable <ImmutableSegmentTreeNode> segmentTrees, TransactionMetricName transactionMetricName, IAttributeValueCollection attribValues) { segmentTrees = segmentTrees.ToList(); if (!segmentTrees.Any()) { throw new ArgumentException("There must be at least one segment to create a trace"); } var filteredAttributes = new AttributeValueCollection(attribValues, AttributeDestinations.TransactionTrace); // See spec for details on these fields: https://source.datanerd.us/agents/agent-specs/blob/master/Transaction-Trace-LEGACY.md var startTime = immutableTransaction.StartTime; var duration = immutableTransaction.ResponseTimeOrDuration; string uri = null; if (_attribDefs.RequestUri.IsAvailableForAny(AttributeDestinations.TransactionTrace)) { uri = immutableTransaction.TransactionMetadata.Uri?.TrimAfterAChar(StringSeparators.QuestionMarkChar) ?? "/Unknown"; } var guid = immutableTransaction.Guid; var xraySessionId = null as ulong?; // The .NET agent does not support xray sessions var isSynthetics = immutableTransaction.TransactionMetadata.IsSynthetics; var syntheticsResourceId = immutableTransaction.TransactionMetadata.SyntheticsResourceId; var rootSegment = GetRootSegment(segmentTrees, immutableTransaction); var traceData = new TransactionTraceData(startTime, rootSegment, attribValues); var trace = new TransactionTraceWireModel(startTime, duration, transactionMetricName.PrefixedName, uri, traceData, guid, xraySessionId, syntheticsResourceId, isSynthetics); return(trace); }
private static string SerializeTransactionTraceData(TransactionTraceWireModel transactionTraceWireModel) { try { return(JsonConvert.SerializeObject(transactionTraceWireModel.TransactionTraceData)); } catch (Exception exception) { return("Caught exception when trying to serialize TransactionTraceData: " + exception); } }
public static IDictionary <string, object> GetAttributes(this TransactionTraceWireModel transactionTrace, AttributeClassification attributeClassification) { switch (attributeClassification) { case AttributeClassification.Intrinsics: return(transactionTrace.TransactionTraceData.Attributes.Intrinsics); case AttributeClassification.AgentAttributes: return(transactionTrace.TransactionTraceData.Attributes.AgentAttributes); case AttributeClassification.UserAttributes: return(transactionTrace.TransactionTraceData.Attributes.UserAttributes); default: throw new NotImplementedException(); } }
public static void SegmentsDoNotExist(IEnumerable <string> unexpectedTraceSegmentNames, TransactionTraceWireModel trace, bool areRegexNames = false) { var allSegments = trace.TransactionTraceData.RootSegment.Flatten(node => node.Children); var succeeded = true; var builder = new StringBuilder(); foreach (var unexpectedSegmentName in unexpectedTraceSegmentNames) { if (allSegments.Any( segment => areRegexNames && Regex.IsMatch(segment.Name, unexpectedSegmentName) || !areRegexNames && segment.Name == unexpectedSegmentName) ) { builder.AppendFormat("Segment named {0} was found in the transaction sample, but shouldn't be.", unexpectedSegmentName); builder.AppendLine(); succeeded = false; } } Assert.True(succeeded, builder.ToString()); }
public static void DoesNotHaveAttributes(IEnumerable <string> unexpectedAttributes, AttributeClassification attributeClassification, TransactionTraceWireModel trace) { var errorMessageBuilder = new StringBuilder(); var actualAttributes = trace.GetAttributes(attributeClassification); var allAttributesNotFound = ExpectedAttribute.CheckIfAllAttributesNotFound(actualAttributes, unexpectedAttributes, errorMessageBuilder); Assert.True(allAttributesNotFound, errorMessageBuilder.ToString()); }
public static void HasAttributes(IEnumerable <ExpectedAttribute> expectedAttributes, AttributeClassification attributeClassification, TransactionTraceWireModel trace) { var errorMessageBuilder = new StringBuilder(); var actualAttributes = trace.GetAttributes(attributeClassification); var allAttributesMatch = ExpectedAttribute.CheckIfAllAttributesMatch(actualAttributes, expectedAttributes, errorMessageBuilder); Assert.True(allAttributesMatch, errorMessageBuilder.ToString()); }