public TracingMiddleware( [NotNull] RequestDelegate next, [NotNull] IOptions <TracingSettings> options, [NotNull] ITracer tracer) { this.next = next ?? throw new ArgumentNullException(nameof(next)); this.options = (options ?? throw new ArgumentNullException(nameof(options))).Value; this.tracer = tracer ?? throw new ArgumentNullException(nameof(tracer)); }
public SubscriberSettings Create(MqConnectionSettings mqConnectionSettings) { return(new SubscriberSettings( mqConnectionSettings, SubscriberName, QueueName, (Bindings ?? Enumerable.Empty <ExchangeBindingDto>()).Select(b => b.Create()), Arguments, UseModelTypeAsSuffix, ConsumerName, Durable, Exclusive, AutoDelete, AutoAck, UseDeadLetter, UsePublisherConfirms, TracingSettings?.Create(), RetrySettings?.Create(), ScalingSettings?.Create() )); }
/// <summary> /// Получить или сгенерировать TraceId и установить контекст трейсинга. /// </summary> /// <param name="properties">Метаданные сообщения.</param> /// <param name="settings">Настройки трейсинга.</param> /// <param name="logger">Логгер.</param> /// <param name="stubMessage">TraceId из тела сообщения.</param> /// <param name="loggingScope">Скоуп.</param> /// <returns>Идентификатор отслеживания.</returns> public static void EnsureTraceId( this IBasicProperties properties, TracingSettings settings, ILogger logger, ref StubMessage stubMessage, Dictionary <string, object?> loggingScope ) { if (!TryGetTraceInfo(properties, stubMessage.TraceId, out var traceId, out var traceIdSource)) { if (settings.GenerateIfNotPresent) { traceId = Guid.NewGuid(); if (settings.LogWhenGenerated) { using (logger.BeginScope(loggingScope)) { logger.LogInformation("TraceId не указан. Сгенерирован новый {TraceId}.", traceId); } } } } TraceContext.Create(traceId, traceIdSource); loggingScope["TraceId"] = traceId; loggingScope["TraceIdSource"] = traceIdSource; properties.AddTraceId(); if (traceId.HasValue) { stubMessage.TraceId = traceId.Value; } }