Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand on Audited Members #776

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

woksin
Copy link
Contributor

@woksin woksin commented Mar 18, 2024

Audit members are now also added as structured logging context to the Microsoft ILogger in message handler chain if any Audited members are present in the Chain AuditedMembers list or if the Aggregate Type has any Auditted members.

@woksin woksin reopened this Apr 23, 2024
@woksin
Copy link
Contributor Author

woksin commented Apr 23, 2024

I would want to spend more time on writing tests, but I just added one very quick one to just see the compiled source code for message with Audit members. Here is the output of that test:

public class SomeMessageHandler797407002 : Wolverine.Runtime.Handlers.MessageHandler
    {
        private readonly Microsoft.Extensions.Logging.ILogger<CoreTests.Compilation.SomeMessage> _loggerForMessage;

        public SomeMessageHandler797407002(Microsoft.Extensions.Logging.ILogger<CoreTests.Compilation.SomeMessage> loggerForMessage)
        {
            _loggerForMessage = loggerForMessage;
        }



        public override System.Threading.Tasks.Task HandleAsync(Wolverine.Runtime.MessageContext context, System.Threading.CancellationToken cancellation)
        {
            var someMessageHandler = new CoreTests.Compilation.SomeMessageHandler();
            // The actual message body
            var someMessage = (CoreTests.Compilation.SomeMessage)context.Envelope.Message;

            // Application-specific Open Telemetry auditing
            System.Diagnostics.Activity.Current?.SetTag("id", someMessage.Id);
            System.Diagnostics.Activity.Current?.SetTag("some.string", someMessage.SomeString);
            var wolverineLoggingContext_loggingTools = new Wolverine.Logging.LoggingContext();
            wolverineLoggingContext_loggingTools.Add("TenantId", context.TenantId ?? "[NotSet]");
            // Adding audited members to log context
            wolverineLoggingContext_loggingTools.AddRange(("Id", someMessage.Id), ("SomeString", someMessage.SomeString));
            // Beginning logging scopes for new context
            using var disposable_b519d909_ba96_488d_9ed0_bb9c67c85771 = ((Microsoft.Extensions.Logging.ILogger)_loggerForMessage).BeginScope(wolverineLoggingContext_loggingTools);
            
            // The actual message execution
            someMessageHandler.Handle(someMessage, ((Microsoft.Extensions.Logging.ILogger)_loggerForMessage));

            return System.Threading.Tasks.Task.CompletedTask;
        }

    }

@woksin
Copy link
Contributor Author

woksin commented Apr 24, 2024

I see that for the AggregateHandler and Aggregate attributes I need to do something differently because it adds the logging middleware regardless of whether the logging context middleware is registered or not. Also there is probably some things that I'm missing or some other way to write this that makes it a bit better integrated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant