public Process StartSample(int traceAgentPort, string arguments = null) { // get path to native profiler dll string profilerDllPath = GetProfilerDllPath(); if (!File.Exists(profilerDllPath)) { throw new Exception($"profiler not found: {profilerDllPath}"); } // get path to sample app that the profiler will attach to string sampleAppPath = GetSampleApplicationPath(); if (!File.Exists(sampleAppPath)) { throw new Exception($"application not found: {sampleAppPath}"); } // get full paths to integration definitions IEnumerable <string> integrationPaths = Directory.EnumerateFiles(".", "*integrations.json").Select(Path.GetFullPath); return(ProfilerHelper.StartProcessWithProfiler( sampleAppPath, BuildParameters.CoreClr, integrationPaths, Instrumentation.ProfilerClsid, profilerDllPath, arguments, traceAgentPort: traceAgentPort)); }
public Process StartDotnetTestSample(int traceAgentPort, string arguments, string packageVersion, int aspNetCorePort, int?statsdPort = null, string framework = "") { // get path to sample app that the profiler will attach to string sampleAppPath = EnvironmentHelper.GetTestCommandForSampleApplicationPath(packageVersion, framework); if (!File.Exists(sampleAppPath)) { throw new Exception($"application not found: {sampleAppPath}"); } // get full paths to integration definitions IEnumerable <string> integrationPaths = Directory.EnumerateFiles(".", "*integrations.json").Select(Path.GetFullPath); Output.WriteLine($"Starting Application: {sampleAppPath}"); string testCli = EnvironmentHelper.GetDotNetTest(); string exec = testCli; string appPath = testCli.StartsWith("dotnet") ? $"vstest {sampleAppPath}" : sampleAppPath; Output.WriteLine("Executable: " + exec); Output.WriteLine("ApplicationPath: " + appPath); return(ProfilerHelper.StartProcessWithProfiler( exec, appPath, EnvironmentHelper, integrationPaths, arguments, traceAgentPort: traceAgentPort, statsdPort: statsdPort, aspNetCorePort: aspNetCorePort, forceExecutable: true)); }
public Process StartSample(int traceAgentPort, string arguments = null) { // get path to sample app that the profiler will attach to string sampleAppPath = GetSampleApplicationPath(); if (!File.Exists(sampleAppPath)) { throw new Exception($"application not found: {sampleAppPath}"); } // get full paths to integration definitions IEnumerable <string> integrationPaths = Directory.EnumerateFiles(".", "*integrations.json").Select(Path.GetFullPath); return(ProfilerHelper.StartProcessWithProfiler( _environmentHelper, integrationPaths, arguments, traceAgentPort: traceAgentPort)); }
public Process StartSample(int traceAgentPort, string arguments, string packageVersion, int aspNetCorePort, string framework = "") { // get path to sample app that the profiler will attach to string sampleAppPath = EnvironmentHelper.GetSampleApplicationPath(packageVersion, framework); if (!File.Exists(sampleAppPath)) { throw new Exception($"application not found: {sampleAppPath}"); } // get full paths to integration definitions IEnumerable <string> integrationPaths = Directory.EnumerateFiles(".", "*integrations.json").Select(Path.GetFullPath); Output.WriteLine($"Starting Application: {sampleAppPath}"); return(ProfilerHelper.StartProcessWithProfiler( EnvironmentHelper.GetSampleExecutionSource(), sampleAppPath, EnvironmentHelper, integrationPaths, arguments, traceAgentPort: traceAgentPort, aspNetCorePort: aspNetCorePort)); }
public Process StartIISExpress(int traceAgentPort, int iisPort) { // get full paths to integration definitions IEnumerable <string> integrationPaths = Directory.EnumerateFiles(".", "*integrations.json").Select(Path.GetFullPath); var exe = EnvironmentHelper.GetSampleExecutionSource(); var args = new string[] { $"/clr:v4.0", $"/path:{EnvironmentHelper.GetSampleProjectDirectory()}", $"/systray:false", $"/port:{iisPort}", $"/trace:info", }; Output.WriteLine($"[webserver] starting {exe} {string.Join(" ", args)}"); var process = ProfilerHelper.StartProcessWithProfiler( EnvironmentHelper, integrationPaths, arguments: string.Join(" ", args), redirectStandardInput: true, traceAgentPort: traceAgentPort); var wh = new EventWaitHandle(false, EventResetMode.AutoReset); Task.Run(() => { string line; while ((line = process.StandardOutput.ReadLine()) != null) { Output.WriteLine($"[webserver][stdout] {line}"); if (line.Contains("IIS Express is running")) { wh.Set(); } } }); Task.Run(() => { string line; while ((line = process.StandardError.ReadLine()) != null) { Output.WriteLine($"[webserver][stderr] {line}"); } }); wh.WaitOne(5000); // Wait for iis express to finish starting up var retries = 5; while (true) { var usedPorts = IPGlobalProperties.GetIPGlobalProperties() .GetActiveTcpListeners() .Select(ipEndPoint => ipEndPoint.Port); if (usedPorts.Contains(iisPort)) { break; } retries--; if (retries == 0) { throw new Exception("Gave up waiting for IIS Express."); } Thread.Sleep(1500); } return(process); }
public (Process Process, string ConfigFile) StartIISExpress(int traceAgentPort, int iisPort, bool classicMode) { // get full paths to integration definitions IEnumerable <string> integrationPaths = Directory.EnumerateFiles(".", "*integrations.json").Select(Path.GetFullPath); var exe = EnvironmentHelper.GetSampleExecutionSource(); var configTemplate = File.ReadAllText("applicationHost.config"); var newConfig = Path.GetTempFileName(); configTemplate = configTemplate .Replace("[PATH]", EnvironmentHelper.GetSampleProjectDirectory()) .Replace("[PORT]", iisPort.ToString()) .Replace("[POOL]", classicMode ? "Clr4ClassicAppPool" : "Clr4IntegratedAppPool"); File.WriteAllText(newConfig, configTemplate); var args = new[] { "/site:sample", $"/config:{newConfig}", "/systray:false", "/trace:info" }; Output.WriteLine($"[webserver] starting {exe} {string.Join(" ", args)}"); var process = ProfilerHelper.StartProcessWithProfiler( EnvironmentHelper.GetSampleExecutionSource(), EnvironmentHelper.GetSampleExecutionSource(), EnvironmentHelper, integrationPaths, arguments: string.Join(" ", args), redirectStandardInput: true, traceAgentPort: traceAgentPort); var wh = new EventWaitHandle(false, EventResetMode.AutoReset); Task.Run(() => { string line; while ((line = process.StandardOutput.ReadLine()) != null) { Output.WriteLine($"[webserver][stdout] {line}"); if (line.Contains("IIS Express is running")) { wh.Set(); } } }); Task.Run(() => { string line; while ((line = process.StandardError.ReadLine()) != null) { Output.WriteLine($"[webserver][stderr] {line}"); } }); wh.WaitOne(5000); // Wait for iis express to finish starting up var retries = 5; while (true) { var usedPorts = IPGlobalProperties.GetIPGlobalProperties() .GetActiveTcpListeners() .Select(ipEndPoint => ipEndPoint.Port); if (usedPorts.Contains(iisPort)) { break; } retries--; if (retries == 0) { throw new Exception("Gave up waiting for IIS Express."); } Thread.Sleep(1500); } return(process, newConfig); }
public IISExpress StartIISExpress(int traceAgentPort, int iisPort) { // get path to native profiler dll string profilerDllPath = GetProfilerDllPath(); if (!File.Exists(profilerDllPath)) { throw new Exception($"profiler not found: {profilerDllPath}"); } var sampleDir = Path.Combine( GetSolutionDirectory(), "samples", $"Samples.{SampleAppName}"); // get full paths to integration definitions IEnumerable <string> integrationPaths = Directory.EnumerateFiles(".", "*integrations.json").Select(Path.GetFullPath); var exe = $"C:\\Program Files{(Environment.Is64BitProcess ? string.Empty : " (x86)")}\\IIS Express\\iisexpress.exe"; var args = new string[] { $"/clr:v4.0", $"/path:{sampleDir}", $"/systray:false", $"/port:{iisPort}", $"/trace:info", }; Output.WriteLine($"[webserver] starting {exe} {string.Join(" ", args)}"); var process = ProfilerHelper.StartProcessWithProfiler( exe, BuildParameters.CoreClr, integrationPaths, Instrumentation.ProfilerClsid, profilerDllPath, arguments: string.Join(" ", args), redirectStandardInput: true, traceAgentPort: traceAgentPort); var wh = new EventWaitHandle(false, EventResetMode.AutoReset); Task.Run(() => { string line; while ((line = process.StandardOutput.ReadLine()) != null) { if (line.Contains("IIS Express is running")) { wh.Set(); } Output.WriteLine($"[webserver][stdout] {line}"); } }); Task.Run(() => { string line; while ((line = process.StandardError.ReadLine()) != null) { Output.WriteLine($"[webserver][stderr] {line}"); } }); wh.WaitOne(5000); return(new IISExpress(process)); }
private void StartSample( MockTracerAgent agent, string arguments, string packageVersion = "", string framework = "", string path = "/Home", bool enableSecurity = true, string externalRulesFile = null, int?traceRateLimit = null) { var sampleAppPath = EnvironmentHelper.GetSampleApplicationPath(packageVersion, framework); // get path to sample app that the profiler will attach to const int mstimeout = 15_000; if (!File.Exists(sampleAppPath)) { throw new Exception($"application not found: {sampleAppPath}"); } // EnvironmentHelper.DebugModeEnabled = true; Output.WriteLine($"Starting Application: {sampleAppPath}"); var executable = EnvironmentHelper.IsCoreClr() ? EnvironmentHelper.GetSampleExecutionSource() : sampleAppPath; var args = EnvironmentHelper.IsCoreClr() ? $"{sampleAppPath} {arguments ?? string.Empty}" : arguments; EnvironmentHelper.CustomEnvironmentVariables.Add("DD_APPSEC_TRACE_RATE_LIMIT", traceRateLimit?.ToString()); EnvironmentHelper.CustomEnvironmentVariables.Add("DD_APPSEC_WAF_TIMEOUT", 1_000_000.ToString()); int?aspNetCorePort = default; _process = ProfilerHelper.StartProcessWithProfiler( executable, EnvironmentHelper, agent, args, aspNetCorePort: 0, enableSecurity: enableSecurity, externalRulesFile: externalRulesFile); // then wait server ready var wh = new EventWaitHandle(false, EventResetMode.AutoReset); _process.OutputDataReceived += (sender, args) => { if (args.Data != null) { if (args.Data.Contains("Now listening on:")) { var splitIndex = args.Data.LastIndexOf(':'); aspNetCorePort = int.Parse(args.Data.Substring(splitIndex + 1)); wh.Set(); } Output.WriteLine($"[webserver][stdout] {args.Data}"); } }; _process.BeginOutputReadLine(); _process.ErrorDataReceived += (sender, args) => { if (args.Data != null) { Output.WriteLine($"[webserver][stderr] {args.Data}"); } }; _process.BeginErrorReadLine(); wh.WaitOne(mstimeout); if (!aspNetCorePort.HasValue) { _process.Kill(); throw new Exception("Unable to determine port application is listening on"); } _httpPort = aspNetCorePort.Value; }