Exemplo n.º 1
0
        public byte[] WriteTelemetry(ITelemetryEvent telemetryEvent, byte[] encryptionKey = null)
        {
            var t = (TelemetryEvent)telemetryEvent;

            if (t == null)
            {
                throw new SerializationException("Unknown telemetry event type");
            }

            byte[] payload;
            switch (t.Message)
            {
            case UavPositionReport r:
                payload = UavPositionReportSerializer.WriteReport(r);
                break;

            default:
                throw new SerializationException($"Unknown message type: {t.MessageType}");
            }

            var wrapper = new TelemetryWrapper(AutpMessageTypes.UavPosition, payload);

            byte[] wrapperBytes = TelemetryWrapperSerializer.WriteWrapper(wrapper);


            wrapperBytes = encryptionKey != null
                ? EncryptBytes(encryptionKey, t.SequenceNumber, wrapperBytes)
                : EncryptBytes(t.TelemetryId, t.SequenceNumber, wrapperBytes);

            var datagram = new UdpTelemetryDatagram(t.TelemetryId, t.SequenceNumber, wrapperBytes, true);

            return(TelemetryDatagramSerializer.WriteDatagram(datagram));
        }
 public static void LogInfo(ITelemetryEvent tEvent)
 {
     if (tEvent != null)
     {
         _client.TrackEvent(tEvent.GetType().Name, tEvent.ToDictionary());
     }
 }
Exemplo n.º 3
0
 public static void LogInfo(ITelemetryEvent tEvent)
 {
     if (tEvent != null)
     {
         _client.TrackEvent(tEvent.GetType().Name, tEvent.ToDictionary());
     }
 }
Exemplo n.º 4
0
        public static void Post(this ITelemetryEvent evnt, Telemetry.Client client = null)
        {
            if (client != null)
            {
                client.Post(evnt);
                return;
            }

            client = ClientApp.SharedInstance?.Telemetry;

            if (client == null)
            {
                pendingEvents.Add(evnt);
                return;
            }

            pendingEvents.CompleteAdding();

            while (pendingEvents.TryTake(out var pendingEvent))
            {
                client.Post(pendingEvent);
            }

            client.Post(evnt);
        }
