Example #1
0
        private static List <TelemetryItem> DoTheMapping(List <ITelemetry> sentTelemetry)
        {
            byte[] serialized = JsonSerializer.Serialize(sentTelemetry, false);
            var    items      = AppInsightsDeserializer.Deserialize(serialized, false).ToList();
            var    mapped     = AppInsightsTelemetryMapper.Map(items).ToList();

            return(mapped);
        }
Example #2
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 = AppInsightsTelemetryMapper.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 #3
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));
        }
Example #4
0
        public void CheckListOfItems()
        {
            List <ITelemetry> sentTelemetry   = new List <ITelemetry>();
            TelemetryModule   telemetryModule = Helpers.GetTelemetryModule(sentTelemetry, this.testTelemetryKey);

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

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


            var items  = AppInsightsDeserializer.Deserialize(serialized, true).ToList();
            var mapped = AppInsightsTelemetryMapper.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]);
                    }
                }
            }
        }