[NetCoreFact] //see: https://github.com/elastic/apm-agent-dotnet/issues/516 public async Task SubscriptionOnlyRegistersSpansDuringItsLifeTime() { var payloadSender = new MockPayloadSender(); var agent = new ApmAgent(new TestAgentComponents(payloadSender: payloadSender)); StartTransaction(agent); var spans = payloadSender.Spans; using (var localServer = LocalServer.Create()) using (var httpClient = new HttpClient()) { spans.Should().BeEmpty(); using (agent.Subscribe(new HttpDiagnosticsSubscriber())) { var res = await httpClient.GetAsync(localServer.Uri); res.IsSuccessStatusCode.Should().BeTrue(); res = await httpClient.GetAsync(localServer.Uri); res.IsSuccessStatusCode.Should().BeTrue(); } payloadSender.WaitForSpans(); spans = payloadSender.Spans; spans.Should().NotBeEmpty().And.HaveCount(2); foreach (var _ in Enumerable.Range(0, 10)) { await httpClient.GetAsync(localServer.Uri); } localServer.SeenRequests.Should() .BeGreaterOrEqualTo(10, "Make sure we actually performed more than 1 request to our local server"); } spans.Should().HaveCount(2); }
public void PayloadSenderNoUserNamePwPrintedForServerUrlWithServerReturn() { var userName = "******"; var pw = "def"; var inMemoryLogger = new InMemoryBlockingLogger(LogLevel.Error); using var localServer = LocalServer.Create(httpListenerContext => { httpListenerContext.Response.StatusCode = 500; }); var uri = new Uri(localServer.Uri); var configReader = new MockConfiguration(serverUrls: $"http://{userName}:{pw}@{uri.Authority}", maxBatchEventCount: "0", flushInterval: "0"); using var payloadSender = new PayloadSenderV2(inMemoryLogger, configReader, Service.GetDefaultService(configReader, inMemoryLogger), new Api.System(), MockApmServerInfo.Version710); using var agent = new ApmAgent(new TestAgentComponents(payloadSender: payloadSender)); agent.Tracer.CaptureTransaction("Test", "TestTransaction", () => { }); inMemoryLogger.Lines.Should().HaveCount(1); inMemoryLogger.Lines.Should().NotContain(n => n.Contains($"{userName}:{pw}")); inMemoryLogger.Lines.Should().Contain(n => n.Contains($"http://[REDACTED]:[REDACTED]@{uri.Authority}")); }