From 9d3dcb800aba0c036b032ccd00197712c3f5d0d9 Mon Sep 17 00:00:00 2001 From: Ava Hahn Date: Thu, 7 Nov 2024 14:14:28 -0800 Subject: otel: add build tooling to include otel code Adds the --otel flag to the configure command and the various build time variables and checks that are needed in this flow. It also includes the nxt_otel.c and nxt_otel.h files that are needed for the rest of Unit to talk to the compiled static library that's generated from the rust crate. Signed-off-by: Ava Hahn Co-authored-by: Gabor Javorszky Signed-off-by: Gabor Javorszky --- src/nxt_otel.h | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/nxt_otel.h (limited to 'src/nxt_otel.h') diff --git a/src/nxt_otel.h b/src/nxt_otel.h new file mode 100644 index 00000000..f5a2de8b --- /dev/null +++ b/src/nxt_otel.h @@ -0,0 +1,72 @@ +/* + * Copyright (C) F5, Inc. + */ + +#ifndef _NXT_OTEL_H_INCLUDED_ +#define _NXT_OTEL_H_INCLUDED_ + +#include +#include + + +#if (NXT_HAVE_OTEL) +extern void nxt_otel_rs_send_trace(void *trace); +extern void * nxt_otel_rs_get_or_create_trace(u_char *trace_id); +extern void nxt_otel_rs_init( + void (*log_callback)(nxt_uint_t log_level, const char *log_string), + const nxt_str_t *endpoint, const nxt_str_t *protocol, + double sample_fraction, double batch_size); +extern void nxt_otel_rs_copy_traceparent(u_char *buffer, void *span); +extern void nxt_otel_rs_add_event_to_trace(void *trace, nxt_str_t *key, + nxt_str_t *val); +extern uint8_t nxt_otel_rs_is_init(void); +extern void nxt_otel_rs_uninit(void); +#endif + + +typedef enum nxt_otel_status_e nxt_otel_status_t; +typedef struct nxt_otel_state_s nxt_otel_state_t; + + +/* + * nxt_otel_status_t + * more efficient than a single handler state struct + */ +enum nxt_otel_status_e { + NXT_OTEL_UNINIT_STATE = 0, + NXT_OTEL_INIT_STATE, + NXT_OTEL_HEADER_STATE, + NXT_OTEL_BODY_STATE, + NXT_OTEL_COLLECT_STATE, + NXT_OTEL_ERROR_STATE, +}; + + +/* + * nxt_otel_state_t + * cache of trace data needed per request and + * includes indicator as to current flow state + */ +struct nxt_otel_state_s { + u_char *trace_id; + u_char *version; + u_char *parent_id; + u_char *trace_flags; + void *trace; + nxt_otel_status_t status; + nxt_str_t trace_state; +}; + + +nxt_int_t nxt_otel_parse_traceparent(void *ctx, nxt_http_field_t *field, + uintptr_t data); +nxt_int_t nxt_otel_parse_tracestate(void *ctx, nxt_http_field_t *field, + uintptr_t data); +void nxt_otel_log_callback(nxt_uint_t log_level, const char *arg); + + +void nxt_otel_test_and_call_state(nxt_task_t *task, nxt_http_request_t *r); +void nxt_otel_request_error_path(nxt_task_t *task, nxt_http_request_t *r); + + +#endif /* _NXT_OTEL_H_INCLUDED_ */ -- cgit From b9066210ac378a6255c1e3de5fc01ee29904a05c Mon Sep 17 00:00:00 2001 From: Ava Hahn Date: Wed, 23 Oct 2024 16:30:39 -0700 Subject: otel: add header parsing and test call state Enables Unit to parse the tracestate and traceparent headers and add it to the list, as well as calls to nxt_otel_test_and_call_state. Signed-off-by: Ava Hahn Signed-off-by: Gabor Javorszky --- src/nxt_otel.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/nxt_otel.h') diff --git a/src/nxt_otel.h b/src/nxt_otel.h index f5a2de8b..112f054c 100644 --- a/src/nxt_otel.h +++ b/src/nxt_otel.h @@ -9,6 +9,13 @@ #include +#if (NXT_HAVE_OTEL) +#define NXT_OTEL_TRACE() nxt_otel_test_and_call_state(task, r) +#else +#define NXT_OTEL_TRACE() +#endif + + #if (NXT_HAVE_OTEL) extern void nxt_otel_rs_send_trace(void *trace); extern void * nxt_otel_rs_get_or_create_trace(u_char *trace_id); -- cgit