public CrossApplicationResponseData TryDecodeInboundResponseHeaders(IDictionary <string, string> headers)
        {
            if (!_configurationService.Configuration.CrossApplicationTracingEnabled)
            {
                return(null);
            }

            var responseHeader = headers.GetValueOrDefault(AppDataHttpHeader);

            if (responseHeader == null)
            {
                return(null);
            }

            //It is possible that multiple instrumentations, on the service side, try to add New Relic header
            //to the response on the same transaction. When that happens, the response received by the client
            //has the New Relic header contains multiple header data separated by commas. The agent will only
            //decode the first header data in this case.
            var separatorIndex = responseHeader.IndexOf(",");

            if (separatorIndex > 0)
            {
                _supportabilityMetrics.Record(CATSupportabilityCondition.Response_Accept_MultipleResponses);
                responseHeader = responseHeader.Substring(0, separatorIndex);
            }

            try
            {
                var result = HeaderEncoder.TryDecodeAndDeserialize <CrossApplicationResponseData>(responseHeader, _configurationService.Configuration.EncodingKey);

                if (result == null)
                {
                    _supportabilityMetrics.Record(CATSupportabilityCondition.Response_Accept_Failure);
                }
                else
                {
                    _supportabilityMetrics.Record(CATSupportabilityCondition.Response_Accept_Success);
                }

                return(result);
            }
            catch (Exception ex)
            {
                _supportabilityMetrics.Record(CATSupportabilityCondition.Response_Accept_Failure);

                if (ex is Newtonsoft.Json.JsonSerializationException)
                {
                    return(null);
                }

                throw;
            }
        }
        public CrossApplicationRequestData TryDecodeInboundRequestHeaders <T>(T carrier, Func <T, string, IEnumerable <string> > getter)
        {
            if (!_configurationService.Configuration.CrossApplicationTracingEnabled)
            {
                return(null);
            }

            var encodedTransactionDataHttpHeader = getter(carrier, TransactionDataHttpHeader).FirstOrDefault();

            if (encodedTransactionDataHttpHeader == null)
            {
                return(null);
            }

            var data = HeaderEncoder.TryDecodeAndDeserialize <CrossApplicationRequestData>(encodedTransactionDataHttpHeader, _configurationService.Configuration.EncodingKey);

            if (data == null)
            {
                _supportabilityMetrics.Record(CATSupportabilityCondition.Request_Accept_Failure_Decode);
            }

            return(data);
        }