public async Task FlushTwice() { var w = new CIAgentWriter(_api.Object); await w.FlushAndCloseAsync(); await w.FlushAndCloseAsync(); }
public CIAgentWriterTests() { var tracer = new Mock <IDatadogTracer>(); tracer.Setup(x => x.DefaultServiceName).Returns("Default"); _settings = new Configuration.ImmutableTracerSettings(Ci.Configuration.CIVisibilitySettings.FromDefaultSources().TracerSettings); _api = new Mock <IApi>(); _ciAgentWriter = new CIAgentWriter(_api.Object); }
public static async Task <bool> CheckAgentConnectionAsync(string agentUrl) { var env = new NameValueCollection(); if (!string.IsNullOrWhiteSpace(agentUrl)) { env["DD_TRACE_AGENT_URL"] = agentUrl; } var globalSettings = GlobalSettings.CreateDefaultConfigurationSource(); globalSettings.Add(new NameValueConfigurationSource(env)); var tracerSettings = new TracerSettings(globalSettings); var agentWriter = new CIAgentWriter(tracerSettings.Build(), new CISampler()); try { if (!await agentWriter.Ping().ConfigureAwait(false)) { WriteError($"Error connecting to the Datadog Agent at {tracerSettings.Exporter.AgentUri}."); return(false); } } catch (Exception ex) { WriteError($"Error connecting to the Datadog Agent at {tracerSettings.Exporter.AgentUri}."); AnsiConsole.WriteException(ex); return(false); } finally { await agentWriter.FlushAndCloseAsync().ConfigureAwait(false); } return(true); }