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 SupportabilityMetric_Request_Accept_Success() { //Collect the different metric counts in a dictionary that we can use var conditionCounts = new Dictionary <CATSupportabilityCondition, int>(); Mock.Arrange(() => _catMetricCounters.Record(Arg.IsAny <CATSupportabilityCondition>())) .DoInstead <CATSupportabilityCondition>((cond) => { if (!conditionCounts.ContainsKey(cond)) { conditionCounts.Add(cond, 0); } conditionCounts[cond]++; }); var trx = _agent.CreateTransaction( isWeb: true, category: EnumNameCache <WebTransactionType> .GetName(WebTransactionType.Action), transactionDisplayName: "name", doNotTrackAsUnitOfWork: true); var requestHeaders = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>(NewRelicIdHttpHeader, _crossProcessIDEncoded), new KeyValuePair <string, string>(TransactionDataHttpHeader, _reqDataEncoded) }; _agent.CurrentTransaction.AcceptDistributedTraceHeaders(requestHeaders, HeaderFunctions.GetHeaders, TransportType.HTTP); NrAssert.Multiple ( () => TestExistenceOfConditions(conditionCounts, CATSupportabilityCondition.Request_Accept_Success), () => TestConditionValue(conditionCounts, CATSupportabilityCondition.Request_Accept_Success, 1) ); }
public IEnumerable <KeyValuePair <string, string> > TryGetOutboundRequestHeaders(IInternalTransaction transaction) { try { if (!_configurationService.Configuration.CrossApplicationTracingEnabled) { return(Enumerable.Empty <KeyValuePair <string, string> >()); } var crossProcessId = _configurationService.Configuration.CrossApplicationTracingCrossProcessId; if (crossProcessId == null) { Log.Error("Failed to get cross process id for outbound request."); _supportabilityMetrics.Record(CATSupportabilityCondition.Request_Create_Failure_XProcID); return(Enumerable.Empty <KeyValuePair <string, string> >()); } var encodedNewRelicId = GetEncodedNewRelicId(crossProcessId); var encodedTransactionData = GetEncodedTransactionData(transaction); _supportabilityMetrics.Record(CATSupportabilityCondition.Request_Create_Success); return(new Dictionary <string, string> { { NewRelicIdHttpHeader, encodedNewRelicId }, { TransactionDataHttpHeader, encodedTransactionData } }); } catch (Exception ex) { Log.Error($"Failed to get encoded CAT headers for outbound request: {ex}"); _supportabilityMetrics.Record(CATSupportabilityCondition.Request_Create_Failure); return(Enumerable.Empty <KeyValuePair <string, string> >()); } }