Exemple #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();
            }
        }
Exemple #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();
            }
        }
        private IIncomingRemoteCallTracer getTracer(Grpc.Core.ServerCallContext context, string methodname)
        {
            try {
                Metadata.Entry metadataEntry = context.RequestHeaders.FirstOrDefault(m => String.Equals(m.Key, "x-dynatrace"));

                if (metadataEntry.Equals(default(Metadata.Entry)) || metadataEntry.Value == null)
                {
                    Console.WriteLine("No x-dynatrace header found in the request.");
                    return(null);
                }

                string incomingDynatraceStringTag = metadataEntry.Value;
                IIncomingRemoteCallTracer incomingRemoteCallTracer = oneAgentSdk.TraceIncomingRemoteCall(methodname, "CartService", "grpc://cartservice/" + methodname);
                incomingRemoteCallTracer.SetDynatraceStringTag(incomingDynatraceStringTag);
                incomingRemoteCallTracer.SetProtocolName("gRPC");

                return(incomingRemoteCallTracer);
            } catch (Exception e) {
                Console.WriteLine(e.ToString());
                return(null);
            }
        }