public async Task NoUserNameAndPasswordInLogsForHttp() { var payloadSender = new NoopPayloadSender(); var logger = new TestLogger(LogLevel.Trace); var agent = new ApmAgent(new TestAgentComponents(payloadSender: payloadSender, logger: logger)); agent.Subscribe(new HttpDiagnosticsSubscriber()); StartTransaction(agent); using (var localServer = LocalServer.Create()) using (var httpClient = new HttpClient()) { var uriBuilder = new UriBuilder(localServer.Uri) { UserName = "******", Password = "******" }; var res = await httpClient.GetAsync(uriBuilder.Uri); res.IsSuccessStatusCode.Should().BeTrue(); logger.Lines.Should().NotBeEmpty(); logger.Lines.Should().NotContain(n => n.Contains("TestUser289421")); logger.Lines.Should().NotContain(n => n.Contains("Password973243")); // looking for lines with "localhost:8082" and asserting that those contain [REDACTED]. foreach (var lineWithHttpLog in logger.Lines.Where(n => n.Contains($"{uriBuilder.Host}:{uriBuilder.Port}"))) { lineWithHttpLog.Should().Contain("[REDACTED]"); } } }
public void DistributionShouldBeUniform(double rate) { const int total = 1_000_000; var startCheckingAfter = Convert.ToInt32(total * 0.1); // i.e., after 10% const double allowedDiffInRate = 0.01; var sampledCount = 0; var noopLogger = new NoopLogger(); var noopPayloadSender = new NoopPayloadSender(); var sampler = new Sampler(rate); total.Repeat(i => { var transaction = new Transaction(noopLogger, "test transaction name", "test transaction type", sampler, null, noopPayloadSender, new TestAgentConfigurationReader(noopLogger)); if (transaction.IsSampled) { ++sampledCount; } if (i + 1 >= startCheckingAfter) { var actualRate = (double)sampledCount / (i + 1); var diffInRate = actualRate - rate; Assert.True(Math.Abs(diffInRate) <= allowedDiffInRate, "Abs(diffInRate) should be <= allowedDiffInRate. " + $"diffInRate: {diffInRate}, allowedDiffInRate: {allowedDiffInRate}, " + $"i: {i}, " + $"actual rate: {actualRate}, expected rate: {rate}, " + $"actual sampled count: {sampledCount}, expected sampled count: {Convert.ToInt32((i + 1) * rate)}" ); } }); }
public void Subscribers_Not_Subscribed_When_Agent_Disabled() { var payloadSender = new NoopPayloadSender(); var configReader = new MockConfiguration(enabled: "false"); using var agent = new ApmAgent(new TestAgentComponents(payloadSender: payloadSender, configuration: configReader)); var subscriber = new Mock <IDiagnosticsSubscriber>(); agent.Subscribe(subscriber.Object); subscriber.Verify(s => s.Subscribe(It.IsAny <IApmAgent>()), Times.Never); }
public void DistributionShouldBeUniform(double rate) { const int total = 1_000_000; var startCheckingAfter = Convert.ToInt32(total * 0.1); // i.e., after 10% const double allowedDiffInRate = 0.01; var sampledCount = 0; var noopLogger = new NoopLogger(); var currentExecutionSegmentsContainer = new NoopCurrentExecutionSegmentsContainer(); var noopPayloadSender = new NoopPayloadSender(); var configurationReader = new MockConfigSnapshot(noopLogger); var sampler = new Sampler(rate); total.Repeat(i => { // reset current activity, otherwise all transactions share the same traceid which influences the sampling decision Activity.Current = null; var transaction = new Transaction(noopLogger, "test transaction name", "test transaction type", sampler, /* distributedTracingData: */ null, noopPayloadSender, configurationReader, currentExecutionSegmentsContainer); if (transaction.IsSampled) { ++sampledCount; } // ReSharper disable once InvertIf if (i + 1 >= startCheckingAfter) { var actualRate = (double)sampledCount / (i + 1); var diffInRate = actualRate - rate; Assert.True(Math.Abs(diffInRate) <= allowedDiffInRate, "Abs(diffInRate) should be <= allowedDiffInRate. " + $"diffInRate: {diffInRate}, allowedDiffInRate: {allowedDiffInRate}, " + $"i: {i}, " + $"actual rate: {actualRate}, expected rate: {rate}, " + $"actual sampled count: {sampledCount}, expected sampled count: {Convert.ToInt32((i + 1) * rate)}" ); } }); }