mirror of
https://github.com/haproxy/haproxy.git
synced 2026-04-14 21:36:14 -04:00
Replaced the stub filter callbacks with full implementations that dispatch OTel events through the scope execution engine, and added the supporting debug, error handling and utility infrastructure. The filter lifecycle callbacks (init, deinit, init_per_thread) now initialize the OpenTelemetry C wrapper library, create the tracer from the instrumentation configuration file, enable HTX stream filtering, and clean up the configuration and memory pools on shutdown. The stream callbacks (attach, stream_start, stream_set_backend, stream_stop, detach, check_timeouts) create the per-stream runtime context on attach with rate-limit based sampling, fire the corresponding OTel events (on-stream-start, on-backend-set, on-stream-stop), manage the idle timeout timer with reschedule logic in detach, and free the runtime context in check_timeouts. The attach callback also registers the required pre and post channel analyzers from the instrumentation configuration. The channel callbacks (start_analyze, pre_analyze, post_analyze, end_analyze) register per-channel analyzers, map analyzer bits to event indices via flt_otel_get_event(), and dispatch the matching events. The end_analyze callback also fires the on-server-unavailable event when response analyzers were configured but never executed. The HTTP callbacks (http_headers, http_end, http_reply, and the debug-only http_payload and http_reset) dispatch their respective request/response events based on the channel direction. The event dispatcher flt_otel_event_run() in event.c iterates over all scopes matching a given event index and calls flt_otel_scope_run() for each, sharing a common monotonic and wall-clock timestamp across all spans within a single event. Error handling is centralized in flt_otel_return_int() and flt_otel_return_void(), which implement the hard-error/soft-error policy: hard errors disable the filter for the stream, soft errors are silently cleared. The new debug.h header provides conditional debug macros (FLT_OTEL_DBG_ARGS, FLT_OTEL_DBG_BUF) and the FLT_OTEL_LOG macro for structured logging through the instrumentation's log server list. The utility layer gained debug-only label functions for channel direction, proxy mode, stream position, filter type, and analyzer bit name lookups.
55 lines
2.3 KiB
C
55 lines
2.3 KiB
C
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
|
|
#ifndef _OTEL_DEBUG_H_
|
|
#define _OTEL_DEBUG_H_
|
|
|
|
#ifdef DEBUG_FULL
|
|
# define DEBUG_OTEL
|
|
#endif
|
|
|
|
/*
|
|
* FLT_OTEL_DBG_ARGS - include extra debug-only function parameters.
|
|
* FLT_OTEL_DBG_BUF - dump a buffer structure for debugging.
|
|
*
|
|
* When DEBUG_OTEL is not defined, these expand to nothing.
|
|
*/
|
|
#ifdef DEBUG_OTEL
|
|
# define FLT_OTEL_DBG_ARGS(a, ...) a, ##__VA_ARGS__
|
|
# define FLT_OTEL_DBG_BUF(l,a) OTELC_DBG(l, "%p:{ %zu %p %zu %zu }", (a), (a)->size, (a)->area, (a)->data, (a)->head)
|
|
#else
|
|
# define FLT_OTEL_DBG_ARGS(...)
|
|
# define FLT_OTEL_DBG_BUF(...) while (0)
|
|
#endif /* DEBUG_OTEL */
|
|
|
|
/*
|
|
* ON | NOLOGNORM |
|
|
* -----+-----------+-------------
|
|
* 0 | 0 | no log
|
|
* 0 | 1 | no log
|
|
* 1 | 0 | log all
|
|
* 1 | 1 | log errors
|
|
* -----+-----------+-------------
|
|
*/
|
|
#define FLT_OTEL_LOG(l,f, ...) \
|
|
do { \
|
|
if (!(conf->instr->logging & FLT_OTEL_LOGGING_ON)) \
|
|
OTELC_DBG(DEBUG, "NOLOG[%d]: [" FLT_OTEL_SCOPE "]: [%s] " f, (l), conf->id, ##__VA_ARGS__); \
|
|
else if ((conf->instr->logging & FLT_OTEL_LOGGING_NOLOGNORM) && ((l) > LOG_ERR)) \
|
|
OTELC_DBG(NOTICE, "NOLOG[%d]: [" FLT_OTEL_SCOPE "]: [%s] " f, (l), conf->id, ##__VA_ARGS__); \
|
|
else { \
|
|
send_log(&(conf->instr->proxy_log), (l), "[" FLT_OTEL_SCOPE "]: [%s] " f "\n", conf->id, ##__VA_ARGS__); \
|
|
\
|
|
OTELC_DBG(INFO, "LOG[%d]: %s", (l), logline); \
|
|
} \
|
|
} while (0)
|
|
|
|
#endif /* _OTEL_DEBUG_H_ */
|
|
|
|
/*
|
|
* Local variables:
|
|
* c-indent-level: 8
|
|
* c-basic-offset: 8
|
|
* End:
|
|
*
|
|
* vi: noexpandtab shiftwidth=8 tabstop=8
|
|
*/
|