Skip to content

Commit

Permalink
http spans
Browse files Browse the repository at this point in the history
  • Loading branch information
braindigitalis committed Aug 8, 2024
1 parent 0433340 commit 1cb822c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 3 deletions.
4 changes: 3 additions & 1 deletion include/ssod/sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ namespace sentry {
* @param query Query to log against the span, e.g. an SQL query
* @return void* Opaque pointer to sentry span
*/
void* span(void* tx, const std::string& query);
void* span(void* tx, const std::string& query, const std::string& op = "db.sql.query");

/**
* @brief Set the span status
Expand Down Expand Up @@ -183,4 +183,6 @@ namespace sentry {

void end_user_transaction();

void* http_span(void* tx, const std::string& url, const std::string& method = "GET");
void end_http_span(void* spn, uint16_t s = 200);
};
60 changes: 58 additions & 2 deletions src/sentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,70 @@ namespace sentry {
);
}

void *span(void *tx, const std::string &query) {
void *span(void *tx, const std::string &query, const std::string& op) {
if (tx) {
std::lock_guard<std::mutex> lock(sentry_mutex);
return sentry_transaction_start_child((sentry_transaction_t *) tx, "db.sql.query", query.c_str());
return sentry_transaction_start_child((sentry_transaction_t *) tx, op.c_str(), query.c_str());
}
return nullptr;
}

void* http_span(void* tx, const std::string& url, const std::string& method) {
void* s = span(tx, method + " " + url, "http.client");
return s;
}

void end_http_span(void* spn, uint16_t s) {
/*
* data: http.query -> uri after ?
* http.fragment -> uri after #
* http.request.method
* http.request.body.size
* origin: DPP
*/
sentry_status status{};
case (s) {
switch 401:
status = STATUS_UNAUTHENTICATED;
break;
switch 403:
status = STATUS_PERMISSION_DENIED;
break;
switch 404:
status = STATUS_NOT_FOUND;
break;
switch 409:
status = STATUS_ALREADY_EXISTS;
break;
switch 413:
status = STATUS_FAILED_PRECONDITION;
break;
switch 429:
status = STATUS_RESOURCE_EXHAUSTED;
break;
switch 501:
status = STATUS_UNIMPLEMENTED;
break;
switch 503:
status = STATUS_UNAVAILABLE;
break;
switch 504:
status = STATUS_DEADLINE_EXCEEDED;
break;
default:
if (s < 400) {
status = STATUS_OK;
} else if (s < 600) {
status = STATUS_INTERNAL_ERROR;
} else {
status = STATUS_UNKNOWN;
}
break;
}
set_span_status(spn, status);
end_span(spn);
}

void set_span_status(void *tx, sentry_status s) {
if (tx) {
std::lock_guard<std::mutex> lock(sentry_mutex);
Expand Down

0 comments on commit 1cb822c

Please sign in to comment.