-
-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ScrutR to make decorators easier
- Loading branch information
1 parent
b075b07
commit 7d9bd9e
Showing
5 changed files
with
97 additions
and
66 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
45 changes: 45 additions & 0 deletions
45
Core.EventStoreDB/Repository/EventStoreDBRepositoryWithTelemetryDecorator.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,45 @@ | ||
using Core.Aggregates; | ||
using Core.OpenTelemetry; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Core.EventStoreDB.Repository; | ||
|
||
public class EventStoreDBRepositoryWithTelemetryDecorator<T>: IEventStoreDBRepository<T> | ||
where T : class, IAggregate | ||
{ | ||
private readonly IEventStoreDBRepository<T> inner; | ||
private readonly IActivityScope activityScope; | ||
|
||
public EventStoreDBRepositoryWithTelemetryDecorator( | ||
IEventStoreDBRepository<T> inner, | ||
IActivityScope activityScope | ||
) | ||
{ | ||
this.inner = inner; | ||
this.activityScope = activityScope; | ||
} | ||
|
||
public Task<T?> Find(Guid id, CancellationToken cancellationToken) => | ||
inner.Find(id, cancellationToken); | ||
|
||
public Task<ulong> Add(T aggregate, CancellationToken cancellationToken = default) => | ||
activityScope.Run($"EventStoreDBRepository/{nameof(Add)}", | ||
(_, ct) => inner.Add(aggregate, ct), | ||
new StartActivityOptions { Tags = { { TelemetryTags.Logic.Entity, typeof(T).Name } } }, | ||
cancellationToken | ||
); | ||
|
||
public Task<ulong> Update(T aggregate, ulong? expectedVersion = null, CancellationToken token = default) => | ||
activityScope.Run($"EventStoreDBRepository/{nameof(Update)}", | ||
(_, ct) => inner.Update(aggregate, expectedVersion, ct), | ||
new StartActivityOptions { Tags = { { TelemetryTags.Logic.Entity, typeof(T).Name } } }, | ||
token | ||
); | ||
|
||
public Task<ulong> Delete(T aggregate, ulong? expectedVersion = null, CancellationToken token = default) => | ||
activityScope.Run($"EventStoreDBRepository/{nameof(Delete)}", | ||
(_, ct) => inner.Delete(aggregate, expectedVersion, ct), | ||
new StartActivityOptions { Tags = { { TelemetryTags.Logic.Entity, typeof(T).Name } } }, | ||
token | ||
); | ||
} |
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