OneAgent-SDK-for-dotnet icon indicating copy to clipboard operation
OneAgent-SDK-for-dotnet copied to clipboard

TraceOutgoingRemoteCall StartAsync deprecated

Open AndersLindPedersen opened this issue 4 years ago • 9 comments

As stated in documentation the StartAsync method is deprecated. I want to use the TraceAsync, but is a bit confused on how to retrieve the Tag when TraceAsync requires an action. My action is a RPC and the tag is a prerequisite to that.

Consider this:

` IOutgoingRemoteCallTracer outgoingRemoteCallTracer = oneAgentSdk.TraceOutgoingRemoteCall( "RemoteMethod", "RemoteServiceName", "mrcp://endpoint/service", ChannelType.TCP_IP, "myRemoteHost:1234"); outgoingRemoteCallTracer.SetProtocolName("MyRemoteCallProtocol");

try { string tag = outgoingRemoteCallTracer.GetDynatraceStringTag(); outgoingRemoteCallTracer.TraceAsync(_client.RpcCall(tag)); } catch (Exception e) { outgoingRemoteCallTracer.Error(e); // handle or rethrow } finally { outgoingRemoteCallTracer.End(); } ` Currently we are using the StartAsync and supressing the deprecated log message.

AndersLindPedersen avatar Jan 09 '20 16:01 AndersLindPedersen

Hi Anders,

if I understand your scenario correctly, it should be just possible to write it like this:

...
string tag = outgoingRemoteCallTracer.GetDynatraceStringTag();
outgoingRemoteCallTracer.TraceAsync(() => _client.RpcCall(tag));
...

The TraceAsync operation then takes care of calling Error or End on the tracer.

Hope that helps -Wolfgang

z1c0 avatar Jan 10 '20 08:01 z1c0

Will that not fail? Is the tracer not required to be started prior to invoking GetDynatraceStringTag(). This is atleast what the documentation says for sync scenario.

AndersLindPedersen avatar Jan 10 '20 14:01 AndersLindPedersen

Good point, I think you are indeed right here @AndersLindPedersen. The correct way to use this should be accessing the tracer in the lambda instead of extracting the tag beforehand:

outgoingRemoteCallTracer.TraceAsync(() =>
    _client.RpcCall(outgoingRemoteCallTracer.GetDynatraceStringTag()));

Oberon00 avatar Jan 10 '20 14:01 Oberon00

Thanks @Oberon00, of course that‘s the correct way of doing it. Sorry for overlooking your actual issue in the first place @AndersLindPedersen. Is the suggested approach working for you?

z1c0 avatar Jan 10 '20 15:01 z1c0

Unfortunaly that is not an option for us.

The way our RPC client is structured an POCO header object is early initialized, which needs to include the DynatraceTag. Since this is in a CTOR it is not possible for us to use an async method.

We will continue to use the deperated StartAsync. Please consider this before removing the StartAsync method.

AndersLindPedersen avatar Jan 13 '20 08:01 AndersLindPedersen

Wondering if there is any comments on the last part. Can we count a implementation that supports our scenario when in the future StartAsync is removed?

AndersLindPedersen avatar Jan 16 '20 21:01 AndersLindPedersen

Hi @AndersLindPedersen,

could you please share more information about your scenario, so that I get a better understanding of the problem. Is the POCO / client code out of your control? Otherwise, this sounds like a solvable problem to me by either making the Dynatrace tag settable or just instantiating the whole POCO later.

I know that having to change code due to a breaking API is not pleasant, but StartAsync will be removed for good in future versions in favor of TraceAsync. This decision was not made lightly or arbitrarily, but there are technical limitations, in which the StartAsync pattern simply cannot work generically.

z1c0 avatar Jan 17 '20 08:01 z1c0

So getting a bit back to this since we again are touching this area in the codebase.

Our RPC Client consists of a CommunicationBuffer that is used when ever sending RPC Calls. We have a Communication module consisting of about 150 different RPC calls. When a RPC call the CommunicationBuffer is constructed with header information telling the server what request type it is and other meta data information. Buffer is then appendend with the needed information for the specefic RPC call. To end it all up the RPC call is invoked by sending the command over the wire. We are internally using .NET MemoryStream object, and the nature of the Server implementation requires the client to append the Dynatracetag in the header portion of the CommunicationBuffer:

using (var commBuffer = new CommBuffer(this, "RPC-TYPE-IDENTIFIER")) //CommBuffer initialized header information { //Add RPC specefic data to CommunicationBuffer/MemoryStream commBuffer.WriteString(); //Send the RPC call - would be nice to be able to at this stage already have the tag written to the MemoryStream return await commBuffer.DoRpcCall<T>(); }

Right now the only alternative we have is wrapping all 150 RPC calls in order to inject the tag prior to doing the RPC call.

Does it makes sense?

AndersLindPedersen avatar Sep 08 '20 09:09 AndersLindPedersen

Hi @AndersLindPedersen,

could you extend the code fragment above and demonstrate how you used the SDK calls so far (using StartAsync?) versus this would look now (using TraceAsync)?

z1c0 avatar Sep 09 '20 14:09 z1c0