-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added diagnostic tracing to the service bus. Closes GH-913
- Loading branch information
1 parent
22629a2
commit 196086d
Showing
12 changed files
with
203 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 24 additions & 1 deletion
25
src/FubuMVC.Core/ServiceBus/Runtime/Invocation/ProductionDiagnosticEnvelopeContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,36 @@ | ||
using System; | ||
using FubuCore.Dates; | ||
using FubuCore.Logging; | ||
using FubuMVC.Core.Diagnostics.Instrumentation; | ||
using FubuMVC.Core.ServiceBus.Runtime.Cascading; | ||
|
||
namespace FubuMVC.Core.ServiceBus.Runtime.Invocation | ||
{ | ||
public class ProductionDiagnosticEnvelopeContext : EnvelopeContext | ||
{ | ||
public ProductionDiagnosticEnvelopeContext(ILogger logger, ISystemTime systemTime, IChainInvoker invoker, IOutgoingSender outgoing, IHandlerPipeline pipeline) : base(logger, systemTime, invoker, outgoing, pipeline) | ||
private readonly Envelope _envelope; | ||
private readonly IExecutionLogger _executionLogger; | ||
protected readonly ChainExecutionLog _log; | ||
|
||
public ProductionDiagnosticEnvelopeContext(ILogger logger, ISystemTime systemTime, IChainInvoker invoker, IOutgoingSender outgoing, IHandlerPipeline pipeline, Envelope envelope, IExecutionLogger executionLogger) : base(logger, systemTime, invoker, outgoing, pipeline) | ||
{ | ||
_envelope = envelope; | ||
_executionLogger = executionLogger; | ||
_log = new ChainExecutionLog(); | ||
|
||
_envelope.Log = _log; | ||
} | ||
|
||
public sealed override void Dispose() | ||
{ | ||
_log.MarkFinished(); | ||
_executionLogger.Record(_log, _envelope); | ||
} | ||
|
||
public sealed override void Error(string correlationId, string message, Exception exception) | ||
{ | ||
_log.LogException(exception); | ||
base.Error(correlationId, message, exception); | ||
} | ||
} | ||
} |
26 changes: 24 additions & 2 deletions
26
src/FubuMVC.Core/ServiceBus/Runtime/Invocation/VerboseDiagnosticEnvelopeContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,35 @@ | ||
using System; | ||
using FubuCore.Dates; | ||
using FubuCore.Logging; | ||
using FubuMVC.Core.Diagnostics.Instrumentation; | ||
using FubuMVC.Core.ServiceBus.Runtime.Cascading; | ||
|
||
namespace FubuMVC.Core.ServiceBus.Runtime.Invocation | ||
{ | ||
public class VerboseDiagnosticEnvelopeContext : EnvelopeContext | ||
public class VerboseDiagnosticEnvelopeContext : ProductionDiagnosticEnvelopeContext | ||
{ | ||
public VerboseDiagnosticEnvelopeContext(ILogger logger, ISystemTime systemTime, IChainInvoker invoker, IOutgoingSender outgoing, IHandlerPipeline pipeline) : base(logger, systemTime, invoker, outgoing, pipeline) | ||
public VerboseDiagnosticEnvelopeContext(ILogger logger, ISystemTime systemTime, IChainInvoker invoker, IOutgoingSender outgoing, IHandlerPipeline pipeline, Envelope envelope, IExecutionLogger executionLogger) : base(logger, systemTime, invoker, outgoing, pipeline, envelope, executionLogger) | ||
{ | ||
} | ||
|
||
public override void InfoMessage<T>(Func<T> func) | ||
{ | ||
var message = func(); | ||
_log.Log(message); | ||
logger.InfoMessage(message); | ||
} | ||
|
||
public override void DebugMessage<T>(Func<T> func) | ||
{ | ||
var message = func(); | ||
_log.Log(message); | ||
logger.DebugMessage(message); | ||
} | ||
|
||
public override void InfoMessage<T>(T message) | ||
{ | ||
_log.Log(message); | ||
base.InfoMessage(message); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
src/FubuMVC.IntegrationTesting/ServiceBus/end_to_end_diagnostics_specs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Specialized; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Threading; | ||
using FubuCore; | ||
using FubuCore.Logging; | ||
using FubuMVC.Core; | ||
using FubuMVC.Core.Diagnostics.Instrumentation; | ||
using FubuMVC.Core.ServiceBus; | ||
using FubuMVC.Core.ServiceBus.Configuration; | ||
using NUnit.Framework; | ||
using Shouldly; | ||
using TraceLevel = FubuMVC.Core.TraceLevel; | ||
|
||
namespace FubuMVC.IntegrationTesting.ServiceBus | ||
{ | ||
[TestFixture] | ||
public class end_to_end_diagnostics_specs | ||
{ | ||
[Test] | ||
public void see_tracing_logs_in_production_mode_happy_path() | ||
{ | ||
var registry = new FubuRegistry(); | ||
registry.ServiceBus.Enable(true); | ||
registry.Features.Diagnostics.Enable(TraceLevel.Production); | ||
registry.ServiceBus.EnableInMemoryTransport(); | ||
|
||
using (var runtime = registry.ToRuntime()) | ||
{ | ||
var bus = runtime.Get<IServiceBus>(); | ||
|
||
bus.Consume(new TracedInput()); | ||
|
||
var history = runtime.Get<IChainExecutionHistory>(); | ||
|
||
var log = history.RecentReports().Single(x => x.RootChain != null && x.RootChain.InputType() == typeof(TracedInput)); | ||
|
||
log.Activity.AllSteps().Any(x => x.Log is StringMessage).ShouldBeFalse(); | ||
|
||
var headers = log.Request["Headers"].ShouldBeOfType<NameValueCollection>(); | ||
headers.AllKeys.Each(x => Debug.WriteLine("{0} = {1}", x, headers[x])); | ||
} | ||
} | ||
|
||
[Test] | ||
public void get_error_messages_in_production_mode() | ||
{ | ||
var registry = new FubuRegistry(); | ||
registry.ServiceBus.Enable(true); | ||
registry.Features.Diagnostics.Enable(TraceLevel.Production); | ||
registry.ServiceBus.EnableInMemoryTransport(); | ||
|
||
using (var runtime = registry.ToRuntime()) | ||
{ | ||
var bus = runtime.Get<IServiceBus>(); | ||
|
||
bus.Consume(new TracedInput { Fail = true }); | ||
|
||
|
||
var history = runtime.Get<IChainExecutionHistory>(); | ||
|
||
var log = history.RecentReports().Single(x => x.RootChain != null && x.RootChain.InputType() == typeof(TracedInput)); | ||
|
||
log.Activity.AllSteps().Any(x => x.Log is ExceptionReport).ShouldBeTrue(); | ||
log.HadException.ShouldBeTrue(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void see_tracing_logs_in_verbose_mode_happy_path() | ||
{ | ||
var registry = new FubuRegistry(); | ||
registry.ServiceBus.Enable(true); | ||
registry.Features.Diagnostics.Enable(TraceLevel.Verbose); | ||
registry.ServiceBus.EnableInMemoryTransport(); | ||
|
||
using (var runtime = registry.ToRuntime()) | ||
{ | ||
var bus = runtime.Get<IServiceBus>(); | ||
|
||
bus.Consume(new TracedInput()); | ||
|
||
var history = runtime.Get<IChainExecutionHistory>(); | ||
|
||
var log = history.RecentReports().Single(x => x.RootChain != null && x.RootChain.InputType() == typeof(TracedInput)); | ||
|
||
log.Request["Headers"].ShouldBeOfType<NameValueCollection>(); | ||
|
||
log.Activity.AllSteps().Any().ShouldBeTrue(); | ||
log.Activity.AllSteps().Any(x => x.Log is StringMessage).ShouldBeTrue(); | ||
|
||
log.Activity.AllSteps().Each(x => Debug.WriteLine(x)); | ||
} | ||
} | ||
} | ||
|
||
public class TracedInput | ||
{ | ||
public bool Fail { get; set; } | ||
} | ||
|
||
public class TracedInputConsumer | ||
{ | ||
private readonly ILogger _logger; | ||
|
||
public TracedInputConsumer(ILogger logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
public void Consume(TracedInput input) | ||
{ | ||
_logger.Info("I got into TracedInputConsumer"); | ||
|
||
Thread.Sleep(1.Seconds()); | ||
if (input.Fail) | ||
{ | ||
throw new DivideByZeroException("You shall not pass!"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters