From 53a751a1480bd1d5187993236d3a49a3d821f452 Mon Sep 17 00:00:00 2001 From: Rafael Andrade Date: Fri, 20 Dec 2024 15:32:34 +0000 Subject: [PATCH 1/2] GH-3419 Add missing JsonSerialisationOptions.Options --- .../MQTTMessageConsumer.cs | 2 +- .../MQTTMessagePublisher.cs | 2 +- .../Logging/Handlers/RequestLoggingHandler.cs | 4 +- .../Handlers/RequestLoggingHandlerAsync.cs | 4 +- .../Observability/BrighterTracer.cs | 216 +++++++++--------- 5 files changed, 117 insertions(+), 111 deletions(-) diff --git a/src/Paramore.Brighter.MessagingGateway.MQTT/MQTTMessageConsumer.cs b/src/Paramore.Brighter.MessagingGateway.MQTT/MQTTMessageConsumer.cs index fc86f69b40..2893de43bc 100644 --- a/src/Paramore.Brighter.MessagingGateway.MQTT/MQTTMessageConsumer.cs +++ b/src/Paramore.Brighter.MessagingGateway.MQTT/MQTTMessageConsumer.cs @@ -58,7 +58,7 @@ public MQTTMessageConsumer(MQTTMessagingGatewayConsumerConfiguration configurati { s_logger.LogInformation("MQTTMessageConsumer: Received message from queue {TopicPrefix}", configuration.TopicPrefix); string message = Encoding.UTF8.GetString(e.ApplicationMessage.Payload); - _messageQueue.Enqueue(JsonSerializer.Deserialize(message)); + _messageQueue.Enqueue(JsonSerializer.Deserialize(message, JsonSerialisationOptions.Options)); }); Task connectTask = Connect(configuration.ConnectionAttempts); diff --git a/src/Paramore.Brighter.MessagingGateway.MQTT/MQTTMessagePublisher.cs b/src/Paramore.Brighter.MessagingGateway.MQTT/MQTTMessagePublisher.cs index 83201e7d69..b815748dcd 100644 --- a/src/Paramore.Brighter.MessagingGateway.MQTT/MQTTMessagePublisher.cs +++ b/src/Paramore.Brighter.MessagingGateway.MQTT/MQTTMessagePublisher.cs @@ -88,7 +88,7 @@ public async Task PublishMessageAsync(Message message) private MqttApplicationMessage createMQTTMessage(Message message) { - string payload = JsonSerializer.Serialize(message); + string payload = JsonSerializer.Serialize(message, JsonSerialisationOptions.Options); MqttApplicationMessageBuilder outMessage = new MqttApplicationMessageBuilder() .WithTopic(_config.TopicPrefix!=null? $"{_config.TopicPrefix}/{message.Header.Topic}": message.Header.Topic) diff --git a/src/Paramore.Brighter/Logging/Handlers/RequestLoggingHandler.cs b/src/Paramore.Brighter/Logging/Handlers/RequestLoggingHandler.cs index 5ef392c1ea..dd315d55be 100644 --- a/src/Paramore.Brighter/Logging/Handlers/RequestLoggingHandler.cs +++ b/src/Paramore.Brighter/Logging/Handlers/RequestLoggingHandler.cs @@ -90,12 +90,12 @@ public override TRequest Fallback(TRequest command) private void LogCommand(TRequest request) { - s_logger.LogInformation("Logging handler pipeline call. Pipeline timing {HandlerTiming} target, for {RequestType} with values of {Request} at: {Time}", _timing.ToString(), typeof(TRequest), JsonSerializer.Serialize(request), DateTime.UtcNow); + s_logger.LogInformation("Logging handler pipeline call. Pipeline timing {HandlerTiming} target, for {RequestType} with values of {Request} at: {Time}", _timing.ToString(), typeof(TRequest), JsonSerializer.Serialize(request, JsonSerialisationOptions.Options), DateTime.UtcNow); } private void LogFailure(TRequest request) { - s_logger.LogInformation("Failure in pipeline call for {RequestType} with values of {Request} at: {Time}", typeof(TRequest), JsonSerializer.Serialize(request), DateTime.UtcNow); + s_logger.LogInformation("Failure in pipeline call for {RequestType} with values of {Request} at: {Time}", typeof(TRequest), JsonSerializer.Serialize(request, JsonSerialisationOptions.Options), DateTime.UtcNow); } } } diff --git a/src/Paramore.Brighter/Logging/Handlers/RequestLoggingHandlerAsync.cs b/src/Paramore.Brighter/Logging/Handlers/RequestLoggingHandlerAsync.cs index 5aada61c6a..7ae40afb79 100644 --- a/src/Paramore.Brighter/Logging/Handlers/RequestLoggingHandlerAsync.cs +++ b/src/Paramore.Brighter/Logging/Handlers/RequestLoggingHandlerAsync.cs @@ -92,13 +92,13 @@ public override async Task FallbackAsync(TRequest command, Cancellatio private void LogCommand(TRequest request) { //TODO: LibLog has no async support, so remains a blocking call for now - s_logger.LogInformation("Logging handler pipeline call. Pipeline timing {HandlerTiming} target, for {RequestType} with values of {Request} at: {Time}", _timing.ToString(), typeof(TRequest), JsonSerializer.Serialize(request), DateTime.UtcNow); + s_logger.LogInformation("Logging handler pipeline call. Pipeline timing {HandlerTiming} target, for {RequestType} with values of {Request} at: {Time}", _timing.ToString(), typeof(TRequest), JsonSerializer.Serialize(request, JsonSerialisationOptions.Options), DateTime.UtcNow); } private void LogFailure(TRequest request) { //TODO: LibLog has no async support, so remains a blocking call for now - s_logger.LogInformation("Failure in pipeline call for {RequestType} with values of {Request} at: {Time}", typeof(TRequest), JsonSerializer.Serialize(request), DateTime.UtcNow); + s_logger.LogInformation("Failure in pipeline call for {RequestType} with values of {Request} at: {Time}", typeof(TRequest), JsonSerializer.Serialize(request, JsonSerialisationOptions.Options), DateTime.UtcNow); } } } diff --git a/src/Paramore.Brighter/Observability/BrighterTracer.cs b/src/Paramore.Brighter/Observability/BrighterTracer.cs index d21424b8f0..87196d71bc 100644 --- a/src/Paramore.Brighter/Observability/BrighterTracer.cs +++ b/src/Paramore.Brighter/Observability/BrighterTracer.cs @@ -24,7 +24,6 @@ THE SOFTWARE. */ #endregion using OpenTelemetry.Trace; - using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -73,20 +72,20 @@ public void Dispose() /// public void AddExceptionToSpan(Activity? span, IEnumerable exceptions) { - if (span == null ) return; + if (span == null) return; var exceptionList = exceptions.ToArray(); - + if (exceptionList.Length == 0) return; - - if (exceptionList .Length == 1) + + if (exceptionList.Length == 1) { span.AddException(exceptionList[0]); span.SetStatus(ActivityStatusCode.Error, exceptionList[0].Message); return; } - var exception = new AggregateException("Operation failed, see inner exceptions for details", exceptionList); + var exception = new AggregateException("Operation failed, see inner exceptions for details", exceptionList); span.AddException(exception); span.SetStatus(ActivityStatusCode.Error, exception.Message); } @@ -101,10 +100,10 @@ public void AddExceptionToSpan(Activity? span, IEnumerable exceptions /// The for how deep should the instrumentation go /// A span for the current request named request.name operation.name public Activity? CreateSpan( - CommandProcessorSpanOperation operation, - TRequest request, + CommandProcessorSpanOperation operation, + TRequest request, Activity? parentActivity = null, - ActivityLink[]? links = null, + ActivityLink[]? links = null, InstrumentationOptions options = InstrumentationOptions.All ) where TRequest : class, IRequest { @@ -117,7 +116,10 @@ public void AddExceptionToSpan(Activity? span, IEnumerable exceptions { { BrighterSemanticConventions.RequestId, request.Id }, { BrighterSemanticConventions.RequestType, request.GetType().Name }, - { BrighterSemanticConventions.RequestBody, JsonSerializer.Serialize(request) }, + { + BrighterSemanticConventions.RequestBody, + JsonSerializer.Serialize(request, JsonSerialisationOptions.Options) + }, { BrighterSemanticConventions.Operation, operation.ToSpanName() } }; @@ -128,7 +130,7 @@ public void AddExceptionToSpan(Activity? span, IEnumerable exceptions tags: tags, links: links, startTime: now); - + Activity.Current = activity; return activity; @@ -143,10 +145,10 @@ public void AddExceptionToSpan(Activity? span, IEnumerable exceptions /// The for how deep should the instrumentation go /// public Activity? CreateSpan( - MessagePumpSpanOperation operation, - Message message, - MessagingSystem messagingSystem, - InstrumentationOptions options = InstrumentationOptions.All + MessagePumpSpanOperation operation, + Message message, + MessagingSystem messagingSystem, + InstrumentationOptions options = InstrumentationOptions.All ) { var spanName = $"{message.Header.Topic} {operation.ToSpanName()}"; @@ -163,29 +165,28 @@ public void AddExceptionToSpan(Activity? span, IEnumerable exceptions { BrighterSemanticConventions.MessageType, message.Header.MessageType.ToString() }, { BrighterSemanticConventions.MessageBodySize, message.Body.Bytes.Length }, { BrighterSemanticConventions.MessageBody, message.Body.Value }, - { BrighterSemanticConventions.MessageHeaders, JsonSerializer.Serialize(message.Header) }, + { BrighterSemanticConventions.MessageHeaders, JsonSerializer.Serialize(message.Header, JsonSerialisationOptions.Options) }, { BrighterSemanticConventions.ConversationId, message.Header.CorrelationId }, { BrighterSemanticConventions.MessagingSystem, messagingSystem.ToMessagingSystemName() }, { BrighterSemanticConventions.CeMessageId, message.Id }, { BrighterSemanticConventions.CeSource, message.Header.Source }, - { BrighterSemanticConventions.CeVersion, "1.0"}, + { BrighterSemanticConventions.CeVersion, "1.0" }, { BrighterSemanticConventions.CeSubject, message.Header.Subject }, - { BrighterSemanticConventions.CeType, message.Header.Type}, + { BrighterSemanticConventions.CeType, message.Header.Type }, { BrighterSemanticConventions.ReplyTo, message.Header.ReplyTo }, { BrighterSemanticConventions.HandledCount, message.Header.HandledCount } - }; - + var activity = ActivitySource.StartActivity( name: spanName, kind: kind, parentId: parentId, tags: tags, startTime: now); - - + + activity?.AddBaggage("correlationId", message.Header.CorrelationId); - + Activity.Current = activity; return activity; @@ -200,13 +201,13 @@ public void AddExceptionToSpan(Activity? span, IEnumerable exceptions /// A span (or dotnet Activity) for the current request named request.name operation.name public Activity? CreateBatchSpan( Activity? parentActivity = null, - ActivityLink[]? links = null, + ActivityLink[]? links = null, InstrumentationOptions options = InstrumentationOptions.All ) where TRequest : class, IRequest { var requestType = typeof(TRequest); var operation = CommandProcessorSpanOperation.Create; - + var spanName = $"{requestType.Name} {operation.ToSpanName()}"; var kind = ActivityKind.Internal; var parentId = parentActivity?.Id; @@ -225,7 +226,7 @@ public void AddExceptionToSpan(Activity? span, IEnumerable exceptions tags: tags, links: links, startTime: now); - + Activity.Current = activity; return activity; @@ -247,7 +248,7 @@ public void AddExceptionToSpan(Activity? span, IEnumerable exceptions { if (operation != MessagePumpSpanOperation.Begin) throw new ArgumentOutOfRangeException(nameof(operation), "Operation must be Begin or End"); - + var spanName = $"{topic} {operation.ToSpanName()}"; var kind = ActivityKind.Consumer; var now = _timeProvider.GetUtcNow(); @@ -258,13 +259,14 @@ public void AddExceptionToSpan(Activity? span, IEnumerable exceptions { BrighterSemanticConventions.MessagingDestination, topic }, { BrighterSemanticConventions.Operation, operation.ToSpanName() } }; - - Activity? activity = ActivitySource.StartActivity(kind: kind, tags: tags, links: null, startTime: now, name: spanName); - - if(activity is not null) + + Activity? activity = + ActivitySource.StartActivity(kind: kind, tags: tags, links: null, startTime: now, name: spanName); + + if (activity is not null) Activity.Current = activity; - return activity; + return activity; } /// @@ -295,17 +297,19 @@ public void AddExceptionToSpan(Activity? span, IEnumerable exceptions { BrighterSemanticConventions.MessagingDestination, topic }, { BrighterSemanticConventions.Operation, operation.ToSpanName() } }; - - Activity? activity; + + Activity? activity; if (Activity.Current != null) - activity = ActivitySource.StartActivity(name: spanName, kind: kind, parentContext: Activity.Current.Context, tags: tags, links: null, now); + activity = ActivitySource.StartActivity(name: spanName, kind: kind, parentContext: Activity.Current.Context, + tags: tags, links: null, now); else - activity = ActivitySource.StartActivity(kind: kind, tags: tags, links: null, startTime: now, name: spanName); - + activity = ActivitySource.StartActivity(kind: kind, tags: tags, links: null, startTime: now, + name: spanName); + activity?.AddException(messagePumpException); activity?.SetStatus(ActivityStatusCode.Error, messagePumpException.Message); - - if(activity is not null) + + if (activity is not null) Activity.Current = activity; return activity; @@ -328,22 +332,21 @@ public void AddExceptionToSpan(Activity? span, IEnumerable exceptions var spanName = $"{BrighterSemanticConventions.ArchiveMessages} {operation.ToSpanName()}"; var kind = ActivityKind.Producer; var parentId = parentActivity?.Id; - var now = _timeProvider.GetUtcNow(); + var now = _timeProvider.GetUtcNow(); var tags = new ActivityTagsCollection() - { { BrighterSemanticConventions.Operation, operation.ToSpanName() }, { BrighterSemanticConventions.ArchiveAge, dispatchedSince.TotalMilliseconds } }; - + var activity = ActivitySource.StartActivity( name: spanName, kind: kind, parentId: parentId, tags: tags, startTime: now); - - Activity.Current = activity; + + Activity.Current = activity; return activity; } @@ -365,27 +368,26 @@ public void AddExceptionToSpan(Activity? span, IEnumerable exceptions var spanName = $"{BrighterSemanticConventions.ClearMessages} {operation.ToSpanName()}"; var kind = ActivityKind.Producer; var parentId = parentActivity?.Id; - var now = _timeProvider.GetUtcNow(); - + var now = _timeProvider.GetUtcNow(); + var tags = new ActivityTagsCollection { { BrighterSemanticConventions.Operation, CommandProcessorSpanOperation.Clear.ToSpanName() } }; - + if (!string.IsNullOrEmpty(messageId)) tags.Add(BrighterSemanticConventions.MessageId, messageId); - + var activity = ActivitySource.StartActivity( name: spanName, kind: kind, parentId: parentId, tags: tags, startTime: now); - + Activity.Current = activity; return activity; - - } + } /// /// Create a span for an outbox operation @@ -396,9 +398,10 @@ public void AddExceptionToSpan(Activity? span, IEnumerable exceptions /// /// A new span named either db.operation db.name db.sql.table or db.operation db.name if db.sql.table not available public Activity? CreateDbSpan(OutboxSpanInfo info, Activity? parentActivity, InstrumentationOptions options) { - var spanName = !string.IsNullOrEmpty(info.dbTable) - ? $"{info.dbOperation.ToSpanName()} {info.dbName} {info.dbTable}" : $"{info.dbOperation} {info.dbName}"; - + var spanName = !string.IsNullOrEmpty(info.dbTable) + ? $"{info.dbOperation.ToSpanName()} {info.dbName} {info.dbTable}" + : $"{info.dbOperation} {info.dbName}"; + var kind = ActivityKind.Client; var parentId = parentActivity?.Id; var now = _timeProvider.GetUtcNow(); @@ -411,17 +414,21 @@ public void AddExceptionToSpan(Activity? span, IEnumerable exceptions { BrighterSemanticConventions.DbSystem, info.dbSystem.ToDbName() } }; - if (!string.IsNullOrEmpty(info.dbStatement)) tags.Add(BrighterSemanticConventions.DbStatement, info.dbStatement); - if (!string.IsNullOrEmpty(info.dbInstanceId)) tags.Add(BrighterSemanticConventions.DbInstanceId, info.dbInstanceId); + if (!string.IsNullOrEmpty(info.dbStatement)) + tags.Add(BrighterSemanticConventions.DbStatement, info.dbStatement); + if (!string.IsNullOrEmpty(info.dbInstanceId)) + tags.Add(BrighterSemanticConventions.DbInstanceId, info.dbInstanceId); if (!string.IsNullOrEmpty(info.dbUser)) tags.Add(BrighterSemanticConventions.DbUser, info.dbUser); - if (!string.IsNullOrEmpty(info.networkPeerAddress)) tags.Add(BrighterSemanticConventions.NetworkPeerAddress, info.networkPeerAddress); - if (!string.IsNullOrEmpty(info.serverAddress)) tags.Add(BrighterSemanticConventions.ServerAddress, info.serverAddress); + if (!string.IsNullOrEmpty(info.networkPeerAddress)) + tags.Add(BrighterSemanticConventions.NetworkPeerAddress, info.networkPeerAddress); + if (!string.IsNullOrEmpty(info.serverAddress)) + tags.Add(BrighterSemanticConventions.ServerAddress, info.serverAddress); if (info.networkPeerPort != 0) tags.Add(BrighterSemanticConventions.NetworkPeerPort, info.networkPeerPort); if (info.serverPort != 0) tags.Add(BrighterSemanticConventions.ServerPort, info.serverPort); - + if (info.dbAttributes != null) - foreach (var pair in info.dbAttributes) - tags.Add(pair.Key, pair.Value); + foreach (var pair in info.dbAttributes) + tags.Add(pair.Key, pair.Value); var activity = ActivitySource.StartActivity( name: spanName, @@ -429,7 +436,7 @@ public void AddExceptionToSpan(Activity? span, IEnumerable exceptions parentId: parentId, tags: tags, startTime: now); - + Activity.Current = activity; return activity; @@ -444,14 +451,14 @@ public void AddExceptionToSpan(Activity? span, IEnumerable exceptions /// The for how deep should the instrumentation go? /// A new span named channel publish public Activity? CreateProducerSpan( - Publication publication, - Message? message, + Publication publication, + Message? message, Activity? parentActivity, InstrumentationOptions instrumentationOptions = InstrumentationOptions.All ) { var spanName = $"{publication.Topic} {CommandProcessorSpanOperation.Publish.ToSpanName()}"; - + var kind = ActivityKind.Producer; var parentId = parentActivity?.Id; var now = _timeProvider.GetUtcNow(); @@ -460,7 +467,7 @@ public void AddExceptionToSpan(Activity? span, IEnumerable exceptions { //OTel specification attributes { BrighterSemanticConventions.MessagingOperationType, CommandProcessorSpanOperation.Publish.ToSpanName() }, - + //cloud events attributes { BrighterSemanticConventions.CeSource, publication.Source }, { BrighterSemanticConventions.CeVersion, "1.0" }, @@ -477,9 +484,9 @@ public void AddExceptionToSpan(Activity? span, IEnumerable exceptions tags.Add(BrighterSemanticConventions.MessagingDestinationPartitionId, message.Header.PartitionKey); tags.Add(BrighterSemanticConventions.MessageBodySize, message.Body.Bytes.Length); tags.Add(BrighterSemanticConventions.MessageBody, message.Body.Value); - tags.Add(BrighterSemanticConventions.MessageHeaders, JsonSerializer.Serialize(message.Header)); - tags.Add(BrighterSemanticConventions.ConversationId, message.Header.CorrelationId); - + tags.Add(BrighterSemanticConventions.MessageHeaders, JsonSerializer.Serialize(message.Header, JsonSerialisationOptions.Options)); + tags.Add(BrighterSemanticConventions.ConversationId, message.Header.CorrelationId); + //cloud events attributes tags.Add(BrighterSemanticConventions.CeMessageId, message.Id); } @@ -490,10 +497,10 @@ public void AddExceptionToSpan(Activity? span, IEnumerable exceptions parentId: parentId, tags: tags, startTime: now); - + Activity.Current = activity; - return activity; + return activity; } /// @@ -509,7 +516,7 @@ public void AddExceptionToSpan(Activity? span, IEnumerable exceptions public static void WriteHandlerEvent(Activity? span, string handlerName, bool isAsync, bool isSink = false) { if (span == null) return; - + var tags = new ActivityTagsCollection { { BrighterSemanticConventions.HandlerName, handlerName }, @@ -532,15 +539,15 @@ public static void WriteHandlerEvent(Activity? span, string handlerName, bool is /// Is this an async pipeline? /// Is this the mapper, true, or a transform, false? public static void WriteMapperEvent( - Message message, - Publication publication, - Activity? span, + Message message, + Publication publication, + Activity? span, string mapperName, bool isAsync, bool isSink = false) { if (span == null) return; - + var tags = new ActivityTagsCollection { { BrighterSemanticConventions.MapperName, mapperName }, @@ -551,7 +558,7 @@ public static void WriteMapperEvent( { BrighterSemanticConventions.MessagingDestinationPartitionId, message.Header.PartitionKey }, { BrighterSemanticConventions.MessageBodySize, message.Body.Bytes.Length }, { BrighterSemanticConventions.MessageBody, message.Body.Value }, - { BrighterSemanticConventions.MessageHeaders, JsonSerializer.Serialize(message.Header) } + { BrighterSemanticConventions.MessageHeaders, JsonSerializer.Serialize(message.Header, JsonSerialisationOptions.Options) } }; span.AddEvent(new ActivityEvent(mapperName, DateTimeOffset.UtcNow, tags)); @@ -569,18 +576,18 @@ public static void WriteMapperEvent( /// Is the handler writing async? /// for how verbose should our instrumentation be public static void WriteOutboxEvent( - OutboxDbOperation operation, - Message message, + OutboxDbOperation operation, + Message message, Activity? span, - bool isSharedTransaction, - bool isAsync, + bool isSharedTransaction, + bool isAsync, InstrumentationOptions instrumentationOptions - ) + ) { if (span == null) return; - + var outBoxType = isAsync ? "async" : "sync"; - + var tags = new ActivityTagsCollection { { BrighterSemanticConventions.OutboxSharedTransaction, isSharedTransaction }, @@ -591,13 +598,12 @@ InstrumentationOptions instrumentationOptions { BrighterSemanticConventions.MessageBody, message.Body.Value }, { BrighterSemanticConventions.MessageType, message.Header.MessageType.ToString() }, { BrighterSemanticConventions.MessagingDestinationPartitionId, message.Header.PartitionKey }, - { BrighterSemanticConventions.MessageHeaders, JsonSerializer.Serialize(message.Header) } + { BrighterSemanticConventions.MessageHeaders, JsonSerializer.Serialize(message.Header, JsonSerialisationOptions.Options) } }; span.AddEvent(new ActivityEvent(operation.ToSpanName(), DateTimeOffset.UtcNow, tags)); - } - + /// /// Create an event representing the external service bus calling the outbox /// This is generic and not specific details from a particular outbox and is thus mostly message properties @@ -610,17 +616,17 @@ InstrumentationOptions instrumentationOptions /// Is this an async operation /// What have we set to control verbosity public static void WriteOutboxEvent( - OutboxDbOperation operation, - IEnumerable messages, - Activity? span, - bool isSharedTransaction, - bool isAsync, + OutboxDbOperation operation, + IEnumerable messages, + Activity? span, + bool isSharedTransaction, + bool isAsync, InstrumentationOptions instrumentationOptions) { if (span == null) return; - + foreach (var message in messages) - WriteOutboxEvent(operation, message, span, isSharedTransaction, isAsync, instrumentationOptions); + WriteOutboxEvent(operation, message, span, isSharedTransaction, isAsync, instrumentationOptions); } /// @@ -634,30 +640,32 @@ public static void WriteOutboxEvent( public static void WriteProducerEvent(Activity? span, MessagingSystem messagingSystem, Message message) { if (span == null) return; - + var tags = new ActivityTagsCollection { - { BrighterSemanticConventions.MessagingOperationType, CommandProcessorSpanOperation.Publish.ToSpanName() }, + { + BrighterSemanticConventions.MessagingOperationType, CommandProcessorSpanOperation.Publish.ToSpanName() + }, { BrighterSemanticConventions.MessagingSystem, messagingSystem.ToMessagingSystemName() }, { BrighterSemanticConventions.MessagingDestination, message.Header.Topic }, { BrighterSemanticConventions.MessagingDestinationPartitionId, message.Header.PartitionKey }, { BrighterSemanticConventions.MessageId, message.Id }, - { BrighterSemanticConventions.MessageHeaders, JsonSerializer.Serialize(message.Header) }, + { BrighterSemanticConventions.MessageHeaders, JsonSerializer.Serialize(message.Header, JsonSerialisationOptions.Options) }, { BrighterSemanticConventions.MessageType, message.Header.MessageType.ToString() }, { BrighterSemanticConventions.MessageBodySize, message.Body.Bytes.Length }, { BrighterSemanticConventions.MessageBody, message.Body.Value }, { BrighterSemanticConventions.ConversationId, message.Header.CorrelationId }, - { BrighterSemanticConventions.CeMessageId, message.Id }, { BrighterSemanticConventions.CeSource, message.Header.Source }, - { BrighterSemanticConventions.CeVersion, "1.0"}, + { BrighterSemanticConventions.CeVersion, "1.0" }, { BrighterSemanticConventions.CeSubject, message.Header.Subject }, { BrighterSemanticConventions.CeType, message.Header.Type } }; - span.AddEvent(new ActivityEvent($"{message.Header.Topic} {CommandProcessorSpanOperation.Publish.ToSpanName()}", DateTimeOffset.UtcNow, tags)); + span.AddEvent(new ActivityEvent($"{message.Header.Topic} {CommandProcessorSpanOperation.Publish.ToSpanName()}", + DateTimeOffset.UtcNow, tags)); } - + /// /// Ends a span by correctly setting its status and then disposing of it /// @@ -676,7 +684,7 @@ public void EndSpan(Activity? span) public void EndSpans(ConcurrentDictionary handlerSpans) { if (!handlerSpans.Any()) return; - + foreach (var handlerSpan in handlerSpans) { EndSpan(handlerSpan.Value); @@ -691,7 +699,7 @@ public void EndSpans(ConcurrentDictionary handlerSpans) public void LinkSpans(ConcurrentDictionary handlerSpans) { if (!handlerSpans.Any()) return; - + var handlerNames = handlerSpans.Keys.ToList(); foreach (var handlerName in handlerNames) { @@ -706,6 +714,4 @@ public void LinkSpans(ConcurrentDictionary handlerSpans) } } } - - } From f0e0189bfc15e50129d9826ea2f110f20c8a25ff Mon Sep 17 00:00:00 2001 From: Rafael Andrade Date: Wed, 8 Jan 2025 15:13:22 +0000 Subject: [PATCH 2/2] GH-3419 fixes unit tests --- .../When_Clearing_A_Message_A_Span_Is_Exported.cs | 4 ++-- ...en_Clearing_A_Message_A_Span_Is_Exported_Async.cs | 4 ++-- .../When_Depositing_A_Request_A_Span_Is_Exported.cs | 2 +- ..._Depositing_A_Request_A_Span_Is_Exported_Async.cs | 2 +- ...epositing_Multiple_Requests_Spans_Are_Exported.cs | 2 +- ...ing_Multiple_Requests_Spans_Are_Exported_Async.cs | 2 +- .../When_Publishing_A_Request_A_Span_Is_Exported.cs | 12 ++++++------ ...n_Publishing_A_Request_A_Span_Is_Exported_Asyn.cs | 12 ++++++------ .../When_Sending_A_Request_A_Span_Is_Exported.cs | 6 +++--- ...hen_Sending_A_Request_A_Span_Is_Exported_Async.cs | 6 +++--- ...ssage_Mapper_Add_Brighter_Semantic_Conventions.cs | 2 +- ...ating_A_Span_Add_Brighter_Semantic_Conventions.cs | 4 ++-- ...A_Message_Is_Dispatched_It_Should_Begin_A_Span.cs | 2 +- 13 files changed, 30 insertions(+), 30 deletions(-) diff --git a/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Clear/When_Clearing_A_Message_A_Span_Is_Exported.cs b/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Clear/When_Clearing_A_Message_A_Span_Is_Exported.cs index 3656ddae8a..5ae9f6c1b0 100644 --- a/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Clear/When_Clearing_A_Message_A_Span_Is_Exported.cs +++ b/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Clear/When_Clearing_A_Message_A_Span_Is_Exported.cs @@ -168,7 +168,7 @@ public void When_Clearing_A_Message_A_Span_Is_Exported() producerActivity.TagObjects.Any(t => t.Key == BrighterSemanticConventions.MessageType && t.Value as string == message.Header.MessageType.ToString()).Should().BeTrue(); producerActivity.TagObjects.Any(t => t is { Value: not null, Key: BrighterSemanticConventions.MessagingDestination } && t.Value.ToString() == "MyEvent").Should().BeTrue(); producerActivity.TagObjects.Any(t => t.Key == BrighterSemanticConventions.MessagingDestinationPartitionId && t.Value as string == message.Header.PartitionKey).Should().BeTrue(); - producerActivity.TagObjects.Any(t => t.Key == BrighterSemanticConventions.MessageHeaders && (string)t.Value == JsonSerializer.Serialize(message.Header)).Should().BeTrue(); + producerActivity.TagObjects.Any(t => t.Key == BrighterSemanticConventions.MessageHeaders && (string)t.Value == JsonSerializer.Serialize(message.Header, JsonSerialisationOptions.Options)).Should().BeTrue(); producerActivity.TagObjects.Any(t => t is { Value: not null, Key: BrighterSemanticConventions.MessageBodySize } && (int)t.Value == message.Body.Bytes.Length).Should().BeTrue(); producerActivity.TagObjects.Any(t => t.Key == BrighterSemanticConventions.MessageBody && t.Value as string == message.Body.Value).Should().BeTrue(); producerActivity.TagObjects.Any(t => t.Key == BrighterSemanticConventions.ConversationId && t.Value as string == message.Header.CorrelationId).Should().BeTrue(); @@ -187,7 +187,7 @@ public void When_Clearing_A_Message_A_Span_Is_Exported() produceEvent.Tags.Any(t => t.Key == BrighterSemanticConventions.MessagingDestinationPartitionId && (string)t.Value == message.Header.PartitionKey).Should().BeTrue(); produceEvent.Tags.Any(t => t.Key == BrighterSemanticConventions.MessageId && (string)t.Value == message.Id).Should().BeTrue(); produceEvent.Tags.Any(t => t.Key == BrighterSemanticConventions.MessageType && (string)t.Value == message.Header.MessageType.ToString()).Should().BeTrue(); - produceEvent.Tags.Any(t => t.Key == BrighterSemanticConventions.MessageHeaders && (string)t.Value == JsonSerializer.Serialize(message.Header)).Should().BeTrue(); + produceEvent.Tags.Any(t => t.Key == BrighterSemanticConventions.MessageHeaders && (string)t.Value == JsonSerializer.Serialize(message.Header, JsonSerialisationOptions.Options)).Should().BeTrue(); produceEvent.Tags.Any(t => t is { Value: not null, Key: BrighterSemanticConventions.MessageBodySize } && (int)t.Value == message.Body.Bytes.Length).Should().BeTrue(); produceEvent.Tags.Any(t => t.Key == BrighterSemanticConventions.MessageBody && (string)t.Value == message.Body.Value).Should().BeTrue(); produceEvent.Tags.Any(t => t.Key == BrighterSemanticConventions.ConversationId && (string)t.Value == message.Header.CorrelationId).Should().BeTrue(); diff --git a/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Clear/When_Clearing_A_Message_A_Span_Is_Exported_Async.cs b/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Clear/When_Clearing_A_Message_A_Span_Is_Exported_Async.cs index fced18f4a6..1c59e33392 100644 --- a/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Clear/When_Clearing_A_Message_A_Span_Is_Exported_Async.cs +++ b/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Clear/When_Clearing_A_Message_A_Span_Is_Exported_Async.cs @@ -169,7 +169,7 @@ public async Task When_Clearing_A_Message_A_Span_Is_Exported() producerActivity.TagObjects.Any(t => t.Key == BrighterSemanticConventions.MessageType && t.Value as string == message.Header.MessageType.ToString()).Should().BeTrue(); producerActivity.TagObjects.Any(t => t is { Value: not null, Key: BrighterSemanticConventions.MessagingDestination } && t.Value.ToString() == _topic.Value.ToString()).Should().BeTrue(); producerActivity.TagObjects.Any(t => t.Key == BrighterSemanticConventions.MessagingDestinationPartitionId && t.Value as string == message.Header.PartitionKey).Should().BeTrue(); - producerActivity.TagObjects.Any(t => t.Key == BrighterSemanticConventions.MessageHeaders && t.Value as string == JsonSerializer.Serialize(message.Header)).Should().BeTrue(); + producerActivity.TagObjects.Any(t => t.Key == BrighterSemanticConventions.MessageHeaders && t.Value as string == JsonSerializer.Serialize(message.Header, JsonSerialisationOptions.Options)).Should().BeTrue(); producerActivity.TagObjects.Any(t => t is { Value: not null, Key: BrighterSemanticConventions.MessageBodySize } && (int)t.Value == message.Body.Bytes.Length).Should().BeTrue(); producerActivity.TagObjects.Any(t => t.Key == BrighterSemanticConventions.MessageBody && t.Value as string == message.Body.Value).Should().BeTrue(); producerActivity.TagObjects.Any(t => t.Key == BrighterSemanticConventions.ConversationId && t.Value as string == message.Header.CorrelationId).Should().BeTrue(); @@ -188,7 +188,7 @@ public async Task When_Clearing_A_Message_A_Span_Is_Exported() produceEvent.Tags.Any(t => t.Key == BrighterSemanticConventions.MessagingDestinationPartitionId && t.Value as string == message.Header.PartitionKey).Should().BeTrue(); produceEvent.Tags.Any(t => t.Key == BrighterSemanticConventions.MessageId && t.Value as string == message.Id).Should().BeTrue(); produceEvent.Tags.Any(t => t.Key == BrighterSemanticConventions.MessageType && t.Value as string == message.Header.MessageType.ToString()).Should().BeTrue(); - produceEvent.Tags.Any(t => t.Key == BrighterSemanticConventions.MessageHeaders && t.Value as string == JsonSerializer.Serialize(message.Header)).Should().BeTrue(); + produceEvent.Tags.Any(t => t.Key == BrighterSemanticConventions.MessageHeaders && t.Value as string == JsonSerializer.Serialize(message.Header, JsonSerialisationOptions.Options)).Should().BeTrue(); produceEvent.Tags.Any(t => t is { Value: not null, Key: BrighterSemanticConventions.MessageBodySize } && (int)t.Value == message.Body.Bytes.Length).Should().BeTrue(); produceEvent.Tags.Any(t => t.Key == BrighterSemanticConventions.MessageBody && t.Value as string == message.Body.Value).Should().BeTrue(); produceEvent.Tags.Any(t => t.Key == BrighterSemanticConventions.ConversationId && t.Value as string == message.Header.CorrelationId).Should().BeTrue(); diff --git a/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Deposit/When_Depositing_A_Request_A_Span_Is_Exported.cs b/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Deposit/When_Depositing_A_Request_A_Span_Is_Exported.cs index 1ad5671dad..c5b83cf78e 100644 --- a/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Deposit/When_Depositing_A_Request_A_Span_Is_Exported.cs +++ b/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Deposit/When_Depositing_A_Request_A_Span_Is_Exported.cs @@ -117,7 +117,7 @@ public void When_Depositing_A_Request_A_Span_Is_Exported() depositActivity.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestId && t.Value == @event.Id).Should().BeTrue(); depositActivity.Tags.Any(t => t is { Key: BrighterSemanticConventions.RequestType, Value: nameof(MyEvent) }).Should().BeTrue(); - depositActivity.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(@event)).Should().BeTrue(); + depositActivity.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(@event, JsonSerialisationOptions.Options)).Should().BeTrue(); depositActivity.Tags.Any(t => t is { Key: BrighterSemanticConventions.Operation, Value: "deposit" }).Should().BeTrue(); var events = depositActivity.Events.ToList(); diff --git a/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Deposit/When_Depositing_A_Request_A_Span_Is_Exported_Async.cs b/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Deposit/When_Depositing_A_Request_A_Span_Is_Exported_Async.cs index d501b91e83..f3aefbcb34 100644 --- a/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Deposit/When_Depositing_A_Request_A_Span_Is_Exported_Async.cs +++ b/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Deposit/When_Depositing_A_Request_A_Span_Is_Exported_Async.cs @@ -119,7 +119,7 @@ public async Task When_Depositing_A_Request_A_Span_Is_Exported() depositActivity.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestId && t.Value == @event.Id).Should().BeTrue(); depositActivity.Tags.Any(t => t is { Key: BrighterSemanticConventions.RequestType, Value: nameof(MyEvent) }).Should().BeTrue(); - depositActivity.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(@event)).Should().BeTrue(); + depositActivity.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(@event, JsonSerialisationOptions.Options)).Should().BeTrue(); depositActivity.Tags.Any(t => t is { Key: BrighterSemanticConventions.Operation, Value: "deposit" }).Should().BeTrue(); var events = depositActivity.Events.ToList(); diff --git a/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Deposit/When_Depositing_Multiple_Requests_Spans_Are_Exported.cs b/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Deposit/When_Depositing_Multiple_Requests_Spans_Are_Exported.cs index 4e09ac05b3..e3a848f524 100644 --- a/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Deposit/When_Depositing_Multiple_Requests_Spans_Are_Exported.cs +++ b/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Deposit/When_Depositing_Multiple_Requests_Spans_Are_Exported.cs @@ -130,7 +130,7 @@ public void When_Depositing_A_Request_A_Span_Is_Exported() depositActivity.ParentId.Should().Be(createActivity.Id); depositActivity.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestId && t.Value == events[i].Id).Should().BeTrue(); - depositActivity.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(events[i])).Should().BeTrue(); + depositActivity.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(events[i], JsonSerialisationOptions.Options)).Should().BeTrue(); } //TODO: When we deposit multiple we do a bulk write to the Outbox, so we should expect to see a bulk operation at the Db level diff --git a/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Deposit/When_Depositing_Multiple_Requests_Spans_Are_Exported_Async.cs b/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Deposit/When_Depositing_Multiple_Requests_Spans_Are_Exported_Async.cs index 84fec391b0..3eeb425bd3 100644 --- a/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Deposit/When_Depositing_Multiple_Requests_Spans_Are_Exported_Async.cs +++ b/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Deposit/When_Depositing_Multiple_Requests_Spans_Are_Exported_Async.cs @@ -131,7 +131,7 @@ public async Task When_Depositing_A_Request_A_Span_Is_Exported() depositActivity.ParentId.Should().Be(createActivity.Id); depositActivity.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestId && t.Value == events[i].Id).Should().BeTrue(); - depositActivity.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(events[i])).Should().BeTrue(); + depositActivity.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(events[i], JsonSerialisationOptions.Options)).Should().BeTrue(); } //TODO: When we deposit multiple we do a bulk write to the Outbox, so we should expect to see a bulk operation at the Db level diff --git a/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Publish/When_Publishing_A_Request_A_Span_Is_Exported.cs b/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Publish/When_Publishing_A_Request_A_Span_Is_Exported.cs index 35756e9cba..e5acc3b852 100644 --- a/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Publish/When_Publishing_A_Request_A_Span_Is_Exported.cs +++ b/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Publish/When_Publishing_A_Request_A_Span_Is_Exported.cs @@ -104,7 +104,7 @@ public void When_Publishing_A_Request_With_Span_In_Context_Child_Spans_Are_Expor first.ParentId.Should().Be(createActivity.Id); first.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestId && t.Value == @event.Id).Should().BeTrue(); first.Tags.Any(t => t is { Key: BrighterSemanticConventions.RequestType, Value: nameof(MyEvent) }).Should().BeTrue(); - first.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(@event)).Should().BeTrue(); + first.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(@event, JsonSerialisationOptions.Options)).Should().BeTrue(); first.Tags.Any(t => t is { Key: BrighterSemanticConventions.Operation, Value: "publish" }).Should().BeTrue(); var activityEvent = first.Events.Single(e => e.Name == nameof(MyEventHandler) || e.Name == nameof(MyOtherEventHandler)); @@ -117,7 +117,7 @@ public void When_Publishing_A_Request_With_Span_In_Context_Child_Spans_Are_Expor second.ParentId.Should().Be(createActivity.Id); second.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestId && t.Value == @event.Id).Should().BeTrue(); second.Tags.Any(t => t is { Key: BrighterSemanticConventions.RequestType, Value: nameof(MyEvent) }).Should().BeTrue(); - second.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(@event)).Should().BeTrue(); + second.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(@event, JsonSerialisationOptions.Options)).Should().BeTrue(); second.Tags.Any(t => t is { Key: BrighterSemanticConventions.Operation, Value: "publish" }).Should().BeTrue(); activityEvent = second.Events.Single(e => e.Name == nameof(MyEventHandler) || e.Name == nameof(MyOtherEventHandler)); @@ -168,7 +168,7 @@ public void When_Publishing_A_Request_With_Span_In_ActivityCurrent_Child_Spans_A first.ParentId.Should().Be(createActivity.Id); first.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestId && t.Value == @event.Id).Should().BeTrue(); first.Tags.Any(t => t is { Key: BrighterSemanticConventions.RequestType, Value: nameof(MyEvent) }).Should().BeTrue(); - first.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(@event)).Should().BeTrue(); + first.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(@event, JsonSerialisationOptions.Options)).Should().BeTrue(); first.Tags.Any(t => t is { Key: BrighterSemanticConventions.Operation, Value: "publish" }).Should().BeTrue(); first.Events.Count().Should().Be(1); @@ -182,7 +182,7 @@ public void When_Publishing_A_Request_With_Span_In_ActivityCurrent_Child_Spans_A second.ParentId.Should().Be(createActivity.Id); second.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestId && t.Value == @event.Id).Should().BeTrue(); second.Tags.Any(t => t is { Key: BrighterSemanticConventions.RequestType, Value: nameof(MyEvent) }).Should().BeTrue(); - second.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(@event)).Should().BeTrue(); + second.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(@event, JsonSerialisationOptions.Options)).Should().BeTrue(); second.Tags.Any(t => t is { Key: BrighterSemanticConventions.Operation, Value: "publish" }).Should().BeTrue(); second.Events.Count().Should().Be(1); @@ -230,7 +230,7 @@ public void When_Sending_A_Request_With_No_Context_Or_Span_In_ActivityCurrent_A_ first.ParentId.Should().Be(createActivity.Id); first.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestId && t.Value == @event.Id).Should().BeTrue(); first.Tags.Any(t => t is { Key: BrighterSemanticConventions.RequestType, Value: nameof(MyEvent) }).Should().BeTrue(); - first.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(@event)).Should().BeTrue(); + first.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(@event, JsonSerialisationOptions.Options)).Should().BeTrue(); first.Tags.Any(t => t is { Key: BrighterSemanticConventions.Operation, Value: "publish" }).Should().BeTrue(); first.Events.Count().Should().Be(1); @@ -244,7 +244,7 @@ public void When_Sending_A_Request_With_No_Context_Or_Span_In_ActivityCurrent_A_ second.ParentId.Should().Be(createActivity.Id); second.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestId && t.Value == @event.Id).Should().BeTrue(); second.Tags.Any(t => t is { Key: BrighterSemanticConventions.RequestType, Value: nameof(MyEvent) }).Should().BeTrue(); - second.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(@event)).Should().BeTrue(); + second.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(@event, JsonSerialisationOptions.Options)).Should().BeTrue(); second.Tags.Any(t => t is { Key: BrighterSemanticConventions.Operation, Value: "publish" }).Should().BeTrue(); second.Events.Count().Should().Be(1); diff --git a/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Publish/When_Publishing_A_Request_A_Span_Is_Exported_Asyn.cs b/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Publish/When_Publishing_A_Request_A_Span_Is_Exported_Asyn.cs index 6e31a5502d..582e6468df 100644 --- a/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Publish/When_Publishing_A_Request_A_Span_Is_Exported_Asyn.cs +++ b/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Publish/When_Publishing_A_Request_A_Span_Is_Exported_Asyn.cs @@ -105,7 +105,7 @@ public async Task When_Publishing_A_Request_With_Span_In_Context_Child_Spans_Are first.ParentId.Should().Be(createActivity.Id); first.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestId && t.Value == @event.Id).Should().BeTrue(); first.Tags.Any(t => t is { Key: BrighterSemanticConventions.RequestType, Value: nameof(MyEvent) }).Should().BeTrue(); - first.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(@event)).Should().BeTrue(); + first.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(@event, JsonSerialisationOptions.Options)).Should().BeTrue(); first.Tags.Any(t => t is { Key: BrighterSemanticConventions.Operation, Value: "publish" }).Should().BeTrue(); first.Events.Count().Should().Be(1); @@ -119,7 +119,7 @@ public async Task When_Publishing_A_Request_With_Span_In_Context_Child_Spans_Are second.ParentId.Should().Be(createActivity.Id); second.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestId && t.Value == @event.Id).Should().BeTrue(); second.Tags.Any(t => t is { Key: BrighterSemanticConventions.RequestType, Value: nameof(MyEvent) }).Should().BeTrue(); - second.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(@event)).Should().BeTrue(); + second.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(@event, JsonSerialisationOptions.Options)).Should().BeTrue(); second.Tags.Any(t => t is { Key: BrighterSemanticConventions.Operation, Value: "publish" }).Should().BeTrue(); second.Events.Count().Should().Be(1); @@ -171,7 +171,7 @@ public async Task When_Publishing_A_Request_With_Span_In_ActivityCurrent_Child_S first.ParentId.Should().Be(createActivity.Id); first.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestId && t.Value == @event.Id).Should().BeTrue(); first.Tags.Any(t => t is { Key: BrighterSemanticConventions.RequestType, Value: nameof(MyEvent) }).Should().BeTrue(); - first.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(@event)).Should().BeTrue(); + first.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(@event, JsonSerialisationOptions.Options)).Should().BeTrue(); first.Tags.Any(t => t is { Key: BrighterSemanticConventions.Operation, Value: "publish" }).Should().BeTrue(); first.Events.Count().Should().Be(1); @@ -185,7 +185,7 @@ public async Task When_Publishing_A_Request_With_Span_In_ActivityCurrent_Child_S second.ParentId.Should().Be(createActivity.Id); second.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestId && t.Value == @event.Id).Should().BeTrue(); second.Tags.Any(t => t is { Key: BrighterSemanticConventions.RequestType, Value: nameof(MyEvent) }).Should().BeTrue(); - second.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(@event)).Should().BeTrue(); + second.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(@event, JsonSerialisationOptions.Options)).Should().BeTrue(); second.Tags.Any(t => t is { Key: BrighterSemanticConventions.Operation, Value: "publish" }).Should().BeTrue(); second.Events.Count().Should().Be(1); @@ -233,7 +233,7 @@ public async Task When_Sending_A_Request_With_No_Context_Or_Span_In_ActivityCurr first.ParentId.Should().Be(createActivity.Id); first.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestId && t.Value == @event.Id).Should().BeTrue(); first.Tags.Any(t => t is { Key: BrighterSemanticConventions.RequestType, Value: nameof(MyEvent) }).Should().BeTrue(); - first.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(@event)).Should().BeTrue(); + first.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(@event, JsonSerialisationOptions.Options)).Should().BeTrue(); first.Tags.Any(t => t is { Key: BrighterSemanticConventions.Operation, Value: "publish" }).Should().BeTrue(); first.Events.Count().Should().Be(1); @@ -247,7 +247,7 @@ public async Task When_Sending_A_Request_With_No_Context_Or_Span_In_ActivityCurr second.ParentId.Should().Be(createActivity.Id); second.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestId && t.Value == @event.Id).Should().BeTrue(); second.Tags.Any(t => t is { Key: BrighterSemanticConventions.RequestType, Value: nameof(MyEvent) }).Should().BeTrue(); - second.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(@event)).Should().BeTrue(); + second.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(@event, JsonSerialisationOptions.Options)).Should().BeTrue(); second.Tags.Any(t => t is { Key: BrighterSemanticConventions.Operation, Value: "publish" }).Should().BeTrue(); second.Events.Count().Should().Be(1); diff --git a/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Send/When_Sending_A_Request_A_Span_Is_Exported.cs b/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Send/When_Sending_A_Request_A_Span_Is_Exported.cs index 6de22da80f..d3072bb918 100644 --- a/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Send/When_Sending_A_Request_A_Span_Is_Exported.cs +++ b/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Send/When_Sending_A_Request_A_Span_Is_Exported.cs @@ -82,7 +82,7 @@ public void When_Sending_A_Request_With_Span_In_Context_A_Child_Span_Is_Exported _exportedActivities.First().ParentId.Should().Be(parentActivity?.Id); _exportedActivities.First().Tags.Any(t => t.Key == BrighterSemanticConventions.RequestId && t.Value == command.Id).Should().BeTrue(); _exportedActivities.First().Tags.Any(t => t is { Key: BrighterSemanticConventions.RequestType, Value: nameof(MyCommand) }).Should().BeTrue(); - _exportedActivities.First().Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(command)).Should().BeTrue(); + _exportedActivities.First().Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(command, JsonSerialisationOptions.Options)).Should().BeTrue(); _exportedActivities.First().Tags.Any(t => t is { Key: BrighterSemanticConventions.Operation, Value: "send" }).Should().BeTrue(); _exportedActivities.First().Events.Count().Should().Be(1); @@ -115,7 +115,7 @@ public void When_Sending_A_Request_With_Span_In_ActivityCurrent_A_Child_Span_Is_ _exportedActivities.First().ParentId.Should().Be(parentActivity?.Id); _exportedActivities.First().Tags.Any(t => t.Key == BrighterSemanticConventions.RequestId && t.Value == command.Id).Should().BeTrue(); _exportedActivities.First().Tags.Any(t => t is { Key: BrighterSemanticConventions.RequestType, Value: nameof(MyCommand) }).Should().BeTrue(); - _exportedActivities.First().Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(command)).Should().BeTrue(); + _exportedActivities.First().Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(command, JsonSerialisationOptions.Options)).Should().BeTrue(); _exportedActivities.First().Tags.Any(t => t is { Key: BrighterSemanticConventions.Operation, Value: "send" }).Should().BeTrue(); _exportedActivities.First().Events.Count().Should().Be(1); @@ -144,7 +144,7 @@ public void When_Sending_A_Request_With_No_Context_Or_Span_In_ActivityCurrent_A_ _exportedActivities.First().ParentId.Should().BeNull(); _exportedActivities.First().Tags.Any(t => t.Key == BrighterSemanticConventions.RequestId && t.Value == command.Id).Should().BeTrue(); _exportedActivities.First().Tags.Any(t => t is { Key: BrighterSemanticConventions.RequestType, Value: nameof(MyCommand) }).Should().BeTrue(); - _exportedActivities.First().Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(command)).Should().BeTrue(); + _exportedActivities.First().Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(command, JsonSerialisationOptions.Options)).Should().BeTrue(); _exportedActivities.First().Tags.Any(t => t is { Key: BrighterSemanticConventions.Operation, Value: "send" }).Should().BeTrue(); _exportedActivities.First().Events.Count().Should().Be(1); diff --git a/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Send/When_Sending_A_Request_A_Span_Is_Exported_Async.cs b/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Send/When_Sending_A_Request_A_Span_Is_Exported_Async.cs index 3e49111dba..9fd0272858 100644 --- a/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Send/When_Sending_A_Request_A_Span_Is_Exported_Async.cs +++ b/tests/Paramore.Brighter.Core.Tests/Observability/CommandProcessor/Send/When_Sending_A_Request_A_Span_Is_Exported_Async.cs @@ -85,7 +85,7 @@ public async Task When_Sending_A_Request_With_Span_In_Context_A_Child_Span_Is_Ex _exportedActivities.First().ParentId.Should().Be(parentActivity.Id); _exportedActivities.First().Tags.Any(t => t.Key == BrighterSemanticConventions.RequestId && t.Value == command.Id).Should().BeTrue(); _exportedActivities.First().Tags.Any(t => t is { Key: BrighterSemanticConventions.RequestType, Value: nameof(MyCommand) }).Should().BeTrue(); - _exportedActivities.First().Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(command)).Should().BeTrue(); + _exportedActivities.First().Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(command, JsonSerialisationOptions.Options)).Should().BeTrue(); _exportedActivities.First().Tags.Any(t => t is { Key: BrighterSemanticConventions.Operation, Value: "send" }).Should().BeTrue(); _exportedActivities.First().Events.Count().Should().Be(1); @@ -118,7 +118,7 @@ public async Task When_Sending_A_Request_With_Span_In_ActivityCurrent_A_Child_Sp _exportedActivities.First().ParentId.Should().Be(parentActivity.Id); _exportedActivities.First().Tags.Any(t => t.Key == BrighterSemanticConventions.RequestId && t.Value == command.Id).Should().BeTrue(); _exportedActivities.First().Tags.Any(t => t is { Key: BrighterSemanticConventions.RequestType, Value: nameof(MyCommand) }).Should().BeTrue(); - _exportedActivities.First().Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(command)).Should().BeTrue(); + _exportedActivities.First().Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(command, JsonSerialisationOptions.Options)).Should().BeTrue(); _exportedActivities.First().Tags.Any(t => t is { Key: BrighterSemanticConventions.Operation, Value: "send" }).Should().BeTrue(); _exportedActivities.First().Events.Count().Should().Be(1); @@ -147,7 +147,7 @@ public async Task When_Sending_A_Request_With_No_Context_Or_Span_In_ActivityCurr _exportedActivities.First().ParentId.Should().BeNull(); _exportedActivities.First().Tags.Any(t => t.Key == BrighterSemanticConventions.RequestId && t.Value == command.Id).Should().BeTrue(); _exportedActivities.First().Tags.Any(t => t is { Key: BrighterSemanticConventions.RequestType, Value: nameof(MyCommand) }).Should().BeTrue(); - _exportedActivities.First().Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(command)).Should().BeTrue(); + _exportedActivities.First().Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && t.Value == JsonSerializer.Serialize(command, JsonSerialisationOptions.Options)).Should().BeTrue(); _exportedActivities.First().Tags.Any(t => t is { Key: BrighterSemanticConventions.Operation, Value: "send" }).Should().BeTrue(); _exportedActivities.First().Events.Count().Should().Be(1); diff --git a/tests/Paramore.Brighter.Core.Tests/Observability/Common/When_Creating_A_Message_Mapper_Add_Brighter_Semantic_Conventions.cs b/tests/Paramore.Brighter.Core.Tests/Observability/Common/When_Creating_A_Message_Mapper_Add_Brighter_Semantic_Conventions.cs index 807c3ffed2..698a484813 100644 --- a/tests/Paramore.Brighter.Core.Tests/Observability/Common/When_Creating_A_Message_Mapper_Add_Brighter_Semantic_Conventions.cs +++ b/tests/Paramore.Brighter.Core.Tests/Observability/Common/When_Creating_A_Message_Mapper_Add_Brighter_Semantic_Conventions.cs @@ -69,6 +69,6 @@ public void When_Creating_A_Message_Mapper_Add_Brighter_Semantic_Conventions() childEvent.Tags.Any(t => t.Key == BrighterSemanticConventions.MessagingDestinationPartitionId && (string)t.Value == paritionKey).Should().BeTrue(); childEvent.Tags.Any(t => t.Key == BrighterSemanticConventions.MessageBody && (string)t.Value == message.Body.Value).Should().BeTrue(); childEvent.Tags.Any(t => t.Key == BrighterSemanticConventions.MessageBodySize && (int)t.Value == message.Body.Value.Length).Should().BeTrue(); - childEvent.Tags.Any(t => t.Key == BrighterSemanticConventions.MessageHeaders && (string)t.Value == JsonSerializer.Serialize(message.Header)).Should().BeTrue(); + childEvent.Tags.Any(t => t.Key == BrighterSemanticConventions.MessageHeaders && (string)t.Value == JsonSerializer.Serialize(message.Header, JsonSerialisationOptions.Options)).Should().BeTrue(); } } diff --git a/tests/Paramore.Brighter.Core.Tests/Observability/Common/When_Creating_A_Span_Add_Brighter_Semantic_Conventions.cs b/tests/Paramore.Brighter.Core.Tests/Observability/Common/When_Creating_A_Span_Add_Brighter_Semantic_Conventions.cs index 4a1b39ab82..da0dc953fb 100644 --- a/tests/Paramore.Brighter.Core.Tests/Observability/Common/When_Creating_A_Span_Add_Brighter_Semantic_Conventions.cs +++ b/tests/Paramore.Brighter.Core.Tests/Observability/Common/When_Creating_A_Span_Add_Brighter_Semantic_Conventions.cs @@ -66,7 +66,7 @@ public void When_Creating_A_Span_Add_Brighter_Semantic_Conventions() tagDictionary.Should().ContainKey(BrighterSemanticConventions.RequestType); tagDictionary[BrighterSemanticConventions.RequestType].Should().Be(command.GetType().Name); tagDictionary.Should().ContainKey(BrighterSemanticConventions.RequestBody); - tagDictionary[BrighterSemanticConventions.RequestBody].Should().Be(System.Text.Json.JsonSerializer.Serialize(command)); + tagDictionary[BrighterSemanticConventions.RequestBody].Should().Be(System.Text.Json.JsonSerializer.Serialize(command, JsonSerialisationOptions.Options)); tagDictionary.Should().ContainKey(BrighterSemanticConventions.Operation); tagDictionary[BrighterSemanticConventions.Operation].Should().Be(CommandProcessorSpanOperation.Send.ToSpanName()); @@ -79,7 +79,7 @@ public void When_Creating_A_Span_Add_Brighter_Semantic_Conventions() childSpan.ParentId.Should().Be(_parentActivity.Id); childSpan.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestId && (string)t.Value == command.Id.ToString()).Should().BeTrue(); childSpan.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestType && (string)t.Value == command.GetType().Name).Should().BeTrue(); - childSpan.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && (string)t.Value == System.Text.Json.JsonSerializer.Serialize(command)).Should().BeTrue(); + childSpan.Tags.Any(t => t.Key == BrighterSemanticConventions.RequestBody && (string)t.Value == System.Text.Json.JsonSerializer.Serialize(command, JsonSerialisationOptions.Options)).Should().BeTrue(); childSpan.Tags.Any(t => t.Key == BrighterSemanticConventions.Operation && (string)t.Value == CommandProcessorSpanOperation.Send.ToSpanName()).Should().BeTrue(); } diff --git a/tests/Paramore.Brighter.Core.Tests/Observability/MessageDispatch/When_A_Message_Is_Dispatched_It_Should_Begin_A_Span.cs b/tests/Paramore.Brighter.Core.Tests/Observability/MessageDispatch/When_A_Message_Is_Dispatched_It_Should_Begin_A_Span.cs index aee0506f71..c5e5cacd81 100644 --- a/tests/Paramore.Brighter.Core.Tests/Observability/MessageDispatch/When_A_Message_Is_Dispatched_It_Should_Begin_A_Span.cs +++ b/tests/Paramore.Brighter.Core.Tests/Observability/MessageDispatch/When_A_Message_Is_Dispatched_It_Should_Begin_A_Span.cs @@ -145,7 +145,7 @@ public void When_a_message_is_dispatched_it_should_begin_a_span() createActivity.Tags.Any(t => t.Key == BrighterSemanticConventions.MessageType && t.Value == _message.Header.MessageType.ToString()).Should().BeTrue(); createActivity.TagObjects.Any(t => t.Value != null && t.Key == BrighterSemanticConventions.MessageBodySize && Convert.ToInt32(t.Value) == _message.Body.Bytes.Length).Should().BeTrue(); createActivity.Tags.Any(t => t.Key == BrighterSemanticConventions.MessageBody && t.Value == _message.Body.Value).Should().BeTrue(); - createActivity.Tags.Any(t => t.Key == BrighterSemanticConventions.MessageHeaders && t.Value == JsonSerializer.Serialize(_message.Header)).Should().BeTrue(); + createActivity.Tags.Any(t => t.Key == BrighterSemanticConventions.MessageHeaders && t.Value == JsonSerializer.Serialize(_message.Header, JsonSerialisationOptions.Options)).Should().BeTrue(); createActivity.Tags.Any(t => t.Key == BrighterSemanticConventions.ConversationId && t.Value == _message.Header.CorrelationId).Should().BeTrue(); createActivity.Tags.Any(t => t.Key == BrighterSemanticConventions.MessagingSystem && t.Value == MessagingSystem.InternalBus.ToMessagingSystemName()).Should().BeTrue(); createActivity.TagObjects.Any(t => t.Value != null && t.Key == BrighterSemanticConventions.CeSource && ((Uri)(t.Value)) == _message.Header.Source).Should().BeTrue();