Exemplo n.º 1
0
        internal static Activity StartReceiveActivity(
            string clientId,
            EventHubsConnectionStringBuilder csb,
            string partitionKey,
            string consumerGroup,
            EventPosition eventPosition)
        {
            // skip if diagnostic source not enabled
            if (!DiagnosticListener.IsEnabled())
            {
                return(null);
            }

            // skip if no listeners for this "Receive" activity
            if (!DiagnosticListener.IsEnabled(ReceiveActivityName, csb.Endpoint, csb.EntityPath))
            {
                return(null);
            }

            Activity activity = new Activity(ReceiveActivityName);

            // extract activity tags from input
            activity.AddTag("peer.hostname", csb.Endpoint.Host);
            activity.AddTag("eh.event_hub_name", csb.EntityPath);
            activity.AddTag("eh.partition_key", partitionKey);
            activity.AddTag("eh.consumer_group", consumerGroup);
            activity.AddTag("eh.start_offset", eventPosition.Offset);
            activity.AddTag("eh.start_sequence_number", eventPosition.SequenceNumber?.ToString());
            activity.AddTag("eh.start_date_time", eventPosition.EnqueuedTimeUtc?.ToString());
            activity.AddTag("eh.client_id", clientId);

            // in many cases activity start event is not interesting,
            // in that case start activity without firing event
            if (DiagnosticListener.IsEnabled(ReceiveActivityStartName))
            {
                DiagnosticListener.StartActivity(activity,
                                                 new
                {
                    Endpoint      = csb.Endpoint,
                    Entity        = csb.EntityPath,
                    PartitionKey  = partitionKey,
                    ConsumerGroup = consumerGroup
                });
            }
            else
            {
                activity.Start();
            }

            return(activity);
        }
        static EventHubClient Create(EventHubsConnectionStringBuilder csb)
        {
            if (string.IsNullOrWhiteSpace(csb.EntityPath))
            {
                throw Fx.Exception.ArgumentNullOrWhiteSpace(nameof(csb.EntityPath));
            }

            EventHubsEventSource.Log.EventHubClientCreateStart(csb.Endpoint.Host, csb.EntityPath);
            EventHubClient eventHubClient;

            eventHubClient = new AmqpEventHubClient(csb);
            EventHubsEventSource.Log.EventHubClientCreateStop(eventHubClient.ClientId);
            return(eventHubClient);
        }
Exemplo n.º 3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            var connectionStringBuilder = new EH.EventHubsConnectionStringBuilder(EhConnectionString)
            {
                EntityPath = EhEntityPath
            };

            eventHubClient = EH.EventHubClient.CreateFromConnectionString(connectionStringBuilder.ToString());
            string x = eventHubClient.EventHubName;

            var ri = eventHubClient.GetRuntimeInformationAsync().Result;

            //await SendMessagesToEventHub(100);
        }
        internal static void StopSendActivity(Activity activity, EventHubsConnectionStringBuilder csb, string partitionKey, IEnumerable <EventData> eventDatas, Task sendTask)
        {
            if (activity == null)
            {
                return;
            }

            DiagnosticListener.StopActivity(activity,
                                            new
            {
                csb.Endpoint,
                Entity       = csb.EntityPath,
                PartitionKey = partitionKey,
                EventDatas   = eventDatas,
                sendTask?.Status
            });
        }
        internal static void FailSendActivity(Activity activity, EventHubsConnectionStringBuilder csb, string partitionKey, IEnumerable <EventData> eventDatas, Exception ex)
        {
            if (!DiagnosticListener.IsEnabled() || !DiagnosticListener.IsEnabled(SendActivityExceptionName))
            {
                return;
            }

            DiagnosticListener.Write(SendActivityExceptionName,
                                     new
            {
                csb.Endpoint,
                Entity       = csb.EntityPath,
                PartitionKey = partitionKey,
                EventDatas   = eventDatas,
                Exception    = ex
            });
        }
        internal static void FailReceiveActivity(Activity activity, EventHubsConnectionStringBuilder csb, string partitionKey, string consumerGroup, Exception ex)
        {
            // TODO consider enriching activity with data from exception
            if (!DiagnosticListener.IsEnabled() || !DiagnosticListener.IsEnabled(ReceiveActivityExceptionName))
            {
                return;
            }

            DiagnosticListener.Write(ReceiveActivityExceptionName,
                                     new
            {
                csb.Endpoint,
                Entity        = csb.EntityPath,
                PartitionKey  = partitionKey,
                ConsumerGroup = consumerGroup,
                Exception     = ex
            });
        }
        internal static Activity StartSendActivity(string clientId, EventHubsConnectionStringBuilder csb, string partitionKey, IEnumerable <EventData> eventDatas, int count)
        {
            // skip if diagnostic source not enabled
            if (!DiagnosticListener.IsEnabled())
            {
                return(null);
            }

            // skip if no listeners for this "Send" activity
            if (!DiagnosticListener.IsEnabled(SendActivityName, csb.Endpoint, csb.EntityPath))
            {
                return(null);
            }

            Activity activity = new Activity(SendActivityName);

            activity.AddTag("peer.hostname", csb.Endpoint.Host);
            activity.AddTag("eh.event_hub_name", csb.EntityPath);
            activity.AddTag("eh.partition_key", partitionKey);
            activity.AddTag("eh.event_count", count.ToString());
            activity.AddTag("eh.client_id", clientId);

            // in many cases activity start event is not interesting,
            // in that case start activity without firing event
            if (DiagnosticListener.IsEnabled(SendActivityStartName))
            {
                DiagnosticListener.StartActivity(activity,
                                                 new
                {
                    csb.Endpoint,
                    Entity       = csb.EntityPath,
                    PartitionKey = partitionKey,
                    EventDatas   = eventDatas
                });
            }
            else
            {
                activity.Start();
            }

            Inject(eventDatas);

            return(activity);
        }
        internal static void StopReceiveActivity(Activity activity, EventHubsConnectionStringBuilder csb, string partitionKey, string consumerGroup, IList <EventData> events, Task receiveTask)
        {
            if (activity == null)
            {
                return;
            }

            SetRelatedOperations(activity, events);
            activity.AddTag("eh.event_count", (events?.Count ?? 0).ToString());

            DiagnosticListener.StopActivity(activity,
                                            new
            {
                csb.Endpoint,
                Entity        = csb.EntityPath,
                PartitionKey  = partitionKey,
                ConsumerGroup = consumerGroup,
                EventDatas    = events,
                receiveTask?.Status
            });
        }