예제 #1
0
        public static void IncomingRemoteCall()
        {
            IIncomingRemoteCallTracer incomingRemoteCallTracer = SampleApplication.OneAgentSdk
                                                                 .TraceIncomingRemoteCall("RemoteMethod", "RemoteServiceName", "mrcp://endpoint/service");

            string incomingDynatraceStringTag = string.Empty;                           // retrieve from incoming call metadata

            incomingRemoteCallTracer.SetDynatraceStringTag(incomingDynatraceStringTag); // link both sides of the remote call together
            incomingRemoteCallTracer.SetProtocolName("MyRemoteCallProtocol");

            incomingRemoteCallTracer.Start();
            try
            {
                ProcessRemoteCall();
            }
            catch (Exception e)
            {
                incomingRemoteCallTracer.Error(e);
                // handle or rethrow
            }
            finally
            {
                incomingRemoteCallTracer.End();
            }
        }
        public static void RemoteCallWithDatabase()
        {
            IOutgoingRemoteCallTracer outgoingRemoteCallTracer = SampleApplication.OneAgentSdk
                                                                 .TraceOutgoingRemoteCall("RemoteMethod", "RemoteServiceName", "mrcp://endpoint/service", ChannelType.TCP_IP, "myRemoteHost:1234");

            outgoingRemoteCallTracer.SetProtocolName("MyRemoteCallProtocol");

            outgoingRemoteCallTracer.Start();
            try
            {
                string outgoingDynatraceStringTag = outgoingRemoteCallTracer.GetDynatraceStringTag();
                // make the call and transport the tag across to the server to link both sides of the remote call

                // represents server side processing
                Thread server = new Thread(() =>
                {
                    IIncomingRemoteCallTracer incomingRemoteCallTracer = SampleApplication.OneAgentSdk
                                                                         .TraceIncomingRemoteCall("RemoteMethod", "RemoteServiceName", "mrcp://endpoint/service");

                    string incomingDynatraceStringTag = outgoingDynatraceStringTag; // retrieve from incoming call metadata
                    incomingRemoteCallTracer.SetDynatraceStringTag(incomingDynatraceStringTag);
                    incomingRemoteCallTracer.SetProtocolName("MyRemoteCallProtocol");

                    incomingRemoteCallTracer.Start();
                    try
                    {
                        // execute database request on server
                        DatabaseRequestTracerSamples.Sync_StartEnd();
                    }
                    catch (Exception e)
                    {
                        incomingRemoteCallTracer.Error(e);
                        // handle or rethrow
                    }
                    finally
                    {
                        incomingRemoteCallTracer.End();
                    }
                });
                server.Start();
                server.Join(); // sync call, wait for db result
            }
            catch (Exception e)
            {
                outgoingRemoteCallTracer.Error(e);
                // handle or rethrow
            }
            finally
            {
                outgoingRemoteCallTracer.End();
            }
        }
