Exemple #1
0
        protected TestsBase(
            ITestOutputHelper xUnitOutputHelper,
            bool startMockApmServer = true,
            IDictionary <string, string> envVarsToSetForSampleAppPool = null,
            bool sampleAppShouldHaveAccessToPerfCounters = false,
            bool sampleAppLogEnabled = true
            ) : base(xUnitOutputHelper)
        {
            _logger = LoggerBase.Scoped(ThisClassName);

            MockApmServer       = new MockApmServer(_logger, TestDisplayName);
            _iisAdministration  = new IisAdministration(_logger);
            _startMockApmServer = startMockApmServer;
            SampleAppShouldHaveAccessToPerfCounters = sampleAppShouldHaveAccessToPerfCounters;

            _mockApmServerPort = _startMockApmServer ? MockApmServer.FindAvailablePortToListen() : ConfigConsts.DefaultValues.ApmServerPort;

            _sampleAppLogEnabled  = sampleAppLogEnabled;
            _sampleAppLogFilePath = GetSampleAppLogFilePath();

            EnvVarsToSetForSampleAppPool = envVarsToSetForSampleAppPool == null
                                ? new Dictionary <string, string>()
                                : new Dictionary <string, string>(envVarsToSetForSampleAppPool);
            EnvVarsToSetForSampleAppPool.TryAdd(ConfigConsts.EnvVarNames.ServerUrls, BuildApmServerUrl(_mockApmServerPort));

            if (_sampleAppLogEnabled)
            {
                EnvVarsToSetForSampleAppPool.TryAdd(LoggingConfig.LogFileEnvVarName, _sampleAppLogFilePath);
            }

            EnvVarsToSetForSampleAppPool.TryAdd(ConfigConsts.EnvVarNames.FlushInterval, "10ms");
        }
Exemple #2
0
        public AspNetCoreBasicTests(WebApplicationFactory <Startup> factory, ITestOutputHelper xUnitOutputHelper) : base(xUnitOutputHelper)
        {
            _logger  = LoggerBase.Scoped(nameof(AspNetCoreBasicTests));
            _factory = factory;

            _agent = new ApmAgent(new TestAgentComponents(
                                      _logger,
                                      new MockConfigSnapshot(_logger, captureBody: ConfigConsts.SupportedValues.CaptureBodyAll),
                                      // _agent needs to share CurrentExecutionSegmentsContainer with Agent.Instance
                                      // because the sample application used by the tests (SampleAspNetCoreApp) uses Agent.Instance.Tracer.CurrentTransaction/CurrentSpan
                                      currentExecutionSegmentsContainer: Agent.Instance.TracerInternal.CurrentExecutionSegmentsContainer)
                                  );
            HostBuilderExtensions.UpdateServiceInformation(_agent.Service);
            _capturedPayload = _agent.PayloadSender as MockPayloadSender;
        }
        public AspNetCoreMiddlewareTests(WebApplicationFactory <Startup> factory, ITestOutputHelper xUnitOutputHelper) : base(xUnitOutputHelper)
        {
            _logger  = LoggerBase.Scoped(ThisClassName);
            _factory = factory;

            // We need to ensure Agent.Instance is created because we need _agent to use Agent.Instance CurrentExecutionSegmentsContainer
            AgentSingletonUtils.EnsureInstanceCreated();
            _agent = new ApmAgent(new TestAgentComponents(
                                      _logger,
                                      new MockConfigSnapshot(_logger, captureBody: ConfigConsts.SupportedValues.CaptureBodyAll),
                                      // _agent needs to share CurrentExecutionSegmentsContainer with Agent.Instance
                                      // because the sample application used by the tests (SampleAspNetCoreApp) uses Agent.Instance.Tracer.CurrentTransaction/CurrentSpan
                                      currentExecutionSegmentsContainer: Agent.Instance.TracerInternal.CurrentExecutionSegmentsContainer)
                                  );
            ApmMiddlewareExtension.UpdateServiceInformation(_agent.Service);

            _capturedPayload = _agent.PayloadSender as MockPayloadSender;
            _client          = Helper.GetClient(_agent, _factory);
        }
Exemple #4
0
        public TransactionIgnoreUrlsTest(WebApplicationFactory <Startup> factory, ITestOutputHelper xUnitOutputHelper) : base(xUnitOutputHelper)
        {
            _factory = factory;
            _logger  = LoggerBase.Scoped(ThisClassName);

            _agent = new ApmAgent(new TestAgentComponents(
                                      _logger,
                                      new MockConfigSnapshot(_logger, transactionIgnoreUrls: "*simplepage"),
                                      // _agent needs to share CurrentExecutionSegmentsContainer with Agent.Instance
                                      // because the sample application used by the tests (SampleAspNetCoreApp) uses Agent.Instance.Tracer.CurrentTransaction/CurrentSpan
                                      currentExecutionSegmentsContainer: Agent.Instance.TracerInternal.CurrentExecutionSegmentsContainer)
                                  );
            HostBuilderExtensions.UpdateServiceInformation(_agent.Service);

            _capturedPayload = _agent.PayloadSender as MockPayloadSender;
            _client          = Helper.GetClient(_agent, _factory);
#if NETCOREAPP3_0 || NETCOREAPP3_1
            _client.DefaultRequestVersion = new Version(2, 0);
#endif
        }
Exemple #5
0
 public MetricsTests(ITestOutputHelper xUnitOutputHelper) : base(xUnitOutputHelper)
 {
     _output = xUnitOutputHelper;
     _logger = LoggerBase.Scoped(ThisClassName);
 }
Exemple #6
0
        public PayloadSenderTests(ITestOutputHelper xUnitOutputHelper) : base(xUnitOutputHelper /*, LogLevel.Debug */)
        {
            _logger = LoggerBase.Scoped(ThisClassName);
//			LoggerBase.Level = LogLevel.Debug;
        }