Beispiel #1
0
        /// <inheritdoc />
        public IApmSpan StartOperation(ApiOperationDescriptor operation, string spanKind, IDictionary <string, string> existingContext = null)
        {
            // Stackify requires us to pass a Func or Action, but Blueprint uses disposables. To make this work we have
            // Stackify wait on an "empty" async method that waits on the TCS completed below, that will be trigged when the returned
            // StackifyApmSpan is disposed, or sets an exception.
            var tcs = new TaskCompletionSource <bool>();

            var dependency = ProfileTracer.CreateAsOperation(operation.Name);

            dependency.ExecAsync(async() => await tcs.Task);

            return(new StackifyApmSpan(this, tcs));
        }
        public void Start()
        {
            OnMessageOptions options = new OnMessageOptions
            {
                MaxConcurrentCalls = 5,
                AutoComplete       = false
            };

            try
            {
                _QueueClient = QueueClient.CreateFromConnectionString(ConfigurationManager.AppSettings["Microsoft.ServiceBus.ConnectionString"], "WindowsService1");

                _QueueClient.OnMessageAsync(async m =>
                {
                    bool shouldAbandon = false;
                    try
                    {
                        //Create a new ID for the operation for correlation
                        var tracer = ProfileTracer.CreateAsOperation("Queue.WindowsService1", Trace.CorrelationManager.ActivityId.ToString());

                        // asynchronouse processing of messages

                        await tracer.ExecAsync(() =>
                        {
                            return(ProcessMessageAsync(m));
                        });


                        // complete if successful processing
                        await m.CompleteAsync();
                    }
                    catch (Exception ex)
                    {
                        shouldAbandon = true;
                        Console.WriteLine(ex);
                    }

                    if (shouldAbandon)
                    {
                        await m.AbandonAsync();
                    }
                },
                                            options);
            }
            catch (Exception ex)
            {
                Debug.Write(ex.ToString());
            }
        }