public static void Initialize() { if (Interlocked.Exchange(ref _firstInitialization, 0) != 1) { // Initialize() was already called before return; } Log.Information("Initializing CI Visibility"); LifetimeManager.Instance.AddAsyncShutdownTask(ShutdownAsync); TracerSettings tracerSettings = _settings.TracerSettings; // Set the service name if empty Log.Information("Setting up the service name"); if (string.IsNullOrEmpty(tracerSettings.ServiceName)) { // Extract repository name from the git url and use it as a default service name. tracerSettings.ServiceName = GetServiceNameFromRepository(CIEnvironmentValues.Instance.Repository); } // Initialize Tracer Log.Information("Initialize Test Tracer instance"); TracerManager.ReplaceGlobalManager(tracerSettings.Build(), new CITracerManagerFactory(_settings)); }
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); }