public bool Send(TraceMetric metric)
        {
            var ns = _tcpClient.GetStream();

            using (var cod = new CodedOutputStream(ns))
            {
                metric.WriteTo(cod);
            }

            return(true);
        }
示例#2
0
        public bool Send(TraceMetric metric)
        {
            var ms = new MemoryStream();

            using (var cod = new CodedOutputStream(ms))
            {
                metric.WriteTo(cod);
                ms.Flush();
            }

            var ar = ms.ToArray();

            _socket.SendTo(ar, 0, ar.Length, SocketFlags.None, _endPoint);

            return(true);
        }
        public void Histogram(Span span)
        {
            var metric = new TraceMetric();

            metric.Type         = span.OperationName;
            metric.Value        = span.Duration.TotalMilliseconds;
            metric.TraceId      = span.Context.TraceId;
            metric.SpanId       = span.Context.SpanId;
            metric.ParentSpanId = span.Context.ParentSpanId;
            metric.Service      = _serviceConfiguration.Name;
            metric.StartDate    = span.StartTimestampUtc.ToUniversalTime().Subtract(new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
            metric.FinishDate   = span.FinishTimestampUtc?.ToUniversalTime().Subtract(new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds ?? 0;

            metric.Tags.AddRange(span.Context.GetBaggageItems().Select(item => new TraceMetric.Types.Tag {
                Name = item.Key.EscapeTagName(), Value = item.Value
            }));
            metric.Tags.Add(span.GetTags().Select(item => new TraceMetric.Types.Tag {
                Name = item.Key.EscapeTagName(), Value = item.Value?.ToString()
            }));

            _underlyingMetricSender.Send(metric);
        }
示例#4
0
        public bool Send(TraceMetric metric)
        {
            if (!File.Exists(_uds))
            {
                _logger.LogError("Metric proxy socket not found");
                return(false);
            }

            using (var socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified))
            {
                try
                {
                    socket.Connect(new UnixDomainSocketEndPoint(_uds));
                }
                catch (Exception e)
                {
                    _logger.LogError(e, "Cannot connect to a metric proxy");
                    return(false);
                }

                var ns = new NetworkStream(socket);
                using (var cod = new CodedOutputStream(ns))
                {
                    try
                    {
                        metric.WriteTo(cod);
                    }
                    catch (Exception e)
                    {
                        _logger.LogError(e, "Cannot send to a metric proxy");
                        return(false);
                    }
                }

                return(true);
            }
        }