Hello all,

In order to enable the assignment of a context name, and yet exclude the
use of that name (prefix in this case) when extracting the context from
the HTTP header, a special character '-' has been added, which can be
specified at the beginning of the prefix.

So let's say if we look at examples of the fe-be configuration, we can
transfer the context via an HTTP header without a prefix like this:

  fe/ot.cfg:
        ..
        span "HAProxy session"
            inject "" use-headers
        event on-backend-http-request

Such a context can be read in another process using a name that has a
special '-' sign at the beginning:

  be/ot.cfg:
    ot-scope frontend_http_request
        extract "-ot-ctx" use-headers
        span "HAProxy session" child-of "-ot-ctx" root
        ..

This means that the context name will be '-ot-ctx' but it will not be
used when extracting data from HTTP headers.

Of course, if the context does not have a prefix set, all HTTP headers
will be inserted into the OpenTracing library as context.  All of the
above will only work correctly if that library can figure out what is
relevant to the context and what is not.

Best regards,

--
Zaga    <miros...@zagorac.name>

What can change the nature of a man?
>From 6ede4cf6e83b327db132e830dd09b728057ae375 Mon Sep 17 00:00:00 2001
From: Miroslav Zagorac <mzago...@haproxy.com>
Date: Wed, 14 Apr 2021 11:47:28 +0200
Subject: [PATCH 2/2] MINOR: opentracing: transfer of context names without
 prefix

In order to enable the assignment of a context name, and yet exclude the
use of that name (prefix in this case) when extracting the context from
the HTTP header, a special character '-' has been added, which can be
specified at the beginning of the prefix.

So let's say if we look at examples of the fe-be configuration, we can
transfer the context via an HTTP header without a prefix like this:

  fe/ot.cfg:
        ..
        span "HAProxy session"
            inject "" use-headers
        event on-backend-http-request

Such a context can be read in another process using a name that has a
special '-' sign at the beginning:

  be/ot.cfg:
    ot-scope frontend_http_request
        extract "-ot-ctx" use-headers
        span "HAProxy session" child-of "-ot-ctx" root
        ..

This means that the context name will be '-ot-ctx' but it will not be
used when extracting data from HTTP headers.

Of course, if the context does not have a prefix set, all HTTP headers
will be inserted into the OpenTracing library as context.  All of the
above will only work correctly if that library can figure out what is
relevant to the context and what is not.
---
 addons/ot/include/parser.h |  1 +
 addons/ot/src/http.c       | 13 +++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/addons/ot/include/parser.h b/addons/ot/include/parser.h
index 5e7b298d5..75a39cc0c 100644
--- a/addons/ot/include/parser.h
+++ b/addons/ot/include/parser.h
@@ -38,6 +38,7 @@
 #define FLT_OT_PARSE_SPAN_REF_CHILD         "child-of"
 #define FLT_OT_PARSE_SPAN_REF_FOLLOWS       "follows-from"
 #define FLT_OT_PARSE_CTX_AUTONAME           "-"
+#define FLT_OT_PARSE_CTX_IGNORE_NAME        '-'
 #define FLT_OT_PARSE_CTX_USE_HEADERS        "use-headers"
 #define FLT_OT_PARSE_CTX_USE_VARS           "use-vars"
 #define FLT_OT_PARSE_OPTION_HARDERR         "hard-errors"
diff --git a/addons/ot/src/http.c b/addons/ot/src/http.c
index 72b31b76f..4a12ed854 100644
--- a/addons/ot/src/http.c
+++ b/addons/ot/src/http.c
@@ -99,6 +99,19 @@ struct otc_text_map *flt_ot_http_headers_get(struct channel *chn, const char *pr
 	if (chn == NULL)
 		FLT_OT_RETURN(retptr);
 
+	/*
+	 * The keyword 'inject' allows you to define the name of the OpenTracing
+	 * context without using a prefix.  In that case all HTTP headers are
+	 * transferred because it is not possible to separate them from the
+	 * OpenTracing context (this separation is usually done via a prefix).
+	 *
+	 * When using the 'extract' keyword, the context name must be specified.
+	 * To allow all HTTP headers to be extracted, the first character of
+	 * that name must be set to FLT_OT_PARSE_CTX_IGNORE_NAME.
+	 */
+	if (FLT_OT_STR_ISVALID(prefix) && (*prefix == FLT_OT_PARSE_CTX_IGNORE_NAME))
+		prefix_len = 0;
+
 	htx = htxbuf(&(chn->buf));
 
 	for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) {
-- 
2.30.1

Reply via email to