From a252fa0ec7afb92619cbb0f24e14c6fae19e4c58 Mon Sep 17 00:00:00 2001 From: Edu <161594025+ecosalvador@users.noreply.github.com> Date: Thu, 28 Nov 2024 14:57:28 +0100 Subject: [PATCH] fix issue (#84) --- docs/CHANGELOG.md | 3 +++ .../Extensions/DiagnosticIdExtension.cs | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 3f27442..6833eb4 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 5.1.4 +- Changed + - Fix diagnostic id null reference ## 5.1.3 - Changed diff --git a/src/Ev.ServiceBus.Abstractions/Extensions/DiagnosticIdExtension.cs b/src/Ev.ServiceBus.Abstractions/Extensions/DiagnosticIdExtension.cs index 2d95fc6..c0cb06e 100644 --- a/src/Ev.ServiceBus.Abstractions/Extensions/DiagnosticIdExtension.cs +++ b/src/Ev.ServiceBus.Abstractions/Extensions/DiagnosticIdExtension.cs @@ -5,23 +5,28 @@ namespace Ev.ServiceBus.Abstractions.Extensions; public static class DiagnosticIdExtension { private const string DiagnosticIdKey = "Diagnostic-Id"; + public static string? GetDiagnosticId(this ServiceBusReceivedMessage message) { - return message.ApplicationProperties.ContainsKey(DiagnosticIdKey) - ? message.ApplicationProperties[DiagnosticIdKey].ToString() - : null; + if (message.ApplicationProperties.ContainsKey(DiagnosticIdKey) && message.ApplicationProperties[DiagnosticIdKey] != null) + { + return message.ApplicationProperties[DiagnosticIdKey].ToString(); + } + return null; } public static string? GetDiagnosticId(this ServiceBusMessage message) { - return message.ApplicationProperties.ContainsKey(DiagnosticIdKey) - ? message.ApplicationProperties[DiagnosticIdKey].ToString() - : null; + if (message.ApplicationProperties.ContainsKey(DiagnosticIdKey) && message.ApplicationProperties[DiagnosticIdKey] != null) + { + return message.ApplicationProperties[DiagnosticIdKey].ToString(); + } + return null; } public static void SetDiagnosticIdIfIsNot(this ServiceBusMessage message, string diagnosticId) { - if(message.ApplicationProperties.ContainsKey(DiagnosticIdKey)) + if (message.ApplicationProperties.ContainsKey(DiagnosticIdKey) && message.ApplicationProperties[DiagnosticIdKey] != null) return; message.ApplicationProperties.Add(DiagnosticIdKey, diagnosticId); }