I have a Rest API service that as part of the workflow does an opensearch search at runtime.
The opensearchpy library logs the following when I do a os_client.search
INFO:opensearch:POST https://x.opensearch.svc.cluster.local:9200/myindex/_search [status:200 request:0.023s]
The request:0.023s data is unattainable to me anywhere else. It’s not the “took” field, it’s not measurable with my own code, so I need this line of log. (at least for now as I don’t know how to intercept the number 0.023 from Opensearch lib)
Now I want to add a session ID into this line of log, so that I know the 0.023s belonged to which request. I know how to add handler to python logs to change datetime formats and stuff. But I can’t find a way to “hijack” the opensearch logger and inject dynamic stuff in there, without touching the library code obviously. So the adapter and filter doesn’t seem to fit my need.
And I can’t make a new logger for each request either. First, getLogger(‘opensearch’) is a shared object, modifying it causes race condition. Second, python logging stuff is known for not getting GC’ed, so I don’t want to debug a memory leak problem. But I don’t know python logging well enough to achieve what I want. Any help is appreciated!