public void TransmissionProcessorStartsChannelSanitizationAfterDebugOutputSanitization() { var debugOutput = new StubDebugOutput { OnWriteLine = message => { // do nothing }, OnIsAttached = () => true, }; PlatformSingleton.Current = new StubPlatform { OnGetDebugOutput = () => debugOutput }; var channel = new StubTelemetryChannel { OnSend = t => new Task(() => { ((ITelemetry)t).Sanitize(); }).Start() }; var configuration = new TelemetryConfiguration { InstrumentationKey = "Test key", TelemetryChannel = channel }; var client = new TelemetryClient(configuration); var transmissionProcessor = new TransmissionProcessor(configuration); const int ItemsToGenerate = 100; Random random = new Random(); for (int i = 0; i < ItemsToGenerate; i++) { EventTelemetry telemetry = new EventTelemetry(); int len = random.Next(50); for (int j = 0; j < len; j++) { telemetry.Properties.Add(j.ToString(), j.ToString()); } transmissionProcessor.Process(telemetry); } // There were a bug that causes Sanitize call from DebugOutput tracer conflict with Sanitize call from Channel // If no exceptions here - everything fine Assert.True(true); }
public void TrackWritesTelemetryToDebugOutputIfIKeyNotEmpty() { string actualMessage = null; var debugOutput = new StubDebugOutput { OnWriteLine = message => actualMessage = message, OnIsAttached = () => true, }; PlatformSingleton.Current = new StubPlatform { OnGetDebugOutput = () => debugOutput }; var channel = new StubTelemetryChannel { DeveloperMode = true }; var configuration = new TelemetryConfiguration { TelemetryChannel = channel, InstrumentationKey = "123" }; var client = new TelemetryClient(configuration); client.Track(new StubTelemetry()); Assert.True(actualMessage.StartsWith("Application Insights Telemetry: ")); PlatformSingleton.Current = null; }
public void TrackDoesNotWriteTelemetryToDebugOutputIfNotInDeveloperMode() { string actualMessage = null; var debugOutput = new StubDebugOutput { OnWriteLine = message => actualMessage = message }; PlatformSingleton.Current = new StubPlatform { OnGetDebugOutput = () => debugOutput }; var channel = new StubTelemetryChannel(); var configuration = new TelemetryConfiguration { TelemetryChannel = channel, InstrumentationKey = "Test key" }; var client = new TelemetryClient(configuration); client.Track(new StubTelemetry()); PlatformSingleton.Current = null; Assert.Null(actualMessage); }