DataFed icon indicating copy to clipboard operation
DataFed copied to clipboard

[Core] - Logging add correlation id to requests going to foxx api

Open JoshuaSBrown opened this issue 3 months ago • 0 comments

The following needs to be added to dbGet, dbPost, and dbGetRaw

struct curl_slist* headers = nullptr;

// safe: curl_slist_append copies the string internally
headers = curl_slist_append(headers, (std::string("x-correlation-id: ") + log_context.correlation_id).c_str());

// attach headers to the CURL handle
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);

Then after the curl perform call

curl_slist_free_all(headers);

There are several functions where you will need to generate the correlation-id-x from scratch in the core server.

i.e.

in CoreServer

db.notePurge is called in dbMaintenance.
serverPing is called in waitForDB
db.metricsPurge in metricsThread
db.metricsUpdateMsgCounts in metricsThread

in TaskMgr

db.taskLoadReady in initialize
db.taskPurge in purgeTaskHistory

in AuthMap

db.uidByPubKey in hasKey
db.uidByPubKey in getUIDSafe

Can generate a UUID from scratch in C++ using boost.

#include <boost/uuid/uuid.hpp>              // uuid class
#include <boost/uuid/uuid_generators.hpp>   // generators
#include <boost/uuid/uuid_io.hpp>           // streaming operators
#include <iostream>

int main() {
    // Create a random UUID generator
    boost::uuids::random_generator generator;

    // Generate a UUIDv4
    boost::uuids::uuid uuid = generator();

    // Print it
    std::cout << "UUIDv4: " << uuid << std::endl;

    return 0;
}

JoshuaSBrown avatar Sep 30 '25 18:09 JoshuaSBrown