Exemple #1
0
        public ICarrier Decode(string content)
        {
            NullableCarrier Defer()
            {
                return(NullableCarrier.Instance);
            }

            if (string.IsNullOrEmpty(content))
            {
                return(Defer());
            }

            var parts = content.Split('|');

            if (parts.Length < 8)
            {
                return(Defer());
            }

            if (!_uniqueIdParser.TryParse(parts[0], out var segmentId))
            {
                return(Defer());
            }

            if (!int.TryParse(parts[1], out var parentSpanId))
            {
                return(Defer());
            }

            if (!int.TryParse(parts[2], out var parentServiceInstanceId))
            {
                return(Defer());
            }

            if (!int.TryParse(parts[3], out var entryServiceInstanceId))
            {
                return(Defer());
            }

            if (!_uniqueIdParser.TryParse(parts[7], out var traceId))
            {
                return(Defer());
            }

            return(new Carrier(traceId, segmentId, parentSpanId, parentServiceInstanceId,
                               entryServiceInstanceId)
            {
                NetworkAddress = StringOrIntValueHelpers.ParseStringOrIntValue(parts[4]),
                EntryEndpoint = StringOrIntValueHelpers.ParseStringOrIntValue(parts[5]),
                ParentEndpoint = StringOrIntValueHelpers.ParseStringOrIntValue(parts[6])
            });
        }
Exemple #2
0
        public ICarrier Decode(string content)
        {
            NullableCarrier Defer()
            {
                return(NullableCarrier.Instance);
            }

            if (string.IsNullOrEmpty(content))
            {
                return(Defer());
            }

            var parts = content.Split('-');

            if (parts.Length < 7)
            {
                return(Defer());
            }

            if (!int.TryParse(parts[0], out var sampled))
            {
                return(Defer());
            }

            if (!_uniqueIdParser.TryParse(_base64Formatter.Decode(parts[1]), out var traceId))
            {
                return(Defer());
            }

            if (!_uniqueIdParser.TryParse(_base64Formatter.Decode(parts[2]), out var segmentId))
            {
                return(Defer());
            }

            if (!int.TryParse(parts[3], out var parentSpanId))
            {
                return(Defer());
            }

            if (!int.TryParse(parts[4], out var parentServiceInstanceId))
            {
                return(Defer());
            }

            if (!int.TryParse(parts[5], out var entryServiceInstanceId))
            {
                return(Defer());
            }

            var carrier = new Carrier(traceId, segmentId, parentSpanId, parentServiceInstanceId,
                                      entryServiceInstanceId)
            {
                NetworkAddress = StringOrIntValueHelpers.ParseStringOrIntValue(_base64Formatter.Decode(parts[6])),
                Sampled        = sampled != 0
            };

            if (parts.Length >= 9)
            {
                carrier.ParentEndpoint =
                    StringOrIntValueHelpers.ParseStringOrIntValue(_base64Formatter.Decode(parts[7]));
                carrier.EntryEndpoint =
                    StringOrIntValueHelpers.ParseStringOrIntValue(_base64Formatter.Decode(parts[8]));
            }

            return(carrier);
        }