Click the Start a free trial link to start a 15-day SaaS trial of our product and join our community as a trial user. If you are an existing customer do not start a free trial.
AppDynamics customers and established members should click the sign in button to authenticate.
I'm beginning to use the C SDK and have verified that my C applications can communicate with the controller and post business transactions. However, the application I wish to instrument is a simple HTTP server that is unable to create an appd_bt_handle from within the forked child process (appd_bt_begin() returns 0x0).
I noticed the following mesage in the api_user.log:
2017-06-01 16:52:00.495 UTC ERROR 376 [api_user] Error: const void* appd_bt_begin_with_app_context(const char*, const char*, const char*): Cannot call agent functions from child processes
What is the best approach for generating business transactions for a forked child process, such as a web server? A workaround would be to perform the appd_sdk_init() from within the child process (i.e., the HTTP request handler), but that adds a few seconds to the response time, which is unacceptable.
Solved! Go to Solution.
Sorry for the late reply.
Currently C++ SDK is thread safe but not process safe. So if you create a new child process using fork you won't be able to access SDK there and that's why you are getting a NULL bt handle.I can see that you have created a zendesk ticket already for this.We will continue rest of the discussion there.
Thanks and Regards,
Now that ticket that you have raised regarding this issue is closed,i will post the gist of your discussion with Robb and me here for any future references.
In short C++ SDK is thread safe but not process safe. If your fork creates a new process, you can not access the SDK. If you are trying to implement the SDK on a forked child process, then you will need to initiate the SDK from within each forked process separately (including the appd_sdk_init() call), and all API calls must remain within the same process, you can not share BT or ExitCall handles across processes.Currently to determine whether the future SDK API calls should be accepted or not,it validates if the existing pid is the same as the one which issued appd_sdk_init call . But then if you try to call appd_sdk_init() call from a child process as well it might cause some corruption as SDK implements ZeroMQ messaging in the globally shared process space.Within each instrumented thread, the C/C++ SDK API uses ZeroMQ message buffers (and its underlying Unix sockets) to communicate to the Proxy task.
It should be possible to run two (or more) separate processes, both using the SDK API calls, provided they run completely independently of each other (i.e. do not share handles across process spaces). In other words, as long as each process makes its own appd_sdk_init() call, and use only handles created within that process space/sdk contex, (i.e. that they never share any handles between processes) then you should be able to implement the SDK in a forked process architecture.
Feel free to reach out to us in case you have more questions.
Thanks and Regards,