cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Can't trace database requests with oneagent SDK for C/C++

hiroshi_aoki
Dynatrace Organizer
Dynatrace Organizer

To trace database requests(SQL) from C language program by
Dynatrace, we are evaluating oneagent SDK.

According to help and github information, we embedded all
necessary APIs and confirmed that the program successfully retrieves database
data as expected. On the other hand, while we can only see the connection
between the C language program(process) and a database process in smartcape and
infograph of C language program(process), we can’t see any database requests
executed by the C language program in Dynatrace.

Is there anything we are missing to capture database
requests(SQL) executed by C language program or our understanding of oneagent
SDK is wrong?

The below is a sample program with oneagent SDK we are using
to trace database requests to mysql. The mysql is only accessed by this
sample program.

----------------------------------------

int main(intargc, char **argv) {

int i = 0;

onesdk_databaseinfo_handle_t db_info_handle = ONESDK_INVALID_HANDLE;

onesdk_tracer_handle_t tracer;

int c;

MYSQL *conn;

MYSQL_RES *res;

MYSQL_ROW row;

constchar query[256] = "SELECT * FROM
AOKI_DATABASE.personal";

constchar *SERV = "localhost";

constchar *USER = "root";

constchar *PASSWORD = "admin";

constchar *DB_NAME = "AOKI_DATABASE";

constunsignedint PORT = 3306;

conn =
mysql_init(NULL);

/* Initialize SDK */

onesdk_result_tconst onesdk_init_result =
onesdk_initialize();

if (onesdk_init_result
!= ONESDK_SUCCESS) {


onesdk_shutdown();


printf("SDK
initialization error ....\n");


exit(1);

}

/* Create Database
Object */


db_info_handle = onesdk_databaseinfo_create(


onesdk_asciistr("AOKI_DATABASE"), /* the name of the
database that you connect to */


onesdk_asciistr(ONESDK_DATABASE_VENDOR_MYSQL), /* the type of the
database */

ONESDK_CHANNEL_TYPE_TCP_IP,
/*
channel type */


onesdk_asciistr("localhost:3306") /* channel endpoint */);

if (db_info_handle == ONESDK_INVALID_HANDLE) {


printf("onesdk_databaseinfo_create()
error...\n");


onesdk_shutdown();


exit(1);

}

/* ... perform the
database request, consume results ... */

/* database -
AOKI_DATABASE, table - personal(id, name) */

if
(!mysql_real_connect(conn, SERV, USER, PASSWORD, DB_NAME, PORT, NULL, 0)) {


fprintf(stderr, "%s\r\n", mysql_error(conn));


exit(-1);

}

for (i = 1; i < 8;
i++) {


tracer = onesdk_databaserequesttracer_create_sql(


db_info_handle,


onesdk_asciistr("SELECT * FROM AOKI_DATABASE.personal"));

if (tracer == ONESDK_INVALID_HANDLE) {


printf("onesdk_databaserequesttracer_create_sql()
eror...\n");


c = getchar();


onesdk_databaseinfo_delete(db_info_handle);


onesdk_shutdown();


exit(1);


}

else


printf("onesdk_databaserequesttracer_create_sql()...sucess\n");

/* start
tracer */


onesdk_tracer_start(tracer);


printf("onesdk_trace_start()...\n");

if (mysql_query(conn,
query)) {


fprintf(stderr, "%s\r\n", mysql_error(conn));


exit(-1);


}


res = mysql_use_result(conn);

while (NULL != (row =
mysql_fetch_row(res))) {

unsignedint col;

for (col = 0; col <
mysql_num_fields(res); col++) {


printf("%s
",
row[col]);


}


printf("\r\n");


}

if (NULL != res) {


mysql_free_result(res);


}


onesdk_tracer_end(tracer);


Sleep(12000);

}

if (NULL != conn) {


mysql_close(conn);

}


onesdk_databaseinfo_delete(db_info_handle);


onesdk_shutdown();

}

-------------------------------------


4 REPLIES 4

skrystosik
DynaMight Guru
DynaMight Guru

Hello, did you checked OneAgent Logs? There is possibility that potential root cause will show up there 🙂

Sebastian


Regards, Sebastian

sonja
Dynatrace Champion
Dynatrace Champion

Hi - just for reference, the question has already been answered by our team on GitHub: https://github.com/Dynatrace/OneAgent-SDK-for-C/is...


Great answer!


Have a nice day!

hiroshi_aoki
Dynatrace Organizer
Dynatrace Organizer

Thank you. I already checked the post on github and learned that we need to use database tracer with remote call APIs.


Featured Posts