-
-
Notifications
You must be signed in to change notification settings - Fork 506
/
EventStoreDBRepositoryWithTelemetryDecorator.cs
45 lines (38 loc) · 1.77 KB
/
EventStoreDBRepositoryWithTelemetryDecorator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
);
}