예제 #3
0
        /// <summary>
        /// Demonstrates an outgoing remote call originating from a client and being processed by a server.
        /// The Dynatrace tag is used to link both sides of the call together.
        /// </summary>
        public static void LinkedAsyncRemoteCall()
        {
            IOutgoingRemoteCallTracer outgoingRemoteCallTracer = SampleApplication.OneAgentSdk
                                                                 .TraceOutgoingRemoteCall("RemoteMethod", "RemoteServiceName", "mrcp://endpoint/service", ChannelType.TCP_IP, "myRemoteHost:1234");

            outgoingRemoteCallTracer.SetProtocolName("MyRemoteCallProtocol");

            outgoingRemoteCallTracer.Start();
            try
            {
                string outgoingDynatraceStringTag = outgoingRemoteCallTracer.GetDynatraceStringTag();
                // make the call and transport the tag across to the server to link both sides of the remote call together

                // represents server side processing
                Thread server = new Thread(() =>
                {
                    IIncomingRemoteCallTracer incomingRemoteCallTracer = SampleApplication.OneAgentSdk
                                                                         .TraceIncomingRemoteCall("RemoteMethod", "RemoteServiceName", "mrcp://endpoint/service");

                    string incomingDynatraceStringTag = outgoingDynatraceStringTag;             // retrieve from incoming call metadata
                    incomingRemoteCallTracer.SetDynatraceStringTag(incomingDynatraceStringTag); // link both sides of the remote call together
                    incomingRemoteCallTracer.SetProtocolName("MyRemoteCallProtocol");

                    incomingRemoteCallTracer.Start();
                    try
                    {
                        ProcessRemoteCall();
                    }
                    catch (Exception e)
                    {
                        incomingRemoteCallTracer.Error(e);
                        // handle or rethrow
                    }
                    finally
                    {
                        incomingRemoteCallTracer.End();
                    }
                });
                server.Start();
                // async processing on server
            }
            catch (Exception e)
            {
                outgoingRemoteCallTracer.Error(e);
                // handle or rethrow
            }
            finally
            {
                outgoingRemoteCallTracer.End();
            }
        }
        public static void InProcessLinkTracerSample()
        {
            // start a custom background worker
            CustomBackgroundWorker customBackgroundWorker = new CustomBackgroundWorker();

            // we're using the incoming remote call tracer as an example for an active service call
            IIncomingRemoteCallTracer incomingRemoteCallTracer = SampleApplication.OneAgentSdk
                                                                 .TraceIncomingRemoteCall("RemoteMethod", "RemoteServiceName", "mrcp://endpoint/service");

            incomingRemoteCallTracer.Start();
            try
            {
                // create an in-process link on the originating thread
                IInProcessLink inProcessLink = SampleApplication.OneAgentSdk.CreateInProcessLink();

                // delegate work to another thread, in this case we use a custom background worker implementation
                customBackgroundWorker.EnqueueWorkItem(() =>
                {
                    // use the in-process link to link the PurePath on the target thread to its origin
                    IInProcessLinkTracer inProcessLinkTracer = SampleApplication.OneAgentSdk.TraceInProcessLink(inProcessLink);
                    inProcessLinkTracer.Start();
                    DatabaseRequestTracerSamples.Sync_StartEnd(); // performs a database request traced using the IDatabaseRequestTracer
                    inProcessLinkTracer.End();
                });

                // the same link can be re-used multiple times
                customBackgroundWorker.EnqueueWorkItem(() =>
                {
                    IInProcessLinkTracer inProcessLinkTracer = SampleApplication.OneAgentSdk.TraceInProcessLink(inProcessLink);
                    inProcessLinkTracer.Trace(() =>
                    {
                        DatabaseRequestTracerSamples.Sync_StartEnd();
                    });
                });
                customBackgroundWorker.EnqueueWorkItem(() =>
                {
                    IInProcessLinkTracer inProcessLinkTracer = SampleApplication.OneAgentSdk.TraceInProcessLink(inProcessLink);
                    inProcessLinkTracer.Trace(DatabaseRequestTracerSamples.Sync_StartEnd);
                });
            }
            catch (Exception e)
            {
                incomingRemoteCallTracer.Error(e);
                throw e;
            }
            finally
            {
                incomingRemoteCallTracer.End();
                customBackgroundWorker.Shutdown();
            }
        }
        public override Task <Hipstershop.Cart> GetCart(GetCartRequest request, ServerCallContext context)
        {
            IIncomingRemoteCallTracer incomingRemoteCallTracer = getTracer(context, "GetCart");

            try {
                incomingRemoteCallTracer.Start();
                return(cartStore.GetCartAsync(request.UserId));
            } catch (Exception e) {
                Console.WriteLine(e.ToString());
                incomingRemoteCallTracer.Error(e);
            } finally {
                incomingRemoteCallTracer.End();
            }
            return(null);
        }
        public async override Task <Empty> EmptyCart(EmptyCartRequest request, ServerCallContext context)
        {
            IIncomingRemoteCallTracer incomingRemoteCallTracer = getTracer(context, "EmptyCart");

            try {
                await incomingRemoteCallTracer.TraceAsync(() => cartStore.EmptyCartAsync(request.UserId));
            } catch (Exception e) {
                Console.WriteLine(e.ToString());
                incomingRemoteCallTracer.Error(e);
            } finally  {
                incomingRemoteCallTracer.End();
            }

            return(Empty);
        }
        public async override Task <Empty> AddItem(AddItemRequest request, Grpc.Core.ServerCallContext context)
        {
            IIncomingRemoteCallTracer incomingRemoteCallTracer = getTracer(context, "AddItem");

            try {
                await incomingRemoteCallTracer.TraceAsync(() => cartStore.AddItemAsync(request.UserId, request.Item.ProductId, request.Item.Quantity));
            } catch (Exception e) {
                Console.WriteLine(e.ToString());
                incomingRemoteCallTracer.Error(e);
            } finally {
                incomingRemoteCallTracer.End();
            }

            return(Empty);
        }