[ 
https://issues.apache.org/jira/browse/HTRACE-169?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14539306#comment-14539306
 ] 

Colin Patrick McCabe commented on HTRACE-169:
---------------------------------------------

So there are two main ways we could support calling custom span receiver code:
1. Have {{libhtrace.so}} use {{dlopen}} and {{dlsym}} to call into 
user-supplied code.
2. Have {{libhtrace.so}} invoke a callback function supplied by the program 
itself.

The advantage of #1 is that the custom span receiver can be used without any 
code changes.  However, for practicality reasons, the functions invoked this 
way will probably have to have C linkage rather than C\+\+.  The way C\+\+ 
compilers do name mangling is implementation-defined and there can be problems 
using a library compiled with version X of some compiler with a span receiver 
library compiled with version X + 1 of that compiler.  Of course, the developer 
could always write an "extern C" function and have that turn around and call a 
C++ function as its only action.

Approach #2 doesn't have that drawback (we can provide a reasonable C\+\+ 
wrapper for our callbacks), but it does require some modification of the client 
program.  Approach #2 also avoids a dependency on {{libdl.so}} -- but this is a 
pretty trivial or nonexistent advantage, since libdl is supplied with the 
operating system and has sane versioning and ABI.

No matter whether we go with approach #1 or #2, I think the best way to handle 
this is to have a user-defined function that takes a pointer to an opaque 
{{htrace_span}} object, and have a stable API for accessing fields within that 
object (without disclosing the internal representation).  We should also have a 
nice C++ wrapper class in {{htrace.hpp}} like with our other APIs.

We probably also want a span receiver close callback.  This is useful for 
things like short-lived C programs (like simple command line utilities that do 
something and then terminate).  These programs will probably want to free the 
{{htracer}} object before shutting down to ensure that all the spans generated 
by the command-line program get sent out before the process is torn down.

> The HTrace C client should support pluggable span receivers
> -----------------------------------------------------------
>
>                 Key: HTRACE-169
>                 URL: https://issues.apache.org/jira/browse/HTRACE-169
>             Project: HTrace
>          Issue Type: New Feature
>    Affects Versions: 3.2.0
>            Reporter: Colin Patrick McCabe
>            Assignee: Colin Patrick McCabe
>
> The HTrace C client should support pluggable span receivers in much the same 
> way that the Java client supports them.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to