Skip to content

Commit

Permalink
fix issue (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
ecosalvador authored Nov 28, 2024
1 parent 267fec5 commit a252fa0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
3 changes: 3 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 12 additions & 7 deletions src/Ev.ServiceBus.Abstractions/Extensions/DiagnosticIdExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit a252fa0

Please sign in to comment.