Skip to content
This repository has been archived by the owner on Jun 27, 2024. It is now read-only.

Commit

Permalink
Some changes but not ready yet
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyzimarev committed Nov 11, 2021
1 parent 101a078 commit 5b20f90
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 73 deletions.
2 changes: 1 addition & 1 deletion Bookings.Domain/Bookings.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Eventuous" Version="0.5.16-alpha.0.9" />
<PackageReference Include="Eventuous" Version="0.5.16-alpha.0.15" />
</ItemGroup>

</Project>
8 changes: 4 additions & 4 deletions Bookings.Payments/Bookings.Payments.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Eventuous.Shovel" Version="0.5.16-alpha.0.9" />
<PackageReference Include="Eventuous.EventStore" Version="0.5.16-alpha.0.9" />
<PackageReference Include="Eventuous.Diagnostics.OpenTelemetry" Version="0.5.16-alpha.0.9" />
<PackageReference Include="Eventuous.Projections.MongoDB" Version="0.5.16-alpha.0.9" />
<PackageReference Include="Eventuous.Shovel" Version="0.5.16-alpha.0.15" />
<PackageReference Include="Eventuous.EventStore" Version="0.5.16-alpha.0.15" />
<PackageReference Include="Eventuous.Diagnostics.OpenTelemetry" Version="0.5.16-alpha.0.15" />
<PackageReference Include="Eventuous.Projections.MongoDB" Version="0.5.16-alpha.0.15" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.5" />
<PackageReference Include="OpenTelemetry.Exporter.Zipkin" Version="1.2.0-beta1" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.0.0-rc8" />
Expand Down
27 changes: 27 additions & 0 deletions Bookings.Payments/Infrastructure/ActivityListener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Diagnostics;
using Eventuous.Diagnostics;
using Serilog;

namespace Bookings.Payments.Infrastructure;

public sealed class TestActivityListener : IDisposable{
readonly ActivityListener _listener;

public TestActivityListener() {
_listener = new ActivityListener {
ShouldListenTo = _ => true,
Sample = (ref ActivityCreationOptions<ActivityContext> _)
=> ActivitySamplingResult.AllData,
ActivityStarted = activity => Log.Information(
"Started {Activity} with {Id}, parent {ParentId}",
activity.DisplayName,
activity.Id,
activity.ParentId
),
ActivityStopped = activity
=> Log.Information("Stopped {Activity}", activity.DisplayName)
};
}

public void Dispose() => _listener.Dispose();
}
15 changes: 14 additions & 1 deletion Bookings.Payments/Infrastructure/SerilogExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using Serilog;
using Serilog.Events;
using Serilog.Extensions.Hosting;
using Serilog.Extensions.Logging;

namespace Bookings.Payments.Infrastructure;

public static class SerilogExtensions {
public static class Logging {
public static IServiceCollection AddSerilog(this IServiceCollection services) {
var diagnosticContext = new DiagnosticContext(null);

Expand All @@ -13,4 +14,16 @@ public static IServiceCollection AddSerilog(this IServiceCollection services) {
.AddSingleton(diagnosticContext)
.AddSingleton<IDiagnosticContext>(diagnosticContext);
}

public static void ConfigureLog() {
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.MinimumLevel.Override("Grpc", LogEventLevel.Information)
.Enrich.FromLogContext()
.WriteTo.Console(
outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} <s:{SourceContext}>{NewLine}{Exception}"
)
.CreateLogger();
}
}
49 changes: 0 additions & 49 deletions Bookings.Payments/Infrastructure/TestEventListener.cs

This file was deleted.

17 changes: 4 additions & 13 deletions Bookings.Payments/Program.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
using Bookings.Payments;
using Bookings.Payments.Infrastructure;
using Eventuous;
using Serilog;
using Serilog.Events;

using var listener = new TestEventListener();

TypeMap.RegisterKnownEventTypes();
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.MinimumLevel.Override("Grpc", LogEventLevel.Information)
.Enrich.FromLogContext()
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} <s:{SourceContext}>{NewLine}{Exception}")
.CreateLogger();
Logging.ConfigureLog();

var builder = WebApplication.CreateBuilder(args);

Expand All @@ -22,9 +11,11 @@
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddServices();
// OpenTelemetry instrumentation must be added before adding Eventuous services
builder.Services.AddOpenTelemetry();

builder.Services.AddServices();

var app = builder.Build();

if (app.Environment.IsDevelopment()) {
Expand Down
6 changes: 3 additions & 3 deletions Bookings/Bookings.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Eventuous.Diagnostics.OpenTelemetry" Version="0.5.16-alpha.0.9" />
<PackageReference Include="Eventuous.EventStore" Version="0.5.16-alpha.0.9" />
<PackageReference Include="Eventuous.Projections.MongoDB" Version="0.5.16-alpha.0.9" />
<PackageReference Include="Eventuous.Diagnostics.OpenTelemetry" Version="0.5.16-alpha.0.15" />
<PackageReference Include="Eventuous.EventStore" Version="0.5.16-alpha.0.15" />
<PackageReference Include="Eventuous.Projections.MongoDB" Version="0.5.16-alpha.0.15" />
<PackageReference Include="MongoDB.Driver.Core.Extensions.OpenTelemetry" Version="1.0.0" />
<PackageReference Include="OpenTelemetry.Exporter.Prometheus" Version="1.2.0-beta1" />
<PackageReference Include="OpenTelemetry.Exporter.Zipkin" Version="1.2.0-beta1" />
Expand Down
27 changes: 27 additions & 0 deletions Bookings/Infrastructure/ActivityListener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Diagnostics;
using Serilog;

namespace Bookings.Infrastructure;

public sealed class TestActivityListener : IDisposable {
readonly ActivityListener _listener;

public TestActivityListener() {
_listener = new ActivityListener {
ShouldListenTo = _ => true,
Sample = (ref ActivityCreationOptions<ActivityContext> _)
=> ActivitySamplingResult.AllData,
ActivityStarted = activity => Log.Information(
"Started {Activity} with {Id}, parent {ParentId}",
activity.DisplayName,
activity.Id,
activity.ParentId
),
ActivityStopped = activity
=> Log.Information("Stopped {Activity}", activity.DisplayName)
};
ActivitySource.AddActivityListener(_listener);
}

public void Dispose() => _listener.Dispose();
}
5 changes: 3 additions & 2 deletions Bookings/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Serilog.Events;

// using var listener = new TestEventListener();
// using var activityListener = new TestActivityListener();

TypeMap.RegisterKnownEventTypes(typeof(BookingEvents.V1.RoomBooked).Assembly);

Expand All @@ -24,10 +25,10 @@
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddEventuous();

builder.Services.AddOpenTelemetry();

builder.Services.AddEventuous();

var app = builder.Build();

if (app.Environment.IsDevelopment()) {
Expand Down

0 comments on commit 5b20f90

Please sign in to comment.