internal void TryProcessCatRequestData <T>(IInternalTransaction transaction, T carrier, Func <T, string, IEnumerable <string> > getter) { try { var referrerCrossApplicationProcessId = GetReferrerCrossApplicationProcessId(transaction, carrier, getter); if (referrerCrossApplicationProcessId == null) { return; } UpdateReferrerCrossApplicationProcessId(transaction, referrerCrossApplicationProcessId); var crossApplicationRequestData = _catHeaderHandler.TryDecodeInboundRequestHeaders(carrier, getter); if (crossApplicationRequestData == null) { return; } var contentLength = GetContentLength(carrier, getter); UpdateTransactionMetadata(transaction, crossApplicationRequestData, contentLength); _catMetricCounters.Record(CATSupportabilityCondition.Request_Accept_Success); } catch (Exception) { _catMetricCounters.Record(CATSupportabilityCondition.Request_Accept_Failure); } }
public void Test(TestCase testCase) { Mock.Arrange(() => _configuration.ApplicationNames).Returns(new[] { testCase.AppName }); // ConvertToImmutableTransaction a transaction for the test data _transaction = GetTransactionBuilderFor(_configuration, testCase); // Simulate external requests as dictated by the test data var namePriority = 10; var expectedAndActualOutboundRequestPayloads = new Dictionary <CrossApplicationRequestData, CrossApplicationRequestData>(); testCase.OutboundRequests?.ForEach(request => { var transactionName = GetTransactionNameFromString(request.OutboundTxnName); _transaction.CandidateTransactionName.TrySet(transactionName, (TransactionNamePriority)namePriority++); var outboundHeaders = _agent.CurrentTransaction.GetRequestMetadata().ToDictionary(); var actualOutboundPayload = _catHeaderHandler.TryDecodeInboundRequestHeaders(outboundHeaders, GetHeaderValue); var requestData = new CrossApplicationRequestData( (string)request.ExpectedOutboundPayload[0], (bool)request.ExpectedOutboundPayload[1], (string)request.ExpectedOutboundPayload[2], (string)request.ExpectedOutboundPayload[3] ); expectedAndActualOutboundRequestPayloads.Add(requestData, actualOutboundPayload); _transaction.TransactionMetadata.MarkHasCatResponseHeaders(); List <string> GetHeaderValue(Dictionary <string, string> headers, string key) { var headerValues = new List <string>(); foreach (var item in headers) { if (item.Key.Equals(key, StringComparison.OrdinalIgnoreCase)) { headerValues.Add(item.Value); } } return(headerValues); } }); // Simulate the transaction ending (this logic is normally performed by Agent.EndTransaction) _transaction.CandidateTransactionName.TrySet(GetTransactionNameFromString(testCase.TransactionName), (TransactionNamePriority)9999); var currentTransactionName = _transaction.CandidateTransactionName.CurrentTransactionName; var currentTransactionMetricName = _transactionMetricNameMaker.GetTransactionMetricName(currentTransactionName); var pathHash = _pathHashMaker.CalculatePathHash(currentTransactionMetricName.PrefixedName, _transaction.TransactionMetadata.CrossApplicationReferrerPathHash); _transaction.TransactionMetadata.SetCrossApplicationPathHash(pathHash); var transaction = _transaction.ConvertToImmutableTransaction(); var totalTime = transaction.Duration; // Get the attributes that would be created for this transaction var transactionMetricName = _transactionMetricNameMaker.GetTransactionMetricName(transaction.TransactionName); var txStats = new TransactionMetricStatsCollection(transactionMetricName); var attributes = _transactionAttributeMaker.GetAttributes(transaction, transactionMetricName, null, totalTime, txStats); var intrinsics = attributes.GetAttributeValuesDic(AttributeClassification.Intrinsics); // Run assertions testCase.ExpectedIntrinsicFields.ForEach(kvp => { Assert.True(intrinsics.ContainsKey(kvp.Key), $"Expected intrinsic attribute '{kvp.Key}' was not found"); Assert.AreEqual(kvp.Value, intrinsics[kvp.Key], $"Attribute '{kvp.Key}': expected value '{kvp.Value}' but found '{intrinsics[kvp.Key]}'"); }); testCase.NonExpectedIntrinsicFields.ForEach(field => { Assert.False(intrinsics.ContainsKey(field), $"Found unexpected intrinsic attribute '{field}'"); }); if (testCase.OutboundRequests != null) { expectedAndActualOutboundRequestPayloads.ForEach(kvp => { var expected = kvp.Key; var actual = kvp.Value; Assert.NotNull(actual, "Outbound request did not have any CAT headers"); Assert.AreEqual(expected.TransactionGuid, actual.TransactionGuid, $"Expected outbound.TransactionGuid to be '{expected.TransactionGuid}' but found '{actual.TransactionGuid}'"); Assert.AreEqual(expected.PathHash, actual.PathHash, $"Expected outbound.PathHash to be '{expected.TransactionGuid}' but found '{actual.TransactionGuid}'"); Assert.AreEqual(expected.TripId, actual.TripId, $"Expected outbound.TripId to be '{expected.TransactionGuid}' but found '{actual.TransactionGuid}'"); Assert.AreEqual(expected.Unused, actual.Unused, $"Expected outbound.Unused to be '{expected.Unused}' but found '{actual.Unused}'"); }); } }