@@ -14,6 +14,10 @@ namespace NewRelic.Providers.Wrapper.AzureServiceBus
1414 public class AzureServiceBusReceiverManagerWrapper : AzureServiceBusWrapperBase
1515 {
1616 private static Func < object , object > _receiverAccessor ;
17+ private static Func < object , string > _entityPathAccessor ;
18+ private static Func < object , string > _fullyQualifiedNamespaceAccessor ;
19+ private static bool _badReceiverWarningLogged ;
20+
1721 public override bool IsTransactionRequired => false ;
1822
1923 public override CanWrapResponse CanWrap ( InstrumentedMethodInfo instrumentedMethodInfo )
@@ -24,12 +28,30 @@ public override CanWrapResponse CanWrap(InstrumentedMethodInfo instrumentedMetho
2428
2529 public override AfterWrappedMethodDelegate BeforeWrappedMethod ( InstrumentedMethodCall instrumentedMethodCall , IAgent agent , ITransaction transaction )
2630 {
31+ string queueOrTopicName = null ;
32+ string fqns = null ;
33+
2734 var receiverManager = instrumentedMethodCall . MethodCall . InvocationTarget ;
28- _receiverAccessor ??= VisibilityBypasser . Instance . GeneratePropertyAccessor < object > ( receiverManager . GetType ( ) , "Receiver" ) ;
29- dynamic receiver = _receiverAccessor ( receiverManager ) ;
35+ var receiverManagerType = receiverManager . GetType ( ) ;
36+ _receiverAccessor ??= VisibilityBypasser . Instance . GeneratePropertyAccessor < object > ( receiverManagerType , "Receiver" ) ;
37+ object receiver = _receiverAccessor ( receiverManager ) ;
38+ if ( receiver == null )
39+ {
40+ if ( ! _badReceiverWarningLogged )
41+ {
42+ agent . Logger . Warn ( "AzureServiceBusReceiverManagerWrapper: Unable to access Receiver property on ReceiverManager instance of type {ReceiverManagerType}. Unable to access queue/topic name or fully qualified namespace." , receiverManagerType ) ;
43+ _badReceiverWarningLogged = true ;
44+ }
45+ }
46+ else
47+ {
48+ _entityPathAccessor ??= VisibilityBypasser . Instance . GeneratePropertyAccessor < string > ( receiver . GetType ( ) , "EntityPath" ) ;
49+ _fullyQualifiedNamespaceAccessor ??= VisibilityBypasser . Instance . GeneratePropertyAccessor < string > ( receiver . GetType ( ) , "FullyQualifiedNamespace" ) ;
50+
51+ queueOrTopicName = _entityPathAccessor ( receiver ) ? . ToString ( ) ; // some-queue|topic-name
52+ fqns = _fullyQualifiedNamespaceAccessor ( receiver ) ? . ToString ( ) ; // some-service-bus-entity.servicebus.windows.net
53+ }
3054
31- string queueOrTopicName = receiver . EntityPath ; // some-queue|topic-name
32- string fqns = receiver . FullyQualifiedNamespace ; // some-service-bus-entity.servicebus.windows.net
3355 var destinationType = GetMessageBrokerDestinationType ( queueOrTopicName ) ;
3456
3557 // create a transaction for this method call. This method invokes the ProcessMessageAsync handler
@@ -97,6 +119,5 @@ private static IEnumerable<string> ProcessHeaders(ReadOnlyDictionary<string, obj
97119
98120 return headerValues ;
99121 }
100-
101122 }
102123}
0 commit comments