static void Main(string[] args)
        {
            // let's say you want to connect to a database-system which Instana does not
            // support for automatic tracing. How would you get tracing for this?
            // in this example we pretend you had access to the client (or a wrapper around a client)
            // which you can use for instrumentation.
            Console.WriteLine("Awesome fake database tracing demo v1.0");
            DatabaseClient client = new DatabaseClient();

            while (true)
            {
                try
                {
                    Console.Write("Query >");
                    var text = Console.ReadLine();
                    // we create an entry-span as the root to our trace here, and we're pretending it was an http-call
                    // by using the AsHttpTo extensions-method...
                    // also we request a call-stack with a maximum of 10 frames to be captured
                    using (var rootSpan = CustomSpan.CreateEntry(null, null, callStackFrames: 10).AsHttpTo("https://somewhere.inthe.cloud/api/databaseaccess"))
                    {
                        // dig into the code of DatabaseClient to see how the rest of the
                        // trace is created by means of the SDK...
                        bool connected = client.Connect("localhost", "superdatabase");
                        var  reader    = client.ExecuteQuery(text);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Could not connect to the database:" + e.Message);
                }
            }
        }
示例#2
0
        private static void Listen()
        {
            if (_listening)
            {
                return;
            }
            _listening = true;
            foreach (string topic in _topics)
            {
                MessageConsumer consumer = new MessageConsumer()
                {
                    Topic = topic
                };
            }

            _listenerTask = Task.Factory.StartNew(() =>
            {
                foreach (Message msg in _messages.GetConsumingEnumerable())
                {
                    using (var entrySpan = CustomSpan.CreateEntry(null, () => ExtractCorrelation(msg)).AsMessageReceiveFrom(msg.Topic))
                    {
                        if (_topicToConsumer.ContainsKey(msg.Topic))
                        {
                            _topicToConsumer[msg.Topic].HandleMessage(msg);
                        }
                    }
                }
            });
        }
示例#3
0
 public string Execute(string input, Dictionary <string, object> protocol)
 {
     // for every step we create an entry (remember that we create an exit for every call
     // from the pipeline to an IStep-implementation). We correlate based on the current context
     // since we never really leave the boundaries of the app. In remote scenarios though, this would
     // look differently.
     using (var span = CustomSpan.CreateEntry(this, CorrelationUtil.GetCorrelationFromCurrentContext))
     {
         // wrap the call and bubble exceptions up to gather error-information
         span.WrapAction(() =>
         {
             span.SetTag(new string[] { "Input" }, input);
             string[] words = input.Split(new char[] { ',', ' ', '!', '.', '?' });
             int icount     = 0;
             foreach (string word in words)
             {
                 if (!string.IsNullOrEmpty(word))
                 {
                     icount++;
                 }
             }
             protocol["Word-Count"] = icount;
         }, true);
     }
     return(input);
 }
 private void BtnOpenPopup_Click(object sender, EventArgs e)
 {
     using (var span = CustomSpan.CreateEntry(this, (ISpanContext)null, "Open Popup Form"))
     {
         frmPopup popup = new frmPopup();
         popup.Show();
     }
 }
 private void FrmMain_Load(object sender, EventArgs e)
 {
     // create a trace for loading the main-window. Nothing interesting happens here.
     // it just displays that any event-handler can be instrumented
     using (var span = CustomSpan.CreateEntry(this, (ISpanContext)null, "Main Window Load"))
     {
         Thread.Sleep(10);
     }
 }
        public Task <string> GreetMe(GrainMessage <string> nameMessage)
        {
            return(Task.Run <string>(() => {
                using (var span = CustomSpan.CreateEntry(this, () => { return CorrelateFromMessage <string>(nameMessage); }))
                {
                    span.SetData("name", nameMessage.Content);
                    span.SetTag("service", this.GetType().Name);

                    return $"Hello {nameMessage.Content}";
                }
            }));
        }
示例#7
0
 private static async Task DoClientWork(IClusterClient client)
 {
     await Task.Run(async() =>
     {
         using (var span = CustomSpan.CreateEntry(null, (ISpanContext)null))
         {
             span.SetTag("service", "OrleansExampleClient");
             // example of calling grains from the initialized client
             var friend  = client.GetGrain <IHelloGrain>(0);
             var message = new GrainMessage <string>("Oliver Twist");
             using (var exitSpan = CustomSpan.CreateExit(friend, (name, value) => { message.Headers.Add(name, value); }))
             {
                 exitSpan.SetTag("service", "OrleansExampleClient");
                 var response = await friend.GreetMe(message);
                 Console.WriteLine("\n\n{0}\n\n", response);
             }
         }
     });
 }
示例#8
0
 public string Execute(string input, Dictionary <string, object> protocol)
 {
     // for every step we create an entry (remember that we create an exit for every call
     // from the pipeline to an IStep-implementation). We correlate based on the current context
     // since we never really leave the boundaries of the app. In remote scenarios though, this would
     // look differently.
     using (var span = CustomSpan.CreateEntry(this, CorrelationUtil.GetCorrelationFromCurrentContext))
     {
         // wrap the call and bubble exceptions up to gather error-information
         span.WrapAction(() =>
         {
             span.SetTag(new string[] { "Input" }, input);
             if (string.IsNullOrEmpty(input))
             {
                 protocol["Validation-Result"] = "Invalid";
                 throw new ArgumentException("The input for this job was invalid!");
             }
             protocol["Validation-Result"] = "Valid";
         }, true);
         return(input);
     }
 }
        private void BtnRefresh_Click(object sender, EventArgs e)
        {
            // when the refresh-button is hit, we have an interesting trace.
            // so let's start the trace with an entry-span, which will be the root.
            using (var span = CustomSpan.CreateEntry(this, (ISpanContext)null, "Get Country List"))
            {
                // set a tag on the span, so we know which region has been selected by the user
                span.SetTag("region", cbRegion.SelectedItem == null ? "NONE SELECTED" : (string)cbRegion.SelectedItem);
                span.SetTag(new string[] { "infrastructure", "machine" }, Environment.MachineName);

                if (cbRegion.SelectedItem == null)
                {
                    MessageBox.Show("Please select a region first");
                    return;
                }

                // call the CountryService to get the countries from the selected region
                // this call will create additional spans! Go ceck CountryService
                string selectedRegion = (string)cbRegion.SelectedItem;
                var    result         = _countryService.GetCountriesByRegion(selectedRegion);
                if (result.WasSuccessful)
                {
                    FillList(result.Result);
                }
                else
                {
                    if (result.CallException != null)
                    {
                        MessageBox.Show(result.CallException.Message, "Error calling REST-API", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        span.SetException(result.CallException);
                    }
                }
                // set the result of the call on the span
                span.SetResult(result.StatusCode.ToString());
            }
        }