Hi Chris,

Am 26.05.2022 um 21:49 schrieb Christopher Schultz:
On 5/16/22 13:48, Christopher Schultz wrote:

I see the place in the code where the error is generated, but I'm not familiar enough with the code to know how to add that kind of thing. The function in question (ajp_process_callback) has a pointer to a jk_ws_service_t structure. Is it as simple as also logging like this?

   /* convert start-time to a string */
   char[32] timestamp;
   apr_strftime(timestamp, NULL, 32, "%Y-%m-%d %H:%M:%S", r->r->request_time);
   /* emit a detailed log message */
   jk_log(l, JK_LOG_INFO,
          "(%s) Request to (%s %s) started at %s,%ld",
          ae->worker->name, r->method, r->req_uri, timestamp, r->r->request_time.tm_usec);

Does anyone think this might be generally useful?

It looks like I needed a few more things in order to get this to work:

   {
     char *timestamp = malloc(32);
     apr_time_exp_t *timerec = malloc(sizeof(apr_time_exp_t));
     apache_private_data_t *ap = (apache_private_data_t*)r->ws_private;
     apr_time_exp_gmt(timerec, ap->r->request_time);
     apr_strftime(timestamp, NULL, 32, "%Y-%m-%d %H:%M:%S", timerec);
     /* emit a detailed log message */
     jk_log(l, JK_LOG_INFO,
            "(%s) Request to (%s %s) started at %s",
            ae->worker->name, r->method, r->req_uri, timestamp);
     free(timerec);
     free(timestamp);
   }

The compiler wouldn't let me use an automatically-allocated char[32] so I had to malloc it. I also had to convert from long to apr_time_exp_t which required another structure/malloc as well.

Finally, I had to cast the r->ws_private to apache_private_data_t* which required me to copy/paste the definition of apache_private_data_t from mod_jk.h into jk_ajp_common.c -- just as a test for now.

Obviously, this works only for Apache httpd.

I have it running on one of my web servers for now -- hoping to catch an error and see this additional logging to see if it's helpful to me. (LOL just segfaulted; time to go back and look.)

What would be the best way to get the "start time" of the request in a platform-independent way? Maybe just expand the jk_ws_service structure to include it?

Apart from the info chuck send via PM, I think it would be better to try to add a unique request ID as a correlation ID. Apache can already generate them using mod_unique_id and you can add them there to the access log.

Now how could we make that ID accessible from mod_jk?

We could either add it as a new item to jk_ws_service and I think it would be a good fit. Any server not yet providing it, eg. if we find no way adding it in IIS, would have a null value there (or some constant we init it to). We are free to add things, because we do not really provide a public API used elsewhere which we need to keep stable.

When we do logging in mod_jk, we use jk_log(jk_logger_t *l, ...) where the remaining arguments are just standard log arguments. We could add a new jk_request_log(jk_logger_t *l, jk_ws_service_t *s, ...) and that function retrieves the request ID from s and adds it to the log line.

It seems, typically where we want to log something that would benefit from a request ID, we have the jk_ws_service_t at hand, so could add it to the log call.

WDYT?

Best regards,

Rainer

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to