Getting the ActivityId (logging between tiers)

Jan 6, 2011 at 5:51 PM

Can you help me to understand the best way to set ActivityId.  We are in the processing of enhancing of a WCF service written by somebody no longer here.
They implemented your diagnostics, but maybe didn't take it as far as they could have.  All the activity-id's were 000-00-00 etc...

We have set some of them now based on a GUID in our data structure, like this:

        public TransactionRequest BuildTransactionResponse(TransactionRequest transactionRequest, Errors errors, Status.TransactionStatusType statusType)
        {

            Trace.CorrelationManager.ActivityId = new System.Guid(transactionRequest.Header.HeaderGUID);

 

However, we also have method that don't have that data structure.  So how do we set the activity-id in the client, pass it, then retrieve it and put into the diagnostics log/SQL/table on the server?
Is there a blog that describes that somewhere?  I read your primer section "logging between tiers" but don't understand all the specifics to make it happen.  There is a code sample there for the Transfer method, but didn't see anything for setting the activity-id on client, and using it on the server.

Thanks,
Neal Walters

 

 

Jan 6, 2011 at 6:04 PM

Googled for "passing activity-id from client to server" and lo and behold, your blog came up:

http://thejoyofcode.com/Smuggling_Headers_with_WCF.aspx

Still reading...  A little confused about what is documented on CodePlex vs your blog and how to find things...

Neal

 

Jan 6, 2011 at 10:35 PM

Here's our quandry.

We receive an xml message from our vendor in our ExternalWebService, which is outward facing, and it calls our InternalWebService. 

For example,

<Transaction>
  <Header>
   <TransactionGUID>xxxx</TransactionGUID>
   <BusinessManager>JohnDoe</BusinessManager>
  </Header>
  <Detail>
      <Amount>100</Amount>
      <etc>more-stuff</etc>
  </Detail>
</Transaction>

We can use Xpath to get the TransactionGUID, and we want to use that for our Activity-ID.

However, we are not sure how to get access to that in the BeforeSendRequest method.

We might call a method like

bool isValidBusinessManager =intersalServiceProxy.ValidateBusinessManager(name);

and we would like to pass the TransactionGUID as the activity-ID all the way through on that and other methods.

Thanks,

Neal

 


 

 

 

 

Coordinator
Jan 6, 2011 at 10:47 PM

Is this a WCF Service/Client? If so, why not just use a MessageInterceptor to find the TransactionGUID?

See http://www.thejoyofcode.com/Smuggling_Headers_with_WCF.aspx for some example interceptors.

Jan 7, 2011 at 6:11 PM

Right, this is a WCF Service/Client, and you will see above I did quote that web page in my prior post.

We have two types of web methods: 1) passes the whole XML, and 2) does not pass the whole XML.
For example, in my post above, if I call ValidateBusinessManagerI only pass the BusinessManager name and I don't have the entire XML from which to do an XPath. 

OR - are you saying that the interceptor can access the incoming message as well as the outgoing message?
So even when I'm calling ValidateBusinessManager from my external service, I can still get to the message that was received by the external service from our external client?

Thanks,
Neal

 

Coordinator
Jan 7, 2011 at 6:47 PM

If you don't have a GUID that's logical to reuse as your ActivityId then it's common to just create an Activity Id at the beginning of a 'transaction' that you want to correlate. Trace.CorrelationManager.ActivityId = Guid.NewGuid();

The QuickReferenceExample does this. http://ukadcdiagnostics.codeplex.com/releases/view/12869#DownloadId=33123

Apologies for the fragmented conversation - I was reading the thread via e-mail and got confused. Still not sure I've grasped your situation though.

Jan 7, 2011 at 9:25 PM

Thanks Josh.   The point is that I do have a GUID I want to use. 

Outside-Customer A --> Our-External-Service B --> Our-Internal-Service C

A to B includes the XML with the GUID that I want to use as Activity-ID for all calls from B to C.

When A calls B, then B might call 10 methods on C (not by my design, just inherited it that way).

Some calls from B to C have the same XML as received from A to B and some do not (ValidateBusinessManager in my example above). 

On the methods from B to C that do not have that same XML, the question is can I get addressibility to the incoming message or a saved/common variable, and how.  Can the inspector see the incoming message received by A or only the outgoing message about to be sent by A?

Neal

 

Coordinator
Jan 10, 2011 at 4:42 AM

When A calls B you extract the GUID and set the Trace.CorrelationManager.ActivityId to that GUID. You can do this in a messageinspector or just at the start of B's operation body, whichever you prefer.

Now, from this point on, you have appropriately set the ActivityId for this 'transaction' so you can allow the GUID to flow for you.

Follow this guide - there are some caveats but it should get the ActivityId flowing from B to C without you needing to code for it:

http://www.thejoyofcode.com/Propagating_the_ActivityId_to_a_WCF_service.aspx 

HTH

Josh

Jan 13, 2011 at 12:17 AM

Thanks, we got it working today with the inspector methods.

Neal