private static void SerializeSessionStateTelemetry(SessionStateTelemetry sessionStateTelemetry, JsonWriter jsonWriter) { jsonWriter.WriteStartObject(); sessionStateTelemetry.WriteEnvelopeProperties(jsonWriter); sessionStateTelemetry.WriteTelemetryName(jsonWriter, SessionStateTelemetry.TelemetryName); jsonWriter.WritePropertyName("data"); { jsonWriter.WriteStartObject(); jsonWriter.WriteProperty("baseType", typeof(SessionStateData).Name); jsonWriter.WritePropertyName("baseData"); { jsonWriter.WriteStartObject(); jsonWriter.WriteProperty("ver", 2); jsonWriter.WriteProperty("state", sessionStateTelemetry.State.ToString()); jsonWriter.WriteEndObject(); } jsonWriter.WriteEndObject(); } jsonWriter.WriteEndObject(); }
internal void WriteTelemetry(ITelemetry telemetryItem) { if (telemetryItem == null) { CoreEventSource.Log.LogVerbose("telemetryItem param is null in EventSourceWriter.WriteTelemetry()"); } else if (eventSource.IsEnabled()) { if (telemetryItem is EventTelemetry) { EventTelemetry eventTelemetry = telemetryItem as EventTelemetry; WriteEvent("Event", eventTelemetry.Context, eventTelemetry.Data); } else if (telemetryItem is ExceptionTelemetry) { ExceptionTelemetry exceptionTelemetry = telemetryItem as ExceptionTelemetry; WriteEvent("Exception", exceptionTelemetry.Context, exceptionTelemetry.Data); } else if (telemetryItem is MetricTelemetry) { MetricTelemetry metricTelemetry = telemetryItem as MetricTelemetry; WriteEvent("Metric", metricTelemetry.Context, metricTelemetry.Data); } else if (telemetryItem is PageViewTelemetry) { PageViewTelemetry pageViewTelemetry = telemetryItem as PageViewTelemetry; WriteEvent("PageView", pageViewTelemetry.Context, pageViewTelemetry.Data); } else if (telemetryItem is RemoteDependencyTelemetry) { RemoteDependencyTelemetry remoteDependencyTelemetry = telemetryItem as RemoteDependencyTelemetry; WriteEvent("RemoteDependency", remoteDependencyTelemetry.Context, remoteDependencyTelemetry.Data); } else if (telemetryItem is RequestTelemetry) { RequestTelemetry requestTelemetry = telemetryItem as RequestTelemetry; WriteEvent("Request", requestTelemetry.Context, requestTelemetry.Data); } else if (telemetryItem is SessionStateTelemetry) { SessionStateTelemetry sessionStateTelemetry = telemetryItem as SessionStateTelemetry; sessionStateTelemetry.Data.state = (Coding4Fun.VisualStudio.ApplicationInsights.Extensibility.Implementation.External.SessionState)sessionStateTelemetry.State; WriteEvent("SessionState", sessionStateTelemetry.Context, sessionStateTelemetry.Data); } else if (telemetryItem is TraceTelemetry) { TraceTelemetry traceTelemetry = telemetryItem as TraceTelemetry; WriteEvent("Message", traceTelemetry.Context, traceTelemetry.Data); } else { string message = string.Format(CultureInfo.InvariantCulture, "Unknown telemtry type: {0}", new object[1] { telemetryItem.GetType() }); CoreEventSource.Log.LogVerbose(message); } } }
public void SendEventToValidateEndpoint() { EventTelemetry telemetry1 = new EventTelemetry(); MetricTelemetry telemetry2 = new MetricTelemetry(); DependencyTelemetry telemetry3 = new DependencyTelemetry(); ExceptionTelemetry telemetry4 = new ExceptionTelemetry(); MetricTelemetry telemetry5 = new MetricTelemetry(); PageViewTelemetry telemetry6 = new PageViewTelemetry(); PerformanceCounterTelemetry telemetry7 = new PerformanceCounterTelemetry(); RequestTelemetry telemetry8 = new RequestTelemetry(); SessionStateTelemetry telemetry9 = new SessionStateTelemetry(); TraceTelemetry telemetry10 = new TraceTelemetry(); var telemetryItems = new List <ITelemetry> { telemetry1, telemetry2, telemetry3, telemetry4, telemetry5, telemetry6, telemetry7, telemetry8, telemetry9, telemetry10 }; // ChuckNorrisTeamUnitTests resource in Prototypes5 var config = new TelemetryConfiguration { InstrumentationKey = "fafa4b10-03d3-4bb0-98f4-364f0bdf5df8" }; var telemetryClient = new TelemetryClient(config); telemetryClient.Initialize(telemetry1); telemetryClient.Initialize(telemetry2); telemetryClient.Initialize(telemetry3); telemetryClient.Initialize(telemetry4); telemetryClient.Initialize(telemetry5); telemetryClient.Initialize(telemetry6); telemetryClient.Initialize(telemetry7); telemetryClient.Initialize(telemetry8); telemetryClient.Initialize(telemetry9); telemetryClient.Initialize(telemetry10); string json = JsonSerializer.SerializeAsString(telemetryItems); HttpClient client = new HttpClient(); var result = client.PostAsync( "https://dc.services.visualstudio.com/v2/validate", new ByteArrayContent(Encoding.UTF8.GetBytes(json))).GetAwaiter().GetResult(); if (result.StatusCode != HttpStatusCode.OK) { var response = result.Content.ReadAsStringAsync().GetAwaiter().GetResult(); Trace.WriteLine(response); } Assert.Equal(HttpStatusCode.OK, result.StatusCode); }
private void Track(SessionState state, string id, DateTimeOffset timestamp) { var session = new SessionStateTelemetry(state); session.Context.Session.Id = id; session.Timestamp = timestamp; ((HockeyClient)HockeyClient.Current).Track(session); }
private static void SerializeTelemetryItem(ITelemetry telemetryItem, JsonWriter jsonWriter) { if (telemetryItem is EventTelemetry) { EventTelemetry eventTelemetry = telemetryItem as EventTelemetry; SerializeEventTelemetry(eventTelemetry, jsonWriter); } else if (telemetryItem is ExceptionTelemetry) { ExceptionTelemetry exceptionTelemetry = telemetryItem as ExceptionTelemetry; SerializeExceptionTelemetry(exceptionTelemetry, jsonWriter); } else if (telemetryItem is MetricTelemetry) { MetricTelemetry metricTelemetry = telemetryItem as MetricTelemetry; SerializeMetricTelemetry(metricTelemetry, jsonWriter); } else if (telemetryItem is PageViewTelemetry) { PageViewTelemetry pageViewTelemetry = telemetryItem as PageViewTelemetry; SerializePageViewTelemetry(pageViewTelemetry, jsonWriter); } else if (telemetryItem is DependencyTelemetry) { DependencyTelemetry remoteDependencyTelemetry = telemetryItem as DependencyTelemetry; SerializeDependencyTelemetry(remoteDependencyTelemetry, jsonWriter); } else if (telemetryItem is RequestTelemetry) { RequestTelemetry requestTelemetry = telemetryItem as RequestTelemetry; SerializeRequestTelemetry(requestTelemetry, jsonWriter); } else if (telemetryItem is SessionStateTelemetry) { SessionStateTelemetry sessionStateTelemetry = telemetryItem as SessionStateTelemetry; SerializeSessionStateTelemetry(sessionStateTelemetry, jsonWriter); } else if (telemetryItem is TraceTelemetry) { TraceTelemetry traceTelemetry = telemetryItem as TraceTelemetry; SerializeTraceTelemetry(traceTelemetry, jsonWriter); } else if (telemetryItem is PerformanceCounterTelemetry) { PerformanceCounterTelemetry performanceCounterTelemetry = telemetryItem as PerformanceCounterTelemetry; SerializePerformanceCounter(performanceCounterTelemetry, jsonWriter); } else if (telemetryItem is CrashTelemetry) { CrashTelemetry crashTelemetry = telemetryItem as CrashTelemetry; SerializeCrash(crashTelemetry, jsonWriter); } else { string msg = string.Format(CultureInfo.InvariantCulture, "Unknown telemtry type: {0}", telemetryItem.GetType()); CoreEventSource.Log.LogVerbose(msg); } }
public void InitializeSkipsHeadersThatHasIncorrectIps() { var dictionary = new Dictionary <string, string> { { "CustomHeader1", "BAD" }, { "CustomHeader2", "3.4.5.6" }, }; var module = new TestableClientIpHeaderTelemetryInitializer(dictionary); module.HeaderNames.Add("CustomHeader1"); module.HeaderNames.Add("CustomHeader2"); var telemetry = new SessionStateTelemetry(); module.Initialize(telemetry); Assert.AreEqual("3.4.5.6", telemetry.Context.Location.Ip); }
public void CanSetEnvelopeNameForSupportedTypes() { string testEnvelopeName = "Non_Standard*Envelope.Name"; var at = new AvailabilityTelemetry(); var dt = new DependencyTelemetry(); var et = new EventTelemetry(); var ext = new ExceptionTelemetry(); var mt = new MetricTelemetry(); var pvpt = new PageViewPerformanceTelemetry(); var pvt = new PageViewTelemetry(); var rt = new RequestTelemetry(); #pragma warning disable CS0618 // Type or member is obsolete var pct = new PerformanceCounterTelemetry(); var sst = new SessionStateTelemetry(); #pragma warning restore CS0618 // Type or member is obsolete Assert.IsTrue(at.TrySetEnvelopeName(testEnvelopeName)); Assert.IsTrue(dt.TrySetEnvelopeName(testEnvelopeName)); Assert.IsTrue(et.TrySetEnvelopeName(testEnvelopeName)); Assert.IsTrue(ext.TrySetEnvelopeName(testEnvelopeName)); Assert.IsTrue(mt.TrySetEnvelopeName(testEnvelopeName)); Assert.IsTrue(pvpt.TrySetEnvelopeName(testEnvelopeName)); Assert.IsTrue(pvt.TrySetEnvelopeName(testEnvelopeName)); Assert.IsTrue(rt.TrySetEnvelopeName(testEnvelopeName)); Assert.IsTrue(pct.TrySetEnvelopeName(testEnvelopeName)); Assert.IsTrue(sst.TrySetEnvelopeName(testEnvelopeName)); Assert.AreEqual(testEnvelopeName, at.GetEnvelopeName()); Assert.AreEqual(testEnvelopeName, dt.GetEnvelopeName()); Assert.AreEqual(testEnvelopeName, et.GetEnvelopeName()); Assert.AreEqual(testEnvelopeName, ext.GetEnvelopeName()); Assert.AreEqual(testEnvelopeName, mt.GetEnvelopeName()); Assert.AreEqual(testEnvelopeName, pvpt.GetEnvelopeName()); Assert.AreEqual(testEnvelopeName, pvt.GetEnvelopeName()); Assert.AreEqual(testEnvelopeName, rt.GetEnvelopeName()); Assert.AreEqual(testEnvelopeName, pct.Data.GetEnvelopeName()); Assert.AreEqual(testEnvelopeName, sst.Data.GetEnvelopeName()); }
private static void SerializeTelemetryItem(ITelemetry telemetryItem, JsonSerializationWriter jsonSerializationWriter) { jsonSerializationWriter.WriteStartObject(); if (telemetryItem is EventTelemetry) { EventTelemetry eventTelemetry = telemetryItem as EventTelemetry; Utils.CopyDictionary(telemetryItem.Context.GlobalProperties, eventTelemetry.Data.properties); SerializeHelper(telemetryItem, jsonSerializationWriter, eventTelemetry.BaseType, EventTelemetry.TelemetryName); } else if (telemetryItem is ExceptionTelemetry) { ExceptionTelemetry exTelemetry = telemetryItem as ExceptionTelemetry; Utils.CopyDictionary(telemetryItem.Context.GlobalProperties, exTelemetry.Data.Data.properties); SerializeHelper(telemetryItem, jsonSerializationWriter, exTelemetry.BaseType, ExceptionTelemetry.TelemetryName); } else if (telemetryItem is MetricTelemetry) { MetricTelemetry mTelemetry = telemetryItem as MetricTelemetry; Utils.CopyDictionary(telemetryItem.Context.GlobalProperties, mTelemetry.Data.properties); SerializeHelper(telemetryItem, jsonSerializationWriter, mTelemetry.BaseType, MetricTelemetry.TelemetryName); } else if (telemetryItem is PageViewTelemetry) { PageViewTelemetry pvTelemetry = telemetryItem as PageViewTelemetry; Utils.CopyDictionary(telemetryItem.Context.GlobalProperties, pvTelemetry.Data.properties); SerializeHelper(telemetryItem, jsonSerializationWriter, pvTelemetry.BaseType, PageViewTelemetry.TelemetryName); } else if (telemetryItem is PageViewPerformanceTelemetry) { PageViewPerformanceTelemetry pvptelemetry = telemetryItem as PageViewPerformanceTelemetry; Utils.CopyDictionary(telemetryItem.Context.GlobalProperties, pvptelemetry.Data.properties); SerializeHelper(telemetryItem, jsonSerializationWriter, PageViewPerformanceTelemetry.BaseType, PageViewPerformanceTelemetry.TelemetryName); } else if (telemetryItem is DependencyTelemetry) { DependencyTelemetry depTelemetry = telemetryItem as DependencyTelemetry; Utils.CopyDictionary(telemetryItem.Context.GlobalProperties, depTelemetry.InternalData.properties); SerializeHelper(telemetryItem, jsonSerializationWriter, depTelemetry.BaseType, DependencyTelemetry.TelemetryName); } else if (telemetryItem is RequestTelemetry) { RequestTelemetry reqTelemetry = telemetryItem as RequestTelemetry; Utils.CopyDictionary(telemetryItem.Context.GlobalProperties, reqTelemetry.Data.properties); SerializeHelper(telemetryItem, jsonSerializationWriter, reqTelemetry.BaseType, RequestTelemetry.TelemetryName); } #pragma warning disable 618 else if (telemetryItem is PerformanceCounterTelemetry) { PerformanceCounterTelemetry pcTelemetry = telemetryItem as PerformanceCounterTelemetry; Utils.CopyDictionary(telemetryItem.Context.GlobalProperties, pcTelemetry.Properties); SerializeHelper(telemetryItem, jsonSerializationWriter, pcTelemetry.Data.BaseType, MetricTelemetry.TelemetryName); } else if (telemetryItem is SessionStateTelemetry) { SessionStateTelemetry ssTelemetry = telemetryItem as SessionStateTelemetry; SerializeHelper(telemetryItem, jsonSerializationWriter, ssTelemetry.Data.BaseType, EventTelemetry.TelemetryName); } #pragma warning restore 618 else if (telemetryItem is TraceTelemetry) { TraceTelemetry traceTelemetry = telemetryItem as TraceTelemetry; Utils.CopyDictionary(telemetryItem.Context.GlobalProperties, traceTelemetry.Data.properties); SerializeHelper(telemetryItem, jsonSerializationWriter, traceTelemetry.BaseType, TraceTelemetry.TelemetryName); } else if (telemetryItem is AvailabilityTelemetry) { AvailabilityTelemetry availabilityTelemetry = telemetryItem as AvailabilityTelemetry; Utils.CopyDictionary(telemetryItem.Context.GlobalProperties, availabilityTelemetry.Data.properties); SerializeHelper(telemetryItem, jsonSerializationWriter, availabilityTelemetry.BaseType, AvailabilityTelemetry.TelemetryName); } else { string msg = string.Format(CultureInfo.InvariantCulture, "Unknown telemetry type: {0}", telemetryItem.GetType()); CoreEventSource.Log.LogVerbose(msg); } jsonSerializationWriter.WriteEndObject(); }
public void SendEventToValidateEndpoint() { string unicodeString = "русский\\#/\x0000\x0001\x0002\x0003\x0004\x0005\x0006\x0007\x0008\x009Farabicشلاؤيثبلاهتنمةىخحضقسفعشلاؤيصثبل c\n\r\t"; EventTelemetry telemetry1 = new EventTelemetry(unicodeString); MetricTelemetry telemetry2 = new MetricTelemetry("name", 100); DependencyTelemetry telemetry3 = new DependencyTelemetry("name", "commandName", DateTimeOffset.UtcNow, TimeSpan.FromHours(3), true); ExceptionTelemetry telemetry4 = new ExceptionTelemetry(new ArgumentException("Test")); MetricTelemetry telemetry5 = new MetricTelemetry("name", 100); PageViewTelemetry telemetry6 = new PageViewTelemetry("name"); #pragma warning disable 618 PerformanceCounterTelemetry telemetry7 = new PerformanceCounterTelemetry("category", "name", "instance", 100); #pragma warning restore 618 RequestTelemetry telemetry8 = new RequestTelemetry("name", DateTimeOffset.UtcNow, TimeSpan.FromHours(2), "200", true); #pragma warning disable 618 SessionStateTelemetry telemetry9 = new SessionStateTelemetry(SessionState.Start); #pragma warning restore 618 TraceTelemetry telemetry10 = new TraceTelemetry("text"); AvailabilityTelemetry telemetry11 = new AvailabilityTelemetry("name", DateTimeOffset.UtcNow, TimeSpan.FromHours(10), "location", true, "message"); var telemetryItems = new List <ITelemetry> { telemetry1, telemetry2, telemetry3, telemetry4, telemetry5, telemetry6, telemetry7, telemetry8, telemetry9, telemetry10, telemetry11 }; // ChuckNorrisTeamUnitTests resource in Prototypes5 var config = new TelemetryConfiguration("fafa4b10-03d3-4bb0-98f4-364f0bdf5df8"); var telemetryClient = new TelemetryClient(config); telemetryClient.Context.Properties.Add(unicodeString, unicodeString); telemetryClient.Initialize(telemetry1); telemetryClient.Initialize(telemetry2); telemetryClient.Initialize(telemetry3); telemetryClient.Initialize(telemetry4); telemetryClient.Initialize(telemetry5); telemetryClient.Initialize(telemetry6); telemetryClient.Initialize(telemetry7); telemetryClient.Initialize(telemetry8); telemetryClient.Initialize(telemetry9); telemetryClient.Initialize(telemetry10); telemetryClient.Initialize(telemetry11); string json = JsonSerializer.SerializeAsString(telemetryItems); HttpClient client = new HttpClient(); var result = client.PostAsync( "https://dc.services.visualstudio.com/v2/validate", new ByteArrayContent(Encoding.UTF8.GetBytes(json))).GetAwaiter().GetResult(); if (result.StatusCode != HttpStatusCode.OK) { var response = result.Content.ReadAsStringAsync().GetAwaiter().GetResult(); Trace.WriteLine(response); } Assert.Equal(HttpStatusCode.OK, result.StatusCode); }