public void AllTelemetryIsSentWithDefaultSamplingRate() { var sentTelemetry = new List<ITelemetry>(); var channel = new StubTelemetryChannel { OnSend = t => sentTelemetry.Add(t) }; var configuration = new TelemetryConfiguration { InstrumentationKey = "Test key", TelemetryChannel = channel }; var client = new TelemetryClient(configuration); const int ItemsToGenerate = 100; for (int i = 0; i < ItemsToGenerate; i++) { client.TrackRequest(new RequestTelemetry()); } Assert.Equal(ItemsToGenerate, sentTelemetry.Count); }
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 TransmissionProcessorTransmitsAllDataWhenNoOtherProcessorPresent() { var sentTelemetry = new List<ITelemetry>(); var channel = new StubTelemetryChannel { OnSend = t => sentTelemetry.Add(t) }; var configuration = new TelemetryConfiguration { InstrumentationKey = "Test key", TelemetryChannel = channel }; var client = new TelemetryClient(configuration); var transmissionProcessor = new TransmissionProcessor(configuration); const int ItemsToGenerate = 100; for (int i = 0; i < ItemsToGenerate; i++) { transmissionProcessor.Process(new RequestTelemetry()); } Assert.Equal(ItemsToGenerate, sentTelemetry.Count); }
public void TrackAddsDeveloperModeCustomPropertyWhenDeveloperModeIsTrue() { ITelemetry sentTelemetry = null; var channel = new StubTelemetryChannel { OnSend = telemetry => sentTelemetry = telemetry, DeveloperMode = true }; var configuration = new TelemetryConfiguration { TelemetryChannel = channel, InstrumentationKey = "Test key" }; var client = new TelemetryClient(configuration); client.Track(new StubTelemetry()); Assert.Equal("true", ((ISupportProperties)sentTelemetry).Properties["DeveloperMode"]); }
private TelemetryClient InitializeTelemetryClient(ICollection<ITelemetry> sentTelemetry) { var channel = new StubTelemetryChannel { OnSend = t => sentTelemetry.Add(t) }; var telemetryConfiguration = new TelemetryConfiguration { InstrumentationKey = Guid.NewGuid().ToString(), TelemetryChannel = channel}; var client = new TelemetryClient(telemetryConfiguration); return client; }
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 TrackUsesInstrumentationKeyFromConfigurationWhenTheInstrumenationKeyIsEmpty() { ITelemetry sentTelemetry = null; var channel = new StubTelemetryChannel { OnSend = telemetry => sentTelemetry = telemetry }; var configuration = new TelemetryConfiguration { TelemetryChannel = channel }; var client = new TelemetryClient(configuration); var observe = client.Context.InstrumentationKey; string expectedKey = Guid.NewGuid().ToString(); configuration.InstrumentationKey = expectedKey; Assert.DoesNotThrow(() => client.TrackTrace("Test Message")); Assert.Equal(expectedKey, sentTelemetry.Context.InstrumentationKey); }
public void TrackRespectsInstrumentaitonKeySetByTelemetryInitializer() { var sentTelemetry = new List<ITelemetry>(); var channel = new StubTelemetryChannel { OnSend = t => sentTelemetry.Add(t) }; var configuration = new TelemetryConfiguration { // no instrumentation key set here TelemetryChannel = channel }; var initializedTelemetry = new List<ITelemetry>(); var telemetryInitializer = new StubTelemetryInitializer(); telemetryInitializer.OnInitialize = item => { item.Context.InstrumentationKey = "Foo"; initializedTelemetry.Add(item); }; configuration.TelemetryInitializers.Add(telemetryInitializer); var client = new TelemetryClient(configuration); var telemetry = new StubTelemetry(); client.Track(telemetry); Assert.Equal(1, sentTelemetry.Count); Assert.Equal(1, initializedTelemetry.Count); }
public void TrackMethodDontThrowsWhenInstrumentationKeyIsEmptyAndNotSendingTheTelemetryItem() { var channel = new StubTelemetryChannel { ThrowError = true }; TelemetryConfiguration.Active = new TelemetryConfiguration { InstrumentationKey = string.Empty, TelemetryChannel = channel }; Assert.DoesNotThrow(() => new TelemetryClient().Track(new StubTelemetry())); }
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); }
public void TrackDoesNotTryAddingDeveloperModeCustomPropertyWhenTelemetryDoesNotSupportCustomProperties() { var channel = new StubTelemetryChannel { DeveloperMode = true }; var configuration = new TelemetryConfiguration { TelemetryChannel = channel, InstrumentationKey = "Test Key" }; var client = new TelemetryClient(configuration); Assert.DoesNotThrow(() => client.Track(new SessionStateTelemetry())); }
public void TrackDoesNotSendDataWhenTelemetryIsDisabled() { var sentTelemetry = new List<ITelemetry>(); var channel = new StubTelemetryChannel { OnSend = t => sentTelemetry.Add(t) }; var configuration = new TelemetryConfiguration { DisableTelemetry = true , TelemetryChannel = channel }; var client = new TelemetryClient(configuration) {}; client.Track(new StubTelemetry()); Assert.Equal(0, sentTelemetry.Count); }
public void TrackDoesNotAddDeveloperModeCustomPropertyIfDeveloperModeIsSetToFalse() { ITelemetry sentTelemetry = null; var channel = new StubTelemetryChannel { OnSend = telemetry => sentTelemetry = telemetry, DeveloperMode = false }; var configuration = new TelemetryConfiguration { TelemetryChannel = channel, InstrumentationKey = "Test key" }; var client = new TelemetryClient(configuration); client.Track(new StubTelemetry()); Assert.False(((ISupportProperties)sentTelemetry).Properties.ContainsKey("DeveloperMode")); }
public void TrackAddsTimestampWhenMissing() { ITelemetry sentTelemetry = null; var channel = new StubTelemetryChannel { OnSend = telemetry => sentTelemetry = telemetry }; var configuration = new TelemetryConfiguration { TelemetryChannel = channel, InstrumentationKey = "Test key" }; var client = new TelemetryClient(configuration); client.Track(new StubTelemetry()); Assert.NotEqual(DateTimeOffset.MinValue, sentTelemetry.Timestamp); }
public void TelemetryChannelCanBeSetByUserToReplaceDefaultChannelForTesting() { var configuration = new TelemetryConfiguration(); var customChannel = new StubTelemetryChannel(); configuration.TelemetryChannel = customChannel; Assert.Same(customChannel, configuration.TelemetryChannel); }