Beispiel #1
0
        public void CreateConsumer_ErrorToLogsConsumer()
        {
            var eventTarget = EventTarget.ForLogging(_projectId, "test-log", _loggingClient);
            var options     = ErrorReportingOptions.Create(eventTarget);
            var consumer    = options.CreateConsumer();

            Assert.IsType <ErrorEventToLogEntryConsumer>(consumer);
        }
Beispiel #2
0
        public void CreateConsumer_BufferdConsumer()
        {
            var bufferOptions = BufferOptions.SizedBuffer();
            var eventTarget   = EventTarget.ForLogging(_projectId, "test-log", _loggingClient);
            var options       = ErrorReportingOptions.Create(eventTarget, bufferOptions);
            var consumer      = options.CreateConsumer();

            Assert.IsType <SizedBufferingConsumer <ReportedErrorEvent> >(consumer);
        }
        public void CreateConsumer_ErrorToLogsConsumer()
        {
            var eventTarget = EventTarget.ForLogging(_projectId, "test-log", _loggingClient);
            var options     = ErrorReportingOptions.Create(eventTarget);
            var consumer    = options.CreateConsumer();

            Assert.IsType <RpcRetryConsumer <LogEntry> >(consumer);
            var retryConsumer = (RpcRetryConsumer <LogEntry>)consumer;

            Assert.IsType <GrpcLogConsumer>(retryConsumer._consumer);
        }
        public async Task LogAsync()
        {
            var options = ErrorReportingOptions.Create(
                EventTarget.ForLogging("pid", loggingClient: new ThrowingLoggingClient()));
            var consumer = new FakeConsumer();

            IContextExceptionLogger logger = new ErrorReportingContextExceptionLogger(
                consumer, _service, _version, options, null);
            await logger.LogAsync(CreateException(), new FakeContextWrapper());

            ValidateSingleEntry(consumer, _method, _uri, _userAgent, options);
        }
        public void Log_Simple()
        {
            var options = ErrorReportingOptions.Create(
                EventTarget.ForLogging("pid", loggingClient: new ThrowingLoggingClient()));
            var consumer = new FakeConsumer();

            IContextExceptionLogger logger = new ErrorReportingContextExceptionLogger(
                consumer, _service, _version, options, null);

            logger.Log(CreateException(), new EmptyContextWrapper());

            ValidateSingleEntry(consumer, "", "", "", options);
        }
Beispiel #6
0
        public void Log_Compat()
        {
            var eventTarget = EventTarget.ForLogging("pid", loggingClient: new ThrowingLoggingClient());
            var options     = ErrorReportingOptions.Create(eventTarget);
            var consumer    = new FakeConsumer();

            IContextExceptionLogger logger = new ErrorReportingContextExceptionLogger(
                consumer, eventTarget, _serviceContext, options, null);

            logger.Log(CreateException(), new FakeContextWrapper());

            ValidateSingleEntry(consumer, _method, _uri, _userAgent, options, eventTarget);
        }
Beispiel #7
0
        public void Logging_LogTarget()
        {
            var logTarget         = LogTarget.ForOrganization(_organizationId);
            var logName           = "another-log";
            var monitoredResource = new MonitoredResource {
                Type = "not_global"
            };
            var eventTarget = EventTarget.ForLogging(logTarget, logName, _loggingClient, monitoredResource);

            Assert.Equal(EventTargetKind.Logging, eventTarget.Kind);
            Assert.Equal(_loggingClient, eventTarget.LoggingClient);
            Assert.Equal(logTarget, eventTarget.LogTarget);
            Assert.Equal(logName, eventTarget.LogName);
            Assert.Equal(monitoredResource, eventTarget.MonitoredResource);
        }
Beispiel #8
0
        public void Logging_ProjectId()
        {
            var logName     = "another-log";
            var eventTarget = EventTarget.ForLogging(
                _projectId, logName, _loggingClient, MonitoredResourceBuilder.GlobalResource);

            Assert.Equal(EventTargetKind.Logging, eventTarget.Kind);
            Assert.Equal(_projectId, eventTarget.ProjectId);
            Assert.Equal(_loggingClient, eventTarget.LoggingClient);
            Assert.NotNull(eventTarget.LogTarget);
            Assert.Equal(LogTargetKind.Project, eventTarget.LogTarget.Kind);
            Assert.Equal(_projectId, eventTarget.LogTarget.ProjectId);
            Assert.Equal(logName, eventTarget.LogName);
            Assert.Equal(MonitoredResourceBuilder.GlobalResource, eventTarget.MonitoredResource);
        }
Beispiel #9
0
        public void Log_Simple()
        {
            var options = ErrorReportingOptions.Create(
                EventTarget.ForLogging("pid", loggingClient: new Mock <LoggingServiceV2Client>().Object));
            var mockConsumer = new Mock <IConsumer <LogEntry> >();

            mockConsumer.Setup(c => c.Receive(IsContext("", "", "", options)));

            IContextExceptionLogger logger = new ErrorReportingContextExceptionLogger(
                mockConsumer.Object, _service, _version, options);

            logger.Log(CreateException(), new EmptyContextWrapper());

            mockConsumer.VerifyAll();
        }
 public override void ConfigureServices(IServiceCollection services) =>
 base.ConfigureServices(services
                        .AddGoogleExceptionLogging(options =>
 {
     options.ProjectId   = ProjectId;
     options.ServiceName = EntryData.Service;
     options.Version     = EntryData.Version;
     // This is just so that our validator finds the log entries associated to errors.
     options.Options = ErrorReportingOptions.Create(EventTarget.ForLogging(ProjectId, "aspnetcore"));
 })
                        .AddGoogleTrace(options =>
 {
     options.ProjectId = ProjectId;
     options.Options   = TraceOptions.Create(
         double.PositiveInfinity, BufferOptions.NoBuffer(), RetryOptions.NoRetry(ExceptionHandling.Propagate));
 }));
Beispiel #11
0
        public async Task LogAsync()
        {
            var options = ErrorReportingOptions.Create(
                EventTarget.ForLogging("pid", loggingClient: new Mock <LoggingServiceV2Client>().Object));
            var mockConsumer = new Mock <IConsumer <LogEntry> >();

            mockConsumer.Setup(c => c.ReceiveAsync(
                                   IsContext(_method, _uri, _userAgent, options), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(true));

            IContextExceptionLogger logger = new ErrorReportingContextExceptionLogger(
                mockConsumer.Object, _service, _version, options);

            await logger.LogAsync(CreateException(), new FakeContextWrapper());

            mockConsumer.VerifyAll();
        }