Exemplo n.º 5
0
        public void SendTelemetry(ITelemetryEvent dataStructure, string portName, int portNumber, string encryptionKey)
        {
            byte[]          bytes          = _autpService.WriteTelemetry(dataStructure, Convert.FromBase64String(encryptionKey));
            IDatagramSender datagramSender = new DatagramSender(portName, portNumber);

            datagramSender.SendToServer(bytes);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Tracks the event.
 /// </summary>
 /// <typeparam name="TEvent">The type of the event.</typeparam>
 /// <param name="event">The event.</param>
 /// <param name="ttl">The TTL.</param>
 public static void TrackEvent <TEvent>(ITelemetryEvent <TEvent> @event, TimeSpan ttl) where TEvent : class, new()
 {
     LogConsumer.Trace("Tracking event of type {0}", typeof(TEvent).FullName);
     foreach (var client in Clients)
     {
         client.TrackEvent(@event, ttl);
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// Gets the event.
        /// </summary>
        /// <typeparam name="TEvent">The type of the event.</typeparam>
        /// <param name="event">The event.</param>
        /// <returns>TEvent.</returns>
        public TEvent GetEvent <TEvent>(ITelemetryEvent <TEvent> @event) where TEvent : class, new()
        {
            var valueBytes = _redis.GetDatabase(@event.Category).StringGet(@event.Name, CommandFlags.PreferReplica);

            return(!valueBytes.HasValue
                ? null
                : _redis.Serializer.Deserialize <TEvent>(valueBytes));
        }
Exemplo n.º 8
0
 /// <summary>
 /// Tracks the event.
 /// </summary>
 /// <typeparam name="TEvent">The type of the event.</typeparam>
 /// <param name="event">The event.</param>
 /// <param name="ttl">The TTL.</param>
 public void TrackEvent <TEvent>(ITelemetryEvent <TEvent> @event, TimeSpan ttl) where TEvent : class, new()
 {
     _redis.GetDatabase(@event.Category).StringSet(
         @event.Name,
         (string)@event.Event.GetSerializer(),
         ttl,
         When.Always,
         CommandFlags.FireAndForget);
 }
Exemplo n.º 9
0
        public void Post(ITelemetryEvent evnt)
        {
            if (evnt == null)
            {
                throw new ArgumentNullException(nameof(evnt));
            }

            Post(evnt.GetType().Name, evnt.GetProperties());
        }
Exemplo n.º 10
0
        public void Send(ITelemetryEvent telemetryEvent)
        {
            if (telemetryEvent == null)
            {
                throw new ArgumentNullException(nameof(telemetryEvent));
            }

            Send(new ITelemetryEvent[] { telemetryEvent });
        }
Exemplo n.º 11
0
        public void Post(ITelemetryEvent evnt)
        {
            if (httpClient == null || !enabled)
            {
                return;
            }

            PostEventAsync(evnt).Forget();
        }
Exemplo n.º 12
0
 protected TelemetryScopeBase(OperationEvent operationEvent, TelemetryIdentifier telemetryIdentifier, ITelemetryRecorder telemetryRecorder)
 {
     //IL_0008: Unknown result type (might be due to invalid IL or missing references)
     result            = (TelemetryResult)0;
     TelemetryEvent    = (telemetryIdentifier ?? throw new ArgumentNullException("telemetryIdentifier"));
     TelemetryRecorder = (telemetryRecorder ?? throw new ArgumentNullException("telemetryRecorder"));
     endEvent          = new VSTelemetryEvent(operationEvent);
     rootScope         = this;
 }
        private SeverityLevel GetSeverityLevel(ITelemetryEvent telemetryEvent)
        {
            if (telemetryEvent == null)
            {
                return(SeverityLevel.Information);
            }

            TelemetryEvent.Levels level;

            if (telemetryEvent is TelemetryEvent)
            {
                level = (telemetryEvent as TelemetryEvent).LevelValue;
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(telemetryEvent.Level))
                {
                    Enum.TryParse(telemetryEvent.Level, out level);
                }
                else
                {
                    level = TelemetryEvent.Levels.NotSpecified;
                }
            }

            SeverityLevel result;

            switch (level)
            {
            case TelemetryEvent.Levels.Critical:
                result = SeverityLevel.Critical;
                break;

            case TelemetryEvent.Levels.Debug:
                result = SeverityLevel.Verbose;
                break;

            case TelemetryEvent.Levels.Error:
                result = SeverityLevel.Error;
                break;

            case TelemetryEvent.Levels.Information:
                result = SeverityLevel.Information;
                break;

            case TelemetryEvent.Levels.Warning:
                result = SeverityLevel.Warning;
                break;

            default:
                result = SeverityLevel.Information;
                break;
            }

            return(result);
        }
Exemplo n.º 14
0
            public EventObjectStreamContent(Client client, ITelemetryEvent evnt)
            {
                this.client = client
                              ?? throw new ArgumentNullException(nameof(client));

                this.evnt = evnt
                            ?? throw new ArgumentNullException(nameof(evnt));

                EnsureHeaders();
            }
Exemplo n.º 15
0
        public void Send(ITelemetryEvent telemetryEvent)
        {
            if (telemetryEvent == null)
            {
                throw new ArgumentNullException(nameof(telemetryEvent));
            }

            string eventText = telemetryEvent.ToString();

            TelemetryEvent.Levels level;

            if (telemetryEvent is TelemetryEvent)
            {
                level = (telemetryEvent as TelemetryEvent).LevelValue;
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(telemetryEvent.Level))
                {
                    Enum.TryParse(telemetryEvent.Level, out level);
                }
                else
                {
                    level = TelemetryEvent.Levels.NotSpecified;
                }
            }

            switch (level)
            {
            case TelemetryEvent.Levels.Critical:
                _logger.Fatal(eventText, telemetryEvent.Exception);
                break;

            case TelemetryEvent.Levels.Debug:
                _logger.Debug(eventText);
                break;

            case TelemetryEvent.Levels.Error:
                _logger.Error(eventText, telemetryEvent.Exception);
                break;

            case TelemetryEvent.Levels.Warning:
                _logger.Warn(eventText);
                break;

            case TelemetryEvent.Levels.Information:
            case TelemetryEvent.Levels.NotSpecified:
            default:
                _logger.Info(eventText);
                break;
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Gets the event.
        /// </summary>
        /// <typeparam name="TEvent">The type of the event.</typeparam>
        /// <param name="event">The event.</param>
        /// <returns></returns>
        public static TEvent GetEvent <TEvent>(ITelemetryEvent <TEvent> @event) where TEvent : class, new()
        {
            LogConsumer.Trace("Getting event of type {0} with key {1}", typeof(TEvent).FullName, @event.Name);
            TEvent result;

            foreach (var client in Clients)
            {
                if ((result = client.GetEvent(@event)) != null)
                {
                    return(result);
                }
            }

            return(null);
        }
Exemplo n.º 17
0
        async Task PostEventOnceAsync(ITelemetryEvent evnt)
        {
            var response = await httpClient.PostAsync(
                "logEvent",
                new EventObjectStreamContent (this, evnt));

            if (response.StatusCode == HttpStatusCode.Forbidden)
            {
                Log.Info(TAG, "Disabling telemetry at service's direction (403).");
                DisableTelemetry();
                return;
            }

            response.EnsureSuccessStatusCode();

            eventsSent++;

            Log.Verbose(TAG, $"({eventsSent}): {evnt}");
        }
Exemplo n.º 18
0
        async Task PostEventAsync(ITelemetryEvent evnt)
        {
#pragma warning disable 0168
            for (int i = 0; i < 10; i++)
            {
                try {
                    await PostEventOnceAsync(evnt);

                    return;
                } catch (JsonSerializationException e) {
                    Log.Error(TAG, e);
                    return;
                } catch (Exception e) {
#if DEBUG
                    Log.Error(TAG, $"attempt {i} failed", e);
#endif
                }

                await Task.Delay(TimeSpan.FromMilliseconds(Math.Pow(2, i) * 100));

#pragma warning restore 0168
            }
        }
        private void TrackDependency(ITelemetryEvent telemetryEvent)
        {
            DependencyTelemetry info = new DependencyTelemetry();

            info.Data = telemetryEvent.Data;

            if (telemetryEvent.Duration != null && telemetryEvent.Duration.HasValue)
            {
                info.Duration = telemetryEvent.Duration.Value;
            }

            info.Type = telemetryEvent.EventType;

            info.Id = telemetryEvent.Id;

            if (!string.IsNullOrWhiteSpace(telemetryEvent.Level))
            {
                info.Properties.Add(nameof(telemetryEvent.Level), telemetryEvent.Level);
            }

            if (!string.IsNullOrWhiteSpace(telemetryEvent.Message))
            {
                info.Properties.Add(nameof(telemetryEvent.Message), telemetryEvent.Message);
            }

            info.Metrics.AddItems(telemetryEvent.Metrics);

            info.Name = telemetryEvent.Name;

            if (!string.IsNullOrWhiteSpace(telemetryEvent.ProblemId))
            {
                info.Properties.Add(nameof(telemetryEvent.ProblemId), telemetryEvent.ProblemId);
            }

            info.Properties.AddItems(telemetryEvent.Properties);

            if (!string.IsNullOrWhiteSpace(telemetryEvent.Protocol))
            {
                info.Properties.Add(nameof(telemetryEvent.Protocol), telemetryEvent.Protocol);
            }

            if (!string.IsNullOrWhiteSpace(telemetryEvent.ResponseCode))
            {
                info.Properties.Add(nameof(telemetryEvent.ResponseCode), telemetryEvent.ResponseCode);
            }

            info.ResultCode = telemetryEvent.Result;

            info.Success = telemetryEvent.Success;

            info.Target = telemetryEvent.Target;

            if (telemetryEvent.TimeStamp != null)
            {
                info.Timestamp = telemetryEvent.TimeStamp.Value;
            }

            if (!string.IsNullOrWhiteSpace(telemetryEvent.Uri))
            {
                info.Properties.Add(nameof(telemetryEvent.Uri), telemetryEvent.Uri);
            }

            if (!string.IsNullOrWhiteSpace(telemetryEvent.UserId))
            {
                info.Context.User.Id = telemetryEvent.UserId;
            }

            if (telemetryEvent.Value != null)
            {
                info.Properties.Add(nameof(telemetryEvent.Value), telemetryEvent.Value.Value.ToString());
            }

            this.Client.TrackDependency(info);

            if (!string.IsNullOrWhiteSpace(telemetryEvent.UserId))
            {
                info.Context.User.Id = string.Empty;
            }
        }
        private void TrackView(ITelemetryEvent telemetryEvent)
        {
            PageViewTelemetry info = new PageViewTelemetry();

            if (!string.IsNullOrWhiteSpace(telemetryEvent.Data))
            {
                info.Properties.Add(nameof(telemetryEvent.Data), telemetryEvent.Data);
            }

            if (telemetryEvent.Duration != null && telemetryEvent.Duration.HasValue)
            {
                info.Properties.Add(nameof(telemetryEvent.Duration), telemetryEvent.Duration.Value.ToString());
            }

            if (!string.IsNullOrWhiteSpace(telemetryEvent.EventType))
            {
                info.Properties.Add(nameof(telemetryEvent.EventType), telemetryEvent.EventType);
            }

            if (!string.IsNullOrWhiteSpace(telemetryEvent.Id))
            {
                info.Properties.Add(nameof(telemetryEvent.Id), telemetryEvent.Id);
            }

            if (!string.IsNullOrWhiteSpace(telemetryEvent.Level))
            {
                info.Properties.Add(nameof(telemetryEvent.Level), telemetryEvent.Level);
            }

            if (!string.IsNullOrWhiteSpace(telemetryEvent.Message))
            {
                info.Properties.Add(nameof(telemetryEvent.Message), telemetryEvent.Message);
            }

            info.Metrics.AddItems(telemetryEvent.Metrics);

            info.Name = telemetryEvent.Name;

            if (!string.IsNullOrWhiteSpace(telemetryEvent.ProblemId))
            {
                info.Properties.Add(nameof(telemetryEvent.ProblemId), telemetryEvent.ProblemId);
            }

            info.Properties.AddItems(telemetryEvent.Properties);

            if (!string.IsNullOrWhiteSpace(telemetryEvent.Protocol))
            {
                info.Properties.Add(nameof(telemetryEvent.Protocol), telemetryEvent.Protocol);
            }

            if (!string.IsNullOrWhiteSpace(telemetryEvent.ResponseCode))
            {
                info.Properties.Add(nameof(telemetryEvent.ResponseCode), telemetryEvent.ResponseCode);
            }

            if (!string.IsNullOrWhiteSpace(telemetryEvent.Result))
            {
                info.Properties.Add(nameof(telemetryEvent.Result), telemetryEvent.Result);
            }

            if (telemetryEvent.Success != null)
            {
                info.Properties.Add(nameof(telemetryEvent.Success), telemetryEvent.Success.Value.ToString());
            }

            if (!string.IsNullOrWhiteSpace(telemetryEvent.Target))
            {
                info.Properties.Add(nameof(telemetryEvent.Target), telemetryEvent.Target);
            }

            if (telemetryEvent.TimeStamp != null)
            {
                info.Timestamp = telemetryEvent.TimeStamp.Value;
            }

            if (!string.IsNullOrWhiteSpace(telemetryEvent.Uri))
            {
                info.Url = new Uri(telemetryEvent.Uri);
            }

            if (!string.IsNullOrWhiteSpace(telemetryEvent.UserId))
            {
                info.Context.User.Id = telemetryEvent.UserId;
            }

            if (telemetryEvent.Value != null)
            {
                info.Properties.Add(nameof(telemetryEvent.Value), telemetryEvent.Value.Value.ToString());
            }

            this.Client.TrackPageView(info);

            if (!string.IsNullOrWhiteSpace(telemetryEvent.UserId))
            {
                info.Context.User.Id = string.Empty;
            }
        }
        public void Send(ITelemetryEvent telemetryEvent)
        {
            if (telemetryEvent == null)
            {
                throw new ArgumentNullException(nameof(telemetryEvent));
            }

            TelemetryEvent.EventTypes eventType;

            if (telemetryEvent is TelemetryEvent)
            {
                eventType = (telemetryEvent as TelemetryEvent).EventTypeValue;
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(telemetryEvent.EventType))
                {
                    Enum.TryParse(telemetryEvent.EventType, out eventType);
                }
                else
                {
                    eventType = TelemetryEvent.EventTypes.NotSpecified;
                }
            }

            switch (eventType)
            {
            case TelemetryEvent.EventTypes.Dependency:
                TrackDependency(telemetryEvent);
                break;

            case TelemetryEvent.EventTypes.Event:
            case TelemetryEvent.EventTypes.NotSpecified:
                TrackEvent(telemetryEvent);
                break;

            case TelemetryEvent.EventTypes.Exception:
                TrackException(telemetryEvent);
                break;

            case TelemetryEvent.EventTypes.Metric:
                TrackMetric(telemetryEvent);
                break;

            case TelemetryEvent.EventTypes.Request:
                TrackRequest(telemetryEvent);
                break;

            case TelemetryEvent.EventTypes.Trace:
                TrackTrace(telemetryEvent);
                break;

            case TelemetryEvent.EventTypes.View:
                TrackView(telemetryEvent);
                break;

            default:
                TrackEvent(telemetryEvent);
                break;
            }
        }
 public static IDictionary <string, string> ToDictionary(this ITelemetryEvent tEvent)
 {
     return(tEvent.GetType().GetProperties().Where(p => p.CanRead && p.PropertyType == typeof(string)).ToDictionary(k => k.Name, v => (string)v.GetValue(tEvent)));
 }