Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-3419 Use JsonSerialisationOptions.Options when use JsonSerializer.Serialize #3463

Merged
merged 3 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,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>(message));
_messageQueue.Enqueue(JsonSerializer.Deserialize<Message>(message, JsonSerialisationOptions.Options));
});

Task connectTask = Connect(configuration.ConnectionAttempts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public async Task PublishMessageAsync(Message message, CancellationToken cancell

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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ public override async Task<TRequest> 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);
}
}
}
12 changes: 6 additions & 6 deletions src/Paramore.Brighter/Observability/BrighterTracer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ THE SOFTWARE. */
#endregion

using OpenTelemetry.Trace;

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
Expand Down Expand Up @@ -120,7 +119,7 @@ public void AddExceptionToSpan(Activity? span, IEnumerable<Exception> exceptions
{ BrighterSemanticConventions.Operation, operation.ToSpanName() },
{ BrighterSemanticConventions.RequestId, request.Id },
{ BrighterSemanticConventions.RequestType, request.GetType().Name },
{ BrighterSemanticConventions.RequestBody, JsonSerializer.Serialize(request) }
{ BrighterSemanticConventions.RequestBody, JsonSerializer.Serialize(request, JsonSerialisationOptions.Options) }
};

var activity = ActivitySource.StartActivity(
Expand Down Expand Up @@ -166,7 +165,7 @@ public void AddExceptionToSpan(Activity? span, IEnumerable<Exception> 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 },
Expand All @@ -176,6 +175,7 @@ public void AddExceptionToSpan(Activity? span, IEnumerable<Exception> exceptions
{ BrighterSemanticConventions.CeType, message.Header.Type},
{ BrighterSemanticConventions.ReplyTo, message.Header.ReplyTo },
{ BrighterSemanticConventions.HandledCount, message.Header.HandledCount }

};

var activity = ActivitySource.StartActivity(
Expand Down Expand Up @@ -491,7 +491,7 @@ public void AddExceptionToSpan(Activity? span, IEnumerable<Exception> 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.MessageHeaders, JsonSerializer.Serialize(message.Header, JsonSerialisationOptions.Options ));
tags.Add(BrighterSemanticConventions.ConversationId, message.Header.CorrelationId);

//cloud events attributes
Expand Down Expand Up @@ -565,7 +565,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));
Expand Down Expand Up @@ -656,7 +656,7 @@ public static void WriteProducerEvent(Activity? span, MessagingSystem messagingS
{ 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 },
Expand Down
Loading