Skip to content

Commit f36be4b

Browse files
cdeckervincenzopalazzo
authored andcommitted
plugin: Add tracing support for send_outreq
The `send_outreq` function is a good place to suspend and resume traces, since these are usually the places where we hand off control back to the `io_loop`. This assumes that we do not continue doing heavy liftin after we have queued an `outreq` call, but that is most likely the case anyway. This frees us from having to track suspensions whenever we call the RPC from a plugin.
1 parent d57accf commit f36be4b

File tree

8 files changed

+54
-7
lines changed

8 files changed

+54
-7
lines changed

bitcoin/test/run-psbt-from-tx.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ u8 *scriptpubkey_p2wsh(const tal_t *ctx UNNEEDED, const u8 *witnessscript UNNEED
6565
/* Generated stub for sha256_double */
6666
void sha256_double(struct sha256_double *shadouble UNNEEDED, const void *p UNNEEDED, size_t len UNNEEDED)
6767
{ fprintf(stderr, "sha256_double called!\n"); abort(); }
68+
/* Generated stub for signature_from_der */
69+
bool signature_from_der(const u8 *der UNNEEDED, size_t len UNNEEDED, struct bitcoin_signature *sig UNNEEDED)
70+
{ fprintf(stderr, "signature_from_der called!\n"); abort(); }
6871
/* Generated stub for signature_to_der */
6972
size_t signature_to_der(u8 der[73] UNNEEDED, const struct bitcoin_signature *sig UNNEEDED)
7073
{ fprintf(stderr, "signature_to_der called!\n"); abort(); }
71-
/* Generated stub for signature_to_der */
72-
bool signature_from_der(const u8 *der UNNEEDED, size_t len UNNEEDED, struct bitcoin_signature *sig UNNEEDED)
73-
{ fprintf(stderr, "signature_from_der called!\n"); abort(); }
7474
/* Generated stub for towire_sha256_double */
7575
void towire_sha256_double(u8 **pptr UNNEEDED, const struct sha256_double *sha256d UNNEEDED)
7676
{ fprintf(stderr, "towire_sha256_double called!\n"); abort(); }

common/test/run-splice_script.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ void command_log(struct command *cmd UNNEEDED, enum log_level level UNNEEDED,
3535
const char *fmt UNNEEDED, ...)
3636

3737
{ fprintf(stderr, "command_log called!\n"); abort(); }
38+
/* Generated stub for mvt_tag_str */
3839
const char *mvt_tag_str(enum mvt_tag tag UNNEEDED)
3940
{ fprintf(stderr, "mvt_tag_str called!\n"); abort(); }
4041
/* AUTOGENERATED MOCKS END */

plugins/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ PLUGIN_COMMANDO_OBJS := $(PLUGIN_COMMANDO_SRC:.c=.o)
2323
PLUGIN_KEYSEND_SRC := plugins/keysend.c
2424
PLUGIN_KEYSEND_OBJS := $(PLUGIN_KEYSEND_SRC:.c=.o)
2525

26-
PLUGIN_LIB_SRC := plugins/libplugin.c
27-
PLUGIN_LIB_HEADER := plugins/libplugin.h
26+
PLUGIN_LIB_SRC := plugins/libplugin.c common/trace.c
27+
PLUGIN_LIB_HEADER := plugins/libplugin.h common/trace.h
2828
PLUGIN_LIB_OBJS := $(PLUGIN_LIB_SRC:.c=.o)
2929

3030
PLUGIN_PAY_LIB_SRC := \

plugins/bkpr/test/run-bkpr_db.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,21 @@ void towire_u8_array(u8 **pptr UNNEEDED, const u8 *arr UNNEEDED, size_t num UNNE
253253
/* Generated stub for towire_wirestring */
254254
void towire_wirestring(u8 **pptr UNNEEDED, const char *str UNNEEDED)
255255
{ fprintf(stderr, "towire_wirestring called!\n"); abort(); }
256+
/* Generated stub for trace_span_end */
257+
void trace_span_end(const void *key UNNEEDED)
258+
{ fprintf(stderr, "trace_span_end called!\n"); abort(); }
259+
/* Generated stub for trace_span_resume */
260+
void trace_span_resume(const void *key UNNEEDED)
261+
{ fprintf(stderr, "trace_span_resume called!\n"); abort(); }
262+
/* Generated stub for trace_span_start */
263+
void trace_span_start(const char *name UNNEEDED, const void *key UNNEEDED)
264+
{ fprintf(stderr, "trace_span_start called!\n"); abort(); }
265+
/* Generated stub for trace_span_suspend */
266+
void trace_span_suspend(const void *key UNNEEDED)
267+
{ fprintf(stderr, "trace_span_suspend called!\n"); abort(); }
268+
/* Generated stub for trace_span_tag */
269+
void trace_span_tag(const void *key UNNEEDED, const char *name UNNEEDED, const char *value UNNEEDED)
270+
{ fprintf(stderr, "trace_span_tag called!\n"); abort(); }
256271
/* AUTOGENERATED MOCKS END */
257272

258273
static char *tmp_dsn(const tal_t *ctx)

plugins/bkpr/test/run-recorder.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,21 @@ void towire_u8_array(u8 **pptr UNNEEDED, const u8 *arr UNNEEDED, size_t num UNNE
259259
/* Generated stub for towire_wirestring */
260260
void towire_wirestring(u8 **pptr UNNEEDED, const char *str UNNEEDED)
261261
{ fprintf(stderr, "towire_wirestring called!\n"); abort(); }
262+
/* Generated stub for trace_span_end */
263+
void trace_span_end(const void *key UNNEEDED)
264+
{ fprintf(stderr, "trace_span_end called!\n"); abort(); }
265+
/* Generated stub for trace_span_resume */
266+
void trace_span_resume(const void *key UNNEEDED)
267+
{ fprintf(stderr, "trace_span_resume called!\n"); abort(); }
268+
/* Generated stub for trace_span_start */
269+
void trace_span_start(const char *name UNNEEDED, const void *key UNNEEDED)
270+
{ fprintf(stderr, "trace_span_start called!\n"); abort(); }
271+
/* Generated stub for trace_span_suspend */
272+
void trace_span_suspend(const void *key UNNEEDED)
273+
{ fprintf(stderr, "trace_span_suspend called!\n"); abort(); }
274+
/* Generated stub for trace_span_tag */
275+
void trace_span_tag(const void *key UNNEEDED, const char *name UNNEEDED, const char *value UNNEEDED)
276+
{ fprintf(stderr, "trace_span_tag called!\n"); abort(); }
262277
/* AUTOGENERATED MOCKS END */
263278

264279
static char *tmp_dsn(const tal_t *ctx)

plugins/libplugin.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <common/memleak.h>
1616
#include <common/plugin.h>
1717
#include <common/route.h>
18+
#include <common/trace.h>
1819
#include <errno.h>
1920
#include <plugins/libplugin.h>
2021
#include <stdio.h>
@@ -1058,7 +1059,14 @@ static void handle_rpc_reply(struct plugin *plugin, const jsmntok_t *toks)
10581059
cmd_freed = false;
10591060
tal_add_destructor2(out->cmd, destroy_cmd_mark_freed, &cmd_freed);
10601061

1062+
trace_span_resume(out);
10611063
contenttok = json_get_member(buf, toks, "error");
1064+
1065+
/* Annotate the JSON-RPC span whether it succeeded or failed,
1066+
* and then emit it. */
1067+
trace_span_tag(out, "error", contenttok ? "true" : "false");
1068+
trace_span_end(out);
1069+
10621070
if (contenttok) {
10631071
if (out->errcb)
10641072
res = out->errcb(out->cmd, out->method, buf, contenttok, out->arg);
@@ -1096,6 +1104,14 @@ send_outreq(const struct out_req *req)
10961104
json_object_end(req->js);
10971105
json_stream_close(req->js, req->cmd);
10981106

1107+
/* We are about to hand control over to the RPC, so suspend
1108+
* the current span. It'll be resumed as soon as we have a
1109+
* result to pass to either the error or the success
1110+
* callback. */
1111+
trace_span_start("jsonrpc", req);
1112+
trace_span_tag(req, "id", req->id);
1113+
trace_span_suspend(req);
1114+
10991115
ld_rpc_send(req->cmd->plugin, req->js);
11001116
notleak_with_children(req->cmd);
11011117
return &pending;

plugins/test/run-route-calc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ void memleak_scan_htable(struct htable *memtable UNNEEDED, const struct htable *
283283
void *notleak_(void *ptr UNNEEDED, bool plus_children UNNEEDED)
284284
{ fprintf(stderr, "notleak_ called!\n"); abort(); }
285285
/* Generated stub for plugin_err */
286-
void plugin_err(struct plugin *p UNNEEDED, const char *fmt UNNEEDED, ...)
286+
void plugin_err(struct plugin *p UNNEEDED, const char *fmt UNNEEDED, ...)
287287
{ fprintf(stderr, "plugin_err called!\n"); abort(); }
288288
/* Generated stub for plugin_log */
289289
void plugin_log(struct plugin *p UNNEEDED, enum log_level l UNNEEDED, const char *fmt UNNEEDED, ...)

plugins/test/run-route-overlong.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ void memleak_scan_htable(struct htable *memtable UNNEEDED, const struct htable *
280280
void *notleak_(void *ptr UNNEEDED, bool plus_children UNNEEDED)
281281
{ fprintf(stderr, "notleak_ called!\n"); abort(); }
282282
/* Generated stub for plugin_err */
283-
void plugin_err(struct plugin *p UNNEEDED, const char *fmt UNNEEDED, ...)
283+
void plugin_err(struct plugin *p UNNEEDED, const char *fmt UNNEEDED, ...)
284284
{ fprintf(stderr, "plugin_err called!\n"); abort(); }
285285
/* Generated stub for plugin_log */
286286
void plugin_log(struct plugin *p UNNEEDED, enum log_level l UNNEEDED, const char *fmt UNNEEDED, ...)

0 commit comments

Comments
 (0)