I want to instrument dubbo which is the popular microservice framework in China, it's default RPC framework is not base on http. For each remote call, this framework will exec a filter chain of which I am going to put the instrument code in.
I am tring to use the public API.
for the consumer filter, I sent the transaction id to provider:
@Override
public Result invoke(
Invoker<?> invoker, Invocation invocation ) throws RpcException
{
Transaction transaction = ElasticApm.startTransaction();
try (final Scope scope = transaction.activate())
{
// this prc context will send to provider
RpcContext.getContext().setAttachment("parentId", transaction.getId());
String name = invocation.getMethodName();
transaction.setName( name );
transaction.setType( Transaction.TYPE_REQUEST );
return invoker.invoke(invocation);
}
catch( Exception e )
{
transaction.captureException( e );
throw e;
}
finally
{
transaction.end();
}
}
for the provider filter, I use the consumer transaction id to create transaction with parent:
@Override
public Result invoke(
Invoker<?> invoker, Invocation invocation ) throws RpcException
{
// use startTransactionWithRemoteParent to create transaction with parent, which id from prc context
Transaction transaction = ElasticApm.startTransactionWithRemoteParent(key -> invocation.getAttachment( "parentId" ));
try (final Scope scope = transaction.activate())
{
String[] interfaceArr = invocation.getAttachment( "interface" ).split( "\\." );
String className = interfaceArr[interfaceArr.length - 1];
String name = className + "#" + invocation.getMethodName();
transaction.setName( name );
transaction.setType( Transaction.TYPE_REQUEST );
return invoker.invoke(invocation);
}
catch( Exception e )
{
transaction.captureException( e );
throw e;
}
finally
{
transaction.end();
}
}
but after I run it, the provider transaction didn't correct set the parent id. actually, in the public API, it do not have clear description about how the build a child-parent relationship between transactions of RPC
Could you please give me a hint about how to do it with the public API? espacially the span.injectTraceHeaders(request::addHeader)
, I don't know how to use it, Thanks in advance!