public async Task InvokeAsync(HttpContext context, ICorrelationIdAccessor correlationIdAccessor) { using (LogContext.Push(new CorrelationIdEnricher(correlationIdAccessor))) { await _next(context); } }
public static void CorrelationId_From_lambda_returns_value() { // Act ICorrelationIdAccessor accessor = CorrelationId.From(() => Guid.NewGuid().ToString("D", CultureInfo.InvariantCulture)); // Assert Assert.True(Guid.TryParse(accessor.CorrelationId, out _)); }
public EventStore(DbContextOptions options, IDateTime dateTime, ICorrelationIdAccessor correlationIdAccessor) : base(options) { ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; _dateTime = dateTime; _correlationIdAccessor = correlationIdAccessor; }
public static void CorrelationId_From_string_returns_value(string expected) { // Arrange ICorrelationIdAccessor accessor = CorrelationId.From(expected); // Act var actual = accessor.CorrelationId; // Assert Assert.Equal(expected, actual); }
public IdentifyingHttpServerEventCallback( ISessionIdAccessor sessionIdAccessor, ICorrelationIdAccessor correlationIdAccessor, IInboundRequestIdAccessor inboundRequestIdAccessor, IApplicationInfo applicationInfo) { _sessionIdAccessor = sessionIdAccessor ?? throw new ArgumentNullException(nameof(sessionIdAccessor)); _correlationIdAccessor = correlationIdAccessor ?? throw new ArgumentNullException(nameof(correlationIdAccessor)); _inboundRequestIdAccessor = inboundRequestIdAccessor ?? throw new ArgumentNullException(nameof(inboundRequestIdAccessor)); _applicationInfo = applicationInfo ?? throw new ArgumentNullException(nameof(applicationInfo)); }
public static void CorrelationId_From_guid_returns_value() { // Arrange var expected = Guid.NewGuid(); ICorrelationIdAccessor accessor = CorrelationId.From(expected); // Act var actual = Guid.Parse(accessor.CorrelationId); // Assert Assert.Equal(expected, actual); }
public CorrelationIdHandlerTests() { _correlationIdAccessor = A.Fake <ICorrelationIdAccessor>(); _underTest = new CorrelationIdHandler(_correlationIdAccessor) { InnerHandler = new DummyInnerHandler() }; _invoker = new HttpMessageInvoker(_underTest); _request = new HttpRequestMessage(HttpMethod.Get, "http://foo.com"); }
public TaggingHttpClientDecorator( ISessionIdAccessor sessionIdAccessor, ICorrelationIdAccessor correlationIdAccessor, IOutboundRequestIdAccessor outboundRequestIdAccessor, IGenerateGuids guidGenerator, IApplicationInfo applicationInfo) { _sessionIdAccessor = sessionIdAccessor; _correlationIdAccessor = correlationIdAccessor; _outboundRequestIdAccessor = outboundRequestIdAccessor; _guidGenerator = guidGenerator; _applicationInfo = applicationInfo; }
protected RepositoryBase(ILogger Logger, ICorrelationIdAccessor CorrelationIdAccessor, ILoggedDatabase Database) { this.Logger = Logger; CorrelationId = CorrelationIdAccessor.GetCorrelationId(); _database = Database; GetContextAsync = async() => { // Return a new, unshared database connection. // Unit of Work classes should modify this Func to return a shared (by multiple repositories) database connection. var connection = await _database.OpenConnectionAsync(CorrelationId); var transaction = connection.BeginTransaction(); return(new RepositoryContext(connection, transaction, true, true)); }; }
public static IHttpClient AddTagging( this IHttpClient httpClient, ISessionIdAccessor sessionIdAccessor, ICorrelationIdAccessor correlationIdAccessor, IOutboundRequestIdAccessor outboundRequestIdAccessor, IGenerateGuids guidGenerator, IApplicationInfo applicationInfo) { return(new TaggingHttpClient( httpClient, sessionIdAccessor, correlationIdAccessor, outboundRequestIdAccessor, guidGenerator, applicationInfo)); }
public TaggingHttpClient( IHttpClient httpClient, ISessionIdAccessor sessionIdGetter, ICorrelationIdAccessor correlationIdGetter, IOutboundRequestIdAccessor outboundRequestIdAccessor, IGenerateGuids guidGenerator, IApplicationInfo applicationInfo) { _httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); _sessionIdAccessor = sessionIdGetter ?? throw new ArgumentNullException(nameof(sessionIdGetter)); _correlationIdAccessor = correlationIdGetter ?? throw new ArgumentNullException(nameof(correlationIdGetter)); _outboundRequestIdAccessor = outboundRequestIdAccessor ?? throw new ArgumentNullException(nameof(outboundRequestIdAccessor)); _guidGenerator = guidGenerator ?? throw new ArgumentNullException(nameof(guidGenerator)); if (applicationInfo == null) { throw new ArgumentNullException(nameof(applicationInfo)); } _userAgent = BuildUserAgent(applicationInfo); }
/// <summary> /// Initializes a new instance of the <see cref="CorrelationIdContextProvider"/> class. /// </summary> /// <param name="accessor">The accessor used to retreive the correlation id.</param> public CorrelationIdContextProvider(ICorrelationIdAccessor accessor) { Accessor = accessor; }
public EventSourcingDistilledDbContext(DbContextOptions options, IDateTime dateTime, ICorrelationIdAccessor correlationIdAccessor) : base(options, dateTime, correlationIdAccessor) { ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; }
public static DisposableHttpClient CreateClientWithTagging(this StubHttpApi api, ISessionIdAccessor sessionIdAccessor, ICorrelationIdAccessor correlationIdAccessor, IOutboundRequestIdAccessor outboundRequestIdAccessor, IGenerateGuids guidGenerator, IApplicationInfo applicationInfo, int timeoutMs = 3000) { var configuration = new InstrumentingConfiguration { Uri = api.BaseUri, TimeoutMs = timeoutMs }; var httpClient = new DefaultHttpClient(configuration); return(new DisposableHttpClient(httpClient, httpClient.AddTagging(sessionIdAccessor, correlationIdAccessor, outboundRequestIdAccessor, guidGenerator, applicationInfo))); }
public DefaultHttpRequestMessageHandler(ICorrelationIdAccessor correlationIdAccessor) { this._correlationIdAccessor = correlationIdAccessor; }
public RequestHandler(ICorrelationIdAccessor correlationIdAccessor, IHttpContextAccessor httpContextAccessor) { this._correlationIdAccessor = correlationIdAccessor; this._httpContextAccessor = httpContextAccessor; }
public async Task InvokeAsync(HttpContext context, ILogger <CorrelationIdMiddleware> logger, ICorrelationIdAccessor correlationIdAccessor) { var correlationIdCreated = false; var correlationId = context.Request.Headers[CorrelationIdHeaderName]; if (correlationId == StringValues.Empty) { correlationId = Guid.NewGuid().ToString(); correlationIdCreated = true; } correlationIdAccessor.Set(correlationId.ToString()); if (correlationIdCreated) { logger.LogDebug($"No {CorrelationIdLogName} found in header. Adding new {CorrelationIdLogName} {correlationId} to context"); } else { logger.LogDebug($"{CorrelationIdLogName} {correlationId} found in header and added to context"); } await _next(context); }
public CorrelationIdHandler(ICorrelationIdAccessor correlationIdAccessor) { _correlationIdAccessor = correlationIdAccessor ?? throw new ArgumentNullException(nameof(correlationIdAccessor)); }
protected UnitOfWorkBase(ILogger Logger, ICorrelationIdAccessor CorrelationIdAccessor, ILoggedDatabase Database) { this.Logger = Logger; CorrelationId = CorrelationIdAccessor.GetCorrelationId(); _database = Database; }
public EventStore(IEventStoreDbContext context, IDateTime dateTime, ICorrelationIdAccessor correlationIdAccessor) { _dateTime = dateTime; _context = context; _correlationIdAccessor = correlationIdAccessor; }
public CorrelationIdMessageHandler(ICorrelationIdAccessor correlationIdAccessor, ILogger <CorrelationIdMessageHandler> logger) { _correlationIdAccessor = correlationIdAccessor; _logger = logger; }
public CorrelationIdEnricher(ICorrelationIdAccessor correlationIdAccessor) { _correlationIdAccessor = correlationIdAccessor; }