public async Task <IHttpActionResult> Post(Guid telemetryKey)
        {
            try
            {
                TelemetryRootObject program = await this.work.GetMonitoredProgram(telemetryKey).ConfigureAwait(false);

                if (program == null)
                {
                    throw new BadRequestException($"Program with telemetry key [{telemetryKey}] does not exist");
                }

                IEnumerable <AppInsightsTelemetry> appInsightsTelemetries = AppInsightsDeserializer.Deserialize(await this.Request.Content.ReadAsByteArrayAsync().ConfigureAwait(false), true);

                List <TelemetryItem> telemetryItems = TelemetryMapper.Map(appInsightsTelemetries).ToList();

                string ip = "0.0.0.0";

                await this.InsertDataInternal(telemetryItems, program, ip).ConfigureAwait(false);

                return(await Task.FromResult(this.StatusCode(HttpStatusCode.Accepted)).ConfigureAwait(false));
            }
            catch (Exception e)
            {
                this.telemetryClient.TrackException(e, new Dictionary <string, string>()
                {
                    { $"Method", Routes.Post },
                    { $"TelemetryKey", telemetryKey.ToString() }
                });
                throw;
            }
        }
Example #2
0
        private static List <TelemetryItem> DoTheMapping(List <ITelemetry> sentTelemetry)
        {
            byte[] serialized = JsonSerializer.Serialize(sentTelemetry, false);
            var    items      = AppInsightsDeserializer.Deserialize(serialized, false).ToList();
            var    mapped     = TelemetryMapper.Map(items).ToList();

            return(mapped);
        }
Example #3
0
        public void CheckListOfItems()
        {
            List <ITelemetry> sentTelemetry = new List <ITelemetry>();
            var teli = Helpers.GetCrackedTelimena(sentTelemetry, this.testTelemetryKey, "ASD", true);

            teli.Track.Event("TestEvent", new Dictionary <string, string>()
            {
                { "AKey", $"AValue" }
            });
            teli.Track.View("TestView");
            teli.Track.Log(LogLevel.Warn, "A log message");
            teli.Track.Exception(new Exception("An error that happened"));
            teli.Track.Exception(new Exception("An error that happened with note"), "A note for error");

            teli.Track.SendAllDataNow();
            byte[] serialized = JsonSerializer.Serialize(sentTelemetry, true);


            var items  = AppInsightsDeserializer.Deserialize(serialized, true).ToList();
            var mapped = TelemetryMapper.Map(items).ToList();

            for (int index = 0; index < sentTelemetry.Count; index++)
            {
                ITelemetry    appInsightsItem = sentTelemetry[index];
                TelemetryItem telimenaItem    = mapped[index];

                Assert.AreEqual(appInsightsItem.Timestamp, telimenaItem.Timestamp);
                Assert.AreEqual(appInsightsItem.Sequence, telimenaItem.Sequence);
                Assert.AreEqual(appInsightsItem.Context.User.Id, telimenaItem.UserIdentifier);
                if (telimenaItem.TelemetryItemType != TelemetryItemTypes.LogMessage && telimenaItem.TelemetryItemType != TelemetryItemTypes.Exception)
                {
                    Assert.AreEqual(appInsightsItem.GetPropertyValue <string>("Name"), telimenaItem.EntryKey);
                }
                foreach (KeyValuePair <string, string> keyValuePair in appInsightsItem.GetPropertyValue <ConcurrentDictionary <string, string> >("Properties"))
                {
                    var props = typeof(TelimenaContextPropertyKeys).GetProperties().Select(x => x.Name);
                    if (!props.Contains(keyValuePair.Key))
                    {
                        Assert.AreEqual(keyValuePair.Value, telimenaItem.Properties[keyValuePair.Key]);
                    }
                }
            }
        }
Example #4
0
        public async Task <IHttpActionResult> Post(Guid telemetryKey)
        {
            TelemetryRootObject program = await this.work.GetMonitoredProgram(telemetryKey).ConfigureAwait(false);

            if (program == null)
            {
                throw new BadRequestException($"Program with telemetry key [{telemetryKey}] does not exist");
            }

            IEnumerable <AppInsightsTelemetry> appInsightsTelemetries = AppInsightsDeserializer.Deserialize(await this.Request.Content.ReadAsByteArrayAsync().ConfigureAwait(false), true);

            IEnumerable <TelemetryItem> telemetryItems = TelemetryMapper.Map(appInsightsTelemetries);

            string ip = this.Request.GetClientIp();

            await this.InsertDataInternal(telemetryItems, program, ip).ConfigureAwait(false);

            return(await Task.FromResult(this.StatusCode(HttpStatusCode.Accepted)).ConfigureAwait(false));
        }
Example #5
0
        public async Task <IHttpActionResult> PostV2()
        {
            IEnumerable <AppInsightsTelemetry> appInsightsTelemetries = AppInsightsDeserializer.Deserialize(await this.Request.Content.ReadAsByteArrayAsync().ConfigureAwait(false), true);

            IEnumerable <TelemetryItem> telemetryItems = AppInsightsTelemetryMapper.Map(appInsightsTelemetries);
            string ip = this.Request.GetClientIp();

            //items might come with various telemetry key in one request (when there are multiple instances of telemetry client)
            IEnumerable <IGrouping <Guid, TelemetryItem> > groups = telemetryItems.GroupBy(telemetry => telemetry.TelemetryKey);

            foreach (IGrouping <Guid, TelemetryItem> grouping in groups)
            {
                TelemetryRootObject program = await this.work.GetMonitoredProgram(grouping.Key).ConfigureAwait(false);

                await this.InsertDataInternal(grouping, program, ip).ConfigureAwait(false);
            }

            return(await Task.FromResult(this.StatusCode(HttpStatusCode.Accepted)).ConfigureAwait(false));
        }
        public async Task <IHttpActionResult> PostWithVariousKeys()
        {
            try
            {
                IEnumerable <AppInsightsTelemetry> appInsightsTelemetries = AppInsightsDeserializer.Deserialize(await this.Request.Content.ReadAsByteArrayAsync().ConfigureAwait(false), true);

                List <TelemetryItem> telemetryItems = TelemetryMapper.Map(appInsightsTelemetries).ToList();
                //  string ip = this.Request.GetClientIp();
                string ip = "0.0.0.0";

                //items might come with various telemetry key in one request (when there are multiple instances of telemetry client)
                IEnumerable <IGrouping <Guid, TelemetryItem> > groups = telemetryItems.GroupBy(telemetry => telemetry.TelemetryKey);
                //todo - parallelism?
                foreach (IGrouping <Guid, TelemetryItem> grouping in groups)
                {
                    TelemetryRootObject program = await this.work.GetMonitoredProgram(grouping.Key).ConfigureAwait(false);

                    if (program != null)
                    {
                        await this.InsertDataInternal(grouping.ToList(), program, ip).ConfigureAwait(false);
                    }
                    else
                    {
                        this.telemetryClient.TrackException(new InvalidOperationException($"Program with telemetry key [{grouping.Key}] does not exist"), new Dictionary <string, string>()
                        {
                            { $"Method", Routes.PostWithVariousKeys },
                            { $"TelemetryKey", grouping.Key.ToString() },
                        });
                    }
                }

                return(await Task.FromResult(this.StatusCode(HttpStatusCode.Accepted)).ConfigureAwait(false));
            }
            catch (Exception e)
            {
                this.telemetryClient.TrackException(e, new Dictionary <string, string>()
                {
                    { $"Method", Routes.PostWithVariousKeys },
                });
                throw;
            }
        }