summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/dbg_malloc.h61
-rw-r--r--include/define.h69
-rw-r--r--include/include.h56
-rw-r--r--include/opentracing-c-wrapper/common.h53
-rw-r--r--include/opentracing-c-wrapper/dbg_malloc.h86
-rw-r--r--include/opentracing-c-wrapper/define.h46
-rw-r--r--include/opentracing-c-wrapper/include.h39
-rw-r--r--include/opentracing-c-wrapper/propagation.h201
-rw-r--r--include/opentracing-c-wrapper/span.h274
-rw-r--r--include/opentracing-c-wrapper/tracer.h93
-rw-r--r--include/opentracing-c-wrapper/util.h110
-rw-r--r--include/opentracing-c-wrapper/value.h60
-rw-r--r--include/span.h94
-rw-r--r--include/tracer.h133
-rw-r--r--include/util.h46
-rw-r--r--include/version.h.in19
16 files changed, 1440 insertions, 0 deletions
diff --git a/include/dbg_malloc.h b/include/dbg_malloc.h
new file mode 100644
index 0000000..b0557be
--- /dev/null
+++ b/include/dbg_malloc.h
@@ -0,0 +1,61 @@
+/***
+ * Copyright 2020 HAProxy Technologies
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _OPENTRACING_C_WRAPPER_DBG_MALLOC_H_
+#define _OPENTRACING_C_WRAPPER_DBG_MALLOC_H_
+
+#ifdef HAVE_MALLOC_H
+# include <malloc.h>
+#endif
+
+
+#define DBG_MEM(l,s,f, ...) \
+ do { \
+ if (dbg_mem == nullptr) \
+ /* Do nothing. */; \
+ else if (!(l) || (dbg_mem->level & (1 << (l)))) \
+ (void)fprintf((s), f "\n", ##__VA_ARGS__); \
+ } while (0)
+#define DBG_MEM_ERR(f, ...) DBG_MEM(0, stderr, "MEM_ERROR: " f, ##__VA_ARGS__)
+#define DBG_MEM_INFO(l,f, ...) DBG_MEM((l), stdout, f, ##__VA_ARGS__)
+
+/* 8 bytes - dBgM (dBgM ^ 0xffffffff) */
+#define DBG_MEM_MAGIC UINT64_C(0x6442674d9bbd98b2)
+#define DBG_MEM_SIZE(n) ((n) + sizeof(struct otc_dbg_mem_metadata))
+#define DBG_MEM_PTR(p) DBG_MEM_SIZE(OT_CAST_TYPEOF(uint8_t *, (p)))
+#define DBG_MEM_DATA(p) OT_CAST_TYPEOF(struct otc_dbg_mem_metadata *, OT_CAST_TYPEOF(uint8_t *, (p)) - DBG_MEM_SIZE(0))
+#define DBG_MEM_RETURN(p) (((p) == nullptr) ? nullptr : DBG_MEM_PTR(p))
+
+struct otc_dbg_mem_metadata {
+ struct otc_dbg_mem_data *data;
+ uint64_t magic;
+};
+
+#ifdef __sun
+#define PRI_MI "lu"
+#else
+#define PRI_MI "d"
+#endif
+
+#endif /* _OPENTRACING_C_WRAPPER_DBG_MALLOC_H_ */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ *
+ * vi: noexpandtab shiftwidth=8 tabstop=8
+ */
diff --git a/include/define.h b/include/define.h
new file mode 100644
index 0000000..1e63fef
--- /dev/null
+++ b/include/define.h
@@ -0,0 +1,69 @@
+/***
+ * Copyright 2020 HAProxy Technologies
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _OPENTRACING_C_WRAPPER_DEFINE_H_
+#define _OPENTRACING_C_WRAPPER_DEFINE_H_
+
+#undef OT_THREADS_NO_LOCKING
+
+#ifdef USE_THREADS
+# define __THR __thread
+#else
+# define __THR
+#endif
+
+#ifdef DEBUG
+# define OTC_DBG_MEM
+# define OT_IFDEF_DBG(a,b) a
+# define OT_EXT_MALLOC(s) otc_ext_malloc(__func__, __LINE__, (s))
+# define OT_EXT_FREE_CLEAR(a) do { if ((a) != nullptr) { otc_ext_free(__func__, __LINE__, a); (a) = nullptr; } } while (0)
+#else
+# define OT_IFDEF_DBG(a,b) b
+# define OT_EXT_MALLOC(s) otc_ext_malloc(s)
+# define OT_EXT_FREE_CLEAR(a) do { if ((a) != nullptr) { otc_ext_free(a); (a) = nullptr; } } while (0)
+#endif
+
+#define OT_FREE(a) do { if ((a) != nullptr) OTC_DBG_FREE(a); } while (0)
+#define OT_FREE_CLEAR(a) do { if ((a) != nullptr) { OTC_DBG_FREE(a); (a) = nullptr; } } while (0)
+
+#define OT_IN_RANGE(v,a,b) (((v) >= (a)) && ((v) <= (b)))
+#define OT_SPAN_KEY_IS_VALID(a) OT_IN_RANGE((a)->idx, 0, ot_span.key - 1)
+#define OT_SPAN_IS_VALID(a) (((a) != nullptr) && OT_SPAN_KEY_IS_VALID(a))
+#define OT_CTX_KEY_IS_VALID(a) OT_IN_RANGE((a)->idx, 0, ot_span_context.key - 1)
+#define OT_CTX_IS_VALID(a) (((a) != nullptr) && (OT_SPAN_IS_VALID((a)->span) || OT_CTX_KEY_IS_VALID(a)))
+
+#define OT_CAST_CONST(t,e) const_cast<t>(e)
+#define OT_CAST_STAT(t,e) static_cast<t>(e)
+#define OT_CAST_REINTERPRET(t,e) reinterpret_cast<t>(e)
+#define OT_CAST_TYPEOF(t,e) OT_CAST_REINTERPRET(typeof(t), (e))
+
+#ifdef __cplusplus
+# define __CPLUSPLUS_DECL_BEGIN extern "C" {
+# define __CPLUSPLUS_DECL_END }
+#else
+# define __CPLUSPLUS_DECL_BEGIN
+# define __CPLUSPLUS_DECL_END
+#endif
+
+#endif /* _OPENTRACING_C_WRAPPER_DEFINE_H_ */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ *
+ * vi: noexpandtab shiftwidth=8 tabstop=8
+ */
diff --git a/include/include.h b/include/include.h
new file mode 100644
index 0000000..85c1b88
--- /dev/null
+++ b/include/include.h
@@ -0,0 +1,56 @@
+/***
+ * Copyright 2020 HAProxy Technologies
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _OPENTRACING_C_WRAPPER_INCLUDE_H_
+#define _OPENTRACING_C_WRAPPER_INCLUDE_H_
+
+#include <cstdio>
+#include <cinttypes>
+#include <stdbool.h>
+#include <sstream>
+#include <mutex>
+
+#include <opentracing/dynamic_load.h>
+#include <opentracing/version.h>
+
+#include "config.h"
+#include "define.h"
+#ifdef DEBUG
+# include "dbg_malloc.h"
+#endif
+
+#include "opentracing-c-wrapper/define.h"
+#include "opentracing-c-wrapper/dbg_malloc.h"
+#include "opentracing-c-wrapper/common.h"
+#include "opentracing-c-wrapper/util.h"
+#include "opentracing-c-wrapper/value.h"
+#include "opentracing-c-wrapper/span.h"
+#include "opentracing-c-wrapper/propagation.h"
+#include "opentracing-c-wrapper/tracer.h"
+
+#include "span.h"
+#include "tracer.h"
+#include "util.h"
+
+#endif /* _OPENTRACING_C_WRAPPER_INCLUDE_H_ */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ *
+ * vi: noexpandtab shiftwidth=8 tabstop=8
+ */
diff --git a/include/opentracing-c-wrapper/common.h b/include/opentracing-c-wrapper/common.h
new file mode 100644
index 0000000..2bac541
--- /dev/null
+++ b/include/opentracing-c-wrapper/common.h
@@ -0,0 +1,53 @@
+/***
+ * Copyright 2020 HAProxy Technologies
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef OPENTRACING_C_WRAPPER_COMMON_H
+#define OPENTRACING_C_WRAPPER_COMMON_H
+
+__CPLUSPLUS_DECL_BEGIN
+
+/***
+ * boolean type
+ */
+typedef enum {
+ otc_false = 0,
+ otc_true = 1,
+} otc_bool_t;
+
+/***
+ * duration type for calculating intervals (monotonic)
+ */
+struct otc_duration {
+ struct timespec value;
+};
+
+/***
+ * timestamp type for absolute time
+ */
+struct otc_timestamp {
+ struct timespec value;
+};
+
+__CPLUSPLUS_DECL_END
+#endif /* OPENTRACING_C_WRAPPER_COMMON_H */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ *
+ * vi: noexpandtab shiftwidth=8 tabstop=8
+ */
diff --git a/include/opentracing-c-wrapper/dbg_malloc.h b/include/opentracing-c-wrapper/dbg_malloc.h
new file mode 100644
index 0000000..4af56ca
--- /dev/null
+++ b/include/opentracing-c-wrapper/dbg_malloc.h
@@ -0,0 +1,86 @@
+/***
+ * Copyright 2020 HAProxy Technologies
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef OPENTRACING_C_WRAPPER_DBG_MALLOC_H
+#define OPENTRACING_C_WRAPPER_DBG_MALLOC_H
+
+__CPLUSPLUS_DECL_BEGIN
+
+#ifdef OTC_DBG_MEM
+
+#define OTC_DBG_MALLOC(s) otc_dbg_malloc(__func__, __LINE__, (s))
+#define OTC_DBG_CALLOC(n,e) otc_dbg_calloc(__func__, __LINE__, (n), (e))
+#define OTC_DBG_REALLOC(p,s) otc_dbg_realloc(__func__, __LINE__, (p), (s))
+#define OTC_DBG_FREE(p) otc_dbg_free(__func__, __LINE__, (p))
+#define OTC_DBG_STRDUP(s) otc_dbg_strdup(__func__, __LINE__, (s))
+#define OTC_DBG_STRNDUP(s,n) otc_dbg_strndup(__func__, __LINE__, (s), (n))
+#define OTC_DBG_MEMDUP(s,n) otc_dbg_memdup(__func__, __LINE__, (s), (n))
+#define OTC_DBG_MEMINFO() otc_dbg_mem_info()
+
+
+struct otc_dbg_mem_data {
+ const void *ptr;
+ size_t size;
+ char func[63];
+ bool used;
+} __attribute__((packed));
+
+struct otc_dbg_mem {
+ struct otc_dbg_mem_data *data;
+ size_t count;
+ size_t unused;
+ size_t reused;
+ uint64_t size;
+ uint64_t op_cnt[4];
+ uint8_t level;
+ pthread_mutex_t mutex;
+};
+
+
+void *otc_dbg_malloc(const char *func, int line, size_t size);
+void *otc_dbg_calloc(const char *func, int line, size_t nelem, size_t elsize);
+void *otc_dbg_realloc(const char *func, int line, void *ptr, size_t size);
+void otc_dbg_free(const char *func, int line, void *ptr);
+char *otc_dbg_strdup(const char *func, int line, const char *s);
+char *otc_dbg_strndup(const char *func, int line, const char *s, size_t size);
+void *otc_dbg_memdup(const char *func, int line, const void *s, size_t size);
+int otc_dbg_mem_init(struct otc_dbg_mem *mem, struct otc_dbg_mem_data *data, size_t count, uint8_t level);
+void otc_dbg_mem_disable(void);
+void otc_dbg_mem_info(void);
+
+#else
+
+#define OTC_DBG_MALLOC(s) malloc(s)
+#define OTC_DBG_CALLOC(n,e) calloc((n), (e))
+#define OTC_DBG_REALLOC(p,s) realloc((p), (s))
+#define OTC_DBG_FREE(p) free(p)
+#define OTC_DBG_STRDUP(s) strdup(s)
+#define OTC_DBG_STRNDUP(s,n) strndup((s), (n))
+#define OTC_DBG_MEMDUP(s,n) mem_dup((s), (n))
+#define OTC_DBG_MEMINFO() while (0)
+
+#endif /* OTC_DBG_MEM */
+
+__CPLUSPLUS_DECL_END
+#endif /* OPENTRACING_C_WRAPPER_DBG_MALLOC_H */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ *
+ * vi: noexpandtab shiftwidth=8 tabstop=8
+ */
diff --git a/include/opentracing-c-wrapper/define.h b/include/opentracing-c-wrapper/define.h
new file mode 100644
index 0000000..457e549
--- /dev/null
+++ b/include/opentracing-c-wrapper/define.h
@@ -0,0 +1,46 @@
+/***
+ * Copyright 2020 HAProxy Technologies
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef OPENTRACING_C_WRAPPER_DEFINE_H
+#define OPENTRACING_C_WRAPPER_DEFINE_H
+
+#define OTC_MAXLOGFIELDS 8
+
+#ifdef __cplusplus
+# define __CPLUSPLUS_DECL_BEGIN extern "C" {
+# define __CPLUSPLUS_DECL_END }
+#else
+# define __CPLUSPLUS_DECL_BEGIN
+# define __CPLUSPLUS_DECL_END
+#endif
+
+#ifdef __GNUC__
+# define OTC_NONNULL(...) __attribute__((nonnull(__VA_ARGS__)))
+# define OTC_NONNULL_ALL __attribute__((nonnull))
+#else
+# define OTC_NONNULL(...)
+# define OTC_NONNULL_ALL
+#endif
+
+#endif /* OPENTRACING_C_WRAPPER_DEFINE_H */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ *
+ * vi: noexpandtab shiftwidth=8 tabstop=8
+ */
diff --git a/include/opentracing-c-wrapper/include.h b/include/opentracing-c-wrapper/include.h
new file mode 100644
index 0000000..ac2f3e4
--- /dev/null
+++ b/include/opentracing-c-wrapper/include.h
@@ -0,0 +1,39 @@
+/***
+ * Copyright 2020 HAProxy Technologies
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef OPENTRACING_C_WRAPPER_INCLUDE_H
+#define OPENTRACING_C_WRAPPER_INCLUDE_H
+
+#include <stdbool.h>
+
+#include <opentracing-c-wrapper/define.h>
+#include <opentracing-c-wrapper/dbg_malloc.h>
+#include <opentracing-c-wrapper/common.h>
+#include <opentracing-c-wrapper/util.h>
+#include <opentracing-c-wrapper/value.h>
+#include <opentracing-c-wrapper/span.h>
+#include <opentracing-c-wrapper/propagation.h>
+#include <opentracing-c-wrapper/tracer.h>
+
+#endif /* OPENTRACING_C_WRAPPER_INCLUDE_H */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ *
+ * vi: noexpandtab shiftwidth=8 tabstop=8
+ */
diff --git a/include/opentracing-c-wrapper/propagation.h b/include/opentracing-c-wrapper/propagation.h
new file mode 100644
index 0000000..636ca37
--- /dev/null
+++ b/include/opentracing-c-wrapper/propagation.h
@@ -0,0 +1,201 @@
+/***
+ * Copyright 2020 HAProxy Technologies
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef OPENTRACING_C_WRAPPER_PROPAGATION_H
+#define OPENTRACING_C_WRAPPER_PROPAGATION_H
+
+__CPLUSPLUS_DECL_BEGIN
+
+/***
+ * span context propagation error codes
+ */
+typedef enum {
+ /***
+ * success
+ */
+ otc_propagation_error_code_success = 0,
+
+ /***
+ * not enough information to extract a span context
+ */
+ otc_propagation_error_code_span_context_not_found = -2,
+
+ /***
+ * invalid/incompatible span context
+ */
+ otc_propagation_error_code_invalid_span_context = -3,
+
+ /***
+ * invalid carrier
+ */
+ otc_propagation_error_code_invalid_carrier = -4,
+
+ /***
+ * corrupted carrier
+ */
+ otc_propagation_error_code_span_context_corrupted = -5,
+
+ /***
+ * unknown error
+ */
+ otc_propagation_error_code_unknown = -6,
+
+ /***
+ * tracer not initialized
+ */
+ otc_propagation_error_code_invalid_tracer = -7,
+
+} otc_propagation_error_code_t;
+
+
+/***
+ * Used to set information into a span context for propagation, entries
+ * are strings in a map of string pointers
+ *
+ * set and get implementations should use the same convention
+ * for naming the keys they manipulate
+ */
+struct otc_text_map_writer {
+ struct otc_text_map text_map;
+
+ /***
+ * NAME
+ * set -
+ *
+ * ARGUMENTS
+ * writer - writer instance
+ * key - string key
+ * value - string value
+ *
+ * DECRTIPTION
+ * set a key-value pair
+ *
+ * RETURN VALUE
+ * otc_propagation_error_code_t - indicates success or failure
+ */
+ otc_propagation_error_code_t (*set)(struct otc_text_map_writer *writer, const char *key, const char *value)
+ OTC_NONNULL(1);
+};
+
+/***
+ * Used to get information from a propagated span context
+ *
+ * set and get implementations should use the same convention
+ * for naming the keys they manipulate
+ */
+struct otc_text_map_reader {
+ struct otc_text_map text_map;
+
+ /***
+ * NAME
+ * foreach_key -
+ *
+ * ARGUMENTS
+ * reader - reader instance
+ * handler - handler function for each key-value pair
+ * arg - user-defined contents
+ *
+ * DESCRIPTION
+ * gets map entries by colling the handler function repeatedly. Returns immediately upon first error
+ *
+ * RETURN VALUE
+ * - error code indicating success or failure.
+ */
+ otc_propagation_error_code_t (*foreach_key)(struct otc_text_map_reader *reader, otc_propagation_error_code_t (*handler)(void *arg, const char *key, const char *value), void *arg)
+ OTC_NONNULL(1, 2);
+};
+
+/***
+ * Used to set HTTP headers
+ */
+struct otc_http_headers_writer {
+ struct otc_text_map text_map;
+
+ otc_propagation_error_code_t (*set)(struct otc_http_headers_writer *writer, const char *key, const char *value)
+ OTC_NONNULL(1);
+};
+
+/***
+ * USed to get HTTP headers
+ */
+struct otc_http_headers_reader {
+ struct otc_text_map text_map;
+
+ otc_propagation_error_code_t (*foreach_key)(struct otc_http_headers_reader *reader, otc_propagation_error_code_t (*handler)(void *arg, const char *key, const char *value), void *arg)
+ OTC_NONNULL(1, 2);
+};
+
+/***
+ * Set/write to a custom format
+ */
+struct otc_custom_carrier_writer {
+ struct otc_binary_data binary_data;
+
+ /***
+ * NAME
+ * inject -
+ *
+ * ARGUMENTS
+ * writer - writer instance
+ * tracer - tracer instance
+ * span_context - span context to write
+ * DESCRIPTION
+ * write a span context into a custom format
+ *
+ * RETURN VALUE
+ * - error code indicating success or failure
+ */
+ otc_propagation_error_code_t (*inject)(struct otc_custom_carrier_writer *writer, const struct otc_tracer *tracer, const struct otc_span_context *span_context)
+ OTC_NONNULL_ALL;
+};
+
+/***
+ * Get from a custom format
+ */
+struct otc_custom_carrier_reader {
+ struct otc_binary_data binary_data;
+
+ /***
+ * NAME
+ * extract -
+ *
+ * ARGUMENTS
+ * reader - reader instance
+ * tracer - tracer instance
+ * span_context - span context pointer to return the decoded
+ * span (can be NULL if propagation failed
+ * or OOM)
+ *
+ * DESCRIPTION
+ * - get a span context from a custom format
+ *
+ * RETURN VALUE
+ * - error code indicating success or failure
+ */
+ otc_propagation_error_code_t (*extract)(struct otc_custom_carrier_reader *reader, const struct otc_tracer *tracer, struct otc_span_context **span_context)
+ OTC_NONNULL_ALL;
+};
+
+__CPLUSPLUS_DECL_END
+#endif /* OPENTRACING_C_WRAPPER_PROPAGATION_H */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ *
+ * vi: noexpandtab shiftwidth=8 tabstop=8
+ */
diff --git a/include/opentracing-c-wrapper/span.h b/include/opentracing-c-wrapper/span.h
new file mode 100644
index 0000000..2ecf8b5
--- /dev/null
+++ b/include/opentracing-c-wrapper/span.h
@@ -0,0 +1,274 @@
+/***
+ * Copyright 2020 HAProxy Technologies
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef OPENTRACING_C_WRAPPER_SPAN_H
+#define OPENTRACING_C_WRAPPER_SPAN_H
+
+__CPLUSPLUS_DECL_BEGIN
+
+/***
+ * Encode a key-value for logging
+ */
+struct otc_log_field {
+ /***
+ * key string
+ */
+ const char *key;
+
+ /***
+ * representation of the value
+ */
+ struct otc_value value;
+};
+
+/***
+ * A log entry for events that occured during the span lifetime
+ */
+struct otc_log_record {
+ /***
+ * event timestamp
+ */
+ struct otc_timestamp timestamp;
+
+ /***
+ * array of log fields
+ */
+ struct otc_log_field *fields;
+
+ /***
+ * number of log fields, must be set to zero if fields is NULL
+ */
+ int num_fields;
+};
+
+typedef enum {
+ /***
+ * parent span that created and also depends on the child span
+ */
+ otc_span_reference_child_of = 1,
+
+ /***
+ * parent span that doesn't dpeend on the child span
+ *
+ * more details in http://opentracing.io/spec/
+ */
+ otc_span_reference_follows_from = 2
+} otc_span_reference_type_t;
+
+struct otc_span_reference {
+ otc_span_reference_type_t type;
+ struct otc_span_context *referenced_context;
+};
+
+struct otc_finish_span_options {
+ /***
+ * time when the span finished (monotonic clock)
+ */
+ struct otc_duration finish_time;
+
+ /***
+ * array with otc_log_record entries
+ */
+ const struct otc_log_record *log_records;
+
+ /***
+ * number of log records, must be set to zero if fields is NULL
+ */
+ int num_log_records;
+};
+
+/***
+ * The span interface
+ */
+struct otc_span {
+ int64_t idx;
+
+ /***
+ * NAME
+ * finish -
+ *
+ * ARGUMENTS
+ * span - span instance
+ *
+ * DESCRIPTION
+ * sets the ending timestamp and finalizes span. Must be the last call for a span instance (except calls to context)
+ */
+ void (*finish)(struct otc_span *span)
+ OTC_NONNULL_ALL;
+
+ /***
+ * NAME
+ * finish_with_options -
+ *
+ * ARGUMENTS
+ * span - span instance
+ * options - override span completion with these options
+ *
+ * DESCRIPTION
+ * finalizes the span but allows for customizing the timestamp and log data
+ */
+ void (*finish_with_options)(struct otc_span *span, const struct otc_finish_span_options *options)
+ OTC_NONNULL(1);
+
+ /***
+ * NAME
+ * otc_span_context -
+ *
+ * ARGUMENTS
+ * span - span instance
+ *
+ * DESCRIPTION
+ * returns an otc_span_context for the span
+ *
+ * RETURN VALUE
+ * span - context for this span
+ */
+ struct otc_span_context *(*span_context)(struct otc_span *span)
+ OTC_NONNULL_ALL;
+
+ /***
+ * NAME
+ * set_operation_name -
+ *
+ * ARGUMENTS
+ * span - span instance
+ * operation_name - new operation name
+ *
+ * DESCRIPTION
+ * set or change the operation name
+ */
+ void (*set_operation_name)(struct otc_span *span, const char *operation_name)
+ OTC_NONNULL_ALL;
+
+ /***
+ * NAME
+ * set_tag
+ *
+ * ARGUMENTS
+ * span - span instance
+ * key - tag key to copy into the span
+ * value - tag value to copy into the span
+ *
+ * DESCRIPTION
+ * add a tag to a span, overwriting any existing tag with the
+ * same key. Tag values supported are strings, numbers and bools
+ */
+ void (*set_tag)(struct otc_span *span, const char *key, const struct otc_value *value)
+ OTC_NONNULL_ALL;
+
+ /***
+ * NAME
+ * log_fields -
+ *
+ * ARGUMENTS
+ * span - span instance
+ * fields - log fields as an array, values should be copied by the implementation
+ * num_fields - number of log fields in the log field array
+ *
+ * DESCRIPTION
+ * store log data for a span
+ */
+ void (*log_fields)(struct otc_span *span, const struct otc_log_field *fields, int num_fields)
+ OTC_NONNULL(1);
+
+ /***
+ * NAME
+ * set_baggage_item -
+ *
+ * ARGUMENTS
+ * span - span instance
+ * key - baggage key
+ * value - baggage value
+ *
+ * DESCRIPTION
+ * store a key-value pair to this span and the associated span
+ * context, also propagating to descendents
+ */
+ void (*set_baggage_item)(struct otc_span *span, const char *key, const char *value)
+ OTC_NONNULL_ALL;
+
+ /***
+ * NAME
+ * baggage_item -
+ *
+ * ARGUMENTS
+ * span - span instance
+ * key - baggage key
+ *
+ * DESCRIPTION
+ * get the baggage for a baggage key
+ *
+ * RETURN VALUE
+ * baggage value for the key, or empty string if the key doesn't exist
+ */
+ const char *(*baggage_item)(const struct otc_span *span, const char *key)
+ OTC_NONNULL_ALL;
+
+ /***
+ * NAME
+ * tracer -
+ *
+ * ARGUMENTS
+ * span - span instance
+ *
+ * DESCRIPTION
+ * returns the tracer that created the span
+ *
+ * RETURN VALUE
+ * tracer instance that creaated the span
+ */
+ struct otc_tracer *(*tracer)(const struct otc_span *span)
+ OTC_NONNULL_ALL;
+
+ /***
+ * NAME
+ * destroy -
+ *
+ * ARGUMENTS
+ * span - span instance
+ */
+ void (*destroy)(struct otc_span **span)
+ OTC_NONNULL_ALL;
+};
+
+/***
+ * interface for span context
+ */
+struct otc_span_context {
+ int64_t idx;
+ const struct otc_span *span;
+
+ /***
+ * NAME
+ * destroy -
+ *
+ * ARGUMENTS
+ * context - instance of span context
+ */
+ void (*destroy)(struct otc_span_context **context)
+ OTC_NONNULL_ALL;
+};
+
+__CPLUSPLUS_DECL_END
+#endif /* OPENTRACING_C_WRAPPER_SPAN_H */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ *
+ * vi: noexpandtab shiftwidth=8 tabstop=8
+ */
diff --git a/include/opentracing-c-wrapper/tracer.h b/include/opentracing-c-wrapper/tracer.h
new file mode 100644
index 0000000..ca27e1e
--- /dev/null
+++ b/include/opentracing-c-wrapper/tracer.h
@@ -0,0 +1,93 @@
+/***
+ * Copyright 2020 HAProxy Technologies
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef OPENTRACING_C_WRAPPER_TRACER_H
+#define OPENTRACING_C_WRAPPER_TRACER_H
+
+__CPLUSPLUS_DECL_BEGIN
+
+struct otc_tag {
+ const char *key;
+ struct otc_value value;
+};
+
+struct otc_start_span_options {
+ struct otc_duration start_time_steady;
+ struct otc_timestamp start_time_system;
+ const struct otc_span_reference *references;
+ int num_references;
+ const struct otc_tag *tags;
+ int num_tags;
+};
+
+/***
+ * tracer interface
+ */
+struct otc_tracer {
+ void (*close)(struct otc_tracer *tracer)
+ OTC_NONNULL_ALL;
+
+ struct otc_span *(*start_span)(struct otc_tracer *tracer, const char *operation_name)
+ OTC_NONNULL_ALL;
+
+ struct otc_span *(*start_span_with_options)(struct otc_tracer *tracer, const char *operation_name, const struct otc_start_span_options *options)
+ OTC_NONNULL(1, 2);
+
+ otc_propagation_error_code_t (*inject_text_map)(struct otc_tracer *tracer, struct otc_text_map_writer *carrier, const struct otc_span_context *span_context)
+ OTC_NONNULL_ALL;
+
+ otc_propagation_error_code_t (*inject_http_headers)(struct otc_tracer *tracer, struct otc_http_headers_writer *carrier, const struct otc_span_context *span_context)
+ OTC_NONNULL_ALL;
+
+ otc_propagation_error_code_t (*inject_binary)(struct otc_tracer *tracer, struct otc_custom_carrier_writer *carrier, const struct otc_span_context *span_context)
+ OTC_NONNULL_ALL;
+
+ otc_propagation_error_code_t (*inject_custom)(struct otc_tracer *tracer, struct otc_custom_carrier_writer *carrier, const struct otc_span_context *span_context)
+ OTC_NONNULL_ALL;
+
+ otc_propagation_error_code_t (*extract_text_map)(struct otc_tracer *tracer, const struct otc_text_map_reader *carrier, struct otc_span_context **span_context)
+ OTC_NONNULL_ALL;
+
+ otc_propagation_error_code_t (*extract_http_headers)(struct otc_tracer *tracer, const struct otc_http_headers_reader *carrier, struct otc_span_context **span_context)
+ OTC_NONNULL_ALL;
+
+ otc_propagation_error_code_t (*extract_binary)(struct otc_tracer *tracer, const struct otc_custom_carrier_reader *carrier, struct otc_span_context **span_context)
+ OTC_NONNULL_ALL;
+
+ otc_propagation_error_code_t (*extract_custom)(struct otc_tracer *tracer, const struct otc_custom_carrier_reader *carrier, struct otc_span_context **span_context)
+ OTC_NONNULL_ALL;
+
+ void (*destroy)(struct otc_tracer **tracer)
+ OTC_NONNULL_ALL;
+};
+
+
+struct otc_tracer *otc_tracer_init(const char *library, const char *cfgfile, const char *cfgbuf, char *errbuf, int errbufsiz);
+struct otc_tracer *otc_tracer_load(const char *library, char *errbuf, int errbufsiz);
+int otc_tracer_start(const char *cfgfile, const char *cfgbuf, char *errbuf, int errbufsiz);
+void otc_tracer_global(struct otc_tracer *tracer);
+void otc_tracer_init_global(struct otc_tracer *tracer);
+
+__CPLUSPLUS_DECL_END
+#endif /* OPENTRACING_C_WRAPPER_TRACER_H */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ *
+ * vi: noexpandtab shiftwidth=8 tabstop=8
+ */
diff --git a/include/opentracing-c-wrapper/util.h b/include/opentracing-c-wrapper/util.h
new file mode 100644
index 0000000..c47c1e4
--- /dev/null
+++ b/include/opentracing-c-wrapper/util.h
@@ -0,0 +1,110 @@
+/***
+ * Copyright 2020 HAProxy Technologies
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef OPENTRACING_C_WRAPPER_UTIL_H
+#define OPENTRACING_C_WRAPPER_UTIL_H
+
+__CPLUSPLUS_DECL_BEGIN
+
+typedef enum {
+ OTC_TEXT_MAP_DUP_KEY = 0x01, /* Duplicate the key data. */
+ OTC_TEXT_MAP_DUP_VALUE = 0x02, /* Duplicate the value data. */
+ OTC_TEXT_MAP_FREE_KEY = 0x04, /* Release the key data. */
+ OTC_TEXT_MAP_FREE_VALUE = 0x08, /* Release the value data. */
+} otc_text_map_flags_t;
+
+struct otc_text_map {
+ char **key;
+ char **value;
+ size_t count;
+ size_t size;
+ bool is_dynamic;
+};
+
+struct otc_binary_data {
+ void *data;
+ size_t size;
+ bool is_dynamic;
+};
+
+/*
+ * Jaeger Trace/Span Identity
+ * uber-trace-id: {trace-id}:{span-id}:{parent-span-id}:{flags}
+ * uberctx-{baggage-key}: {value}
+ *
+ * Zipkin
+ * x-b3-traceid: {trace-id}
+ * x-b3-spanid: {span-id}
+ * x-b3-parentspanid: {parent-span-id}
+ * x-b3-flags: {flags}
+ * x-b3-sampled: {value}
+ * ot-baggage-{baggage-key}: {value}
+ *
+ * DataDog
+ * x-datadog-trace-id: {trace-id}
+ * x-datadog-parent-id: {parent-id}
+ * x-datadog-sampling-priority: {value}
+ * ot-baggage-{baggage-key}: {value}
+ */
+struct otc_jaeger_trace_context {
+ uint64_t trace_id[2]; /* 128-bit random number, value of 0 is not valid. */
+ uint64_t span_id; /* 64-bit random number, value of 0 is not valid. */
+ uint64_t parent_span_id; /* 64-bit parent span id, 0 value is valid and means 'root span' */
+ uint8_t flags; /* 8-bit bitmap, only bits 0 and 1 are used. */
+ uint8_t baggage[0];
+} __attribute__((packed));
+
+struct otc_zipkin_trace_context {
+ uint8_t data[0];
+} __attribute__((packed));
+
+struct otc_dd_trace_context {
+ uint8_t data[0];
+} __attribute__((packed));
+
+
+#ifdef OTC_DBG_MEM
+typedef void *(*otc_ext_malloc_t)(const char *, int, size_t);
+typedef void (*otc_ext_free_t)(const char *, int, void *);
+#else
+typedef void *(*otc_ext_malloc_t)(size_t);
+typedef void (*otc_ext_free_t)(void *);
+#endif
+
+
+void otc_ext_init(otc_ext_malloc_t func_malloc, otc_ext_free_t func_free);
+
+struct otc_text_map *otc_text_map_new(struct otc_text_map *text_map, size_t size);
+int otc_text_map_add(struct otc_text_map *text_map, const char *key, size_t key_len, const char *value, size_t value_len, otc_text_map_flags_t flags);
+void otc_text_map_destroy(struct otc_text_map **text_map, otc_text_map_flags_t flags);
+
+struct otc_binary_data *otc_binary_data_new(struct otc_binary_data *binary_data, const void *data, size_t size);
+void otc_binary_data_destroy(struct otc_binary_data **binary_data);
+
+char *otc_file_read(const char *filename, const char *comment, char *errbuf, int errbufsiz);
+
+void otc_statistics(char *buffer, size_t bufsiz);
+
+__CPLUSPLUS_DECL_END
+#endif /* OPENTRACING_C_WRAPPER_UTIL_H */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ *
+ * vi: noexpandtab shiftwidth=8 tabstop=8
+ */
diff --git a/include/opentracing-c-wrapper/value.h b/include/opentracing-c-wrapper/value.h
new file mode 100644
index 0000000..b9a55fd
--- /dev/null
+++ b/include/opentracing-c-wrapper/value.h
@@ -0,0 +1,60 @@
+/***
+ * Copyright 2020 HAProxy Technologies
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef OPENTRACING_C_WRAPPER_VALUE_H
+#define OPENTRACING_C_WRAPPER_VALUE_H
+
+__CPLUSPLUS_DECL_BEGIN
+
+/***
+ * value types
+ */
+typedef enum {
+ otc_value_bool = 0,
+ otc_value_double,
+ otc_value_int64,
+ otc_value_uint64,
+ otc_value_string,
+ otc_value_null,
+} otc_value_type_t;
+
+
+/***
+ * union for representing various value types
+ */
+struct otc_value {
+
+ otc_value_type_t type;
+
+ union {
+ otc_bool_t bool_value;
+ double double_value;
+ int64_t int64_value;
+ uint64_t uint64_value;
+ const char *string_value;
+ } value;
+};
+
+__CPLUSPLUS_DECL_END
+#endif /* OPENTRACING_C_WRAPPER_VALUE_H */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ *
+ * vi: noexpandtab shiftwidth=8 tabstop=8
+ */
diff --git a/include/span.h b/include/span.h
new file mode 100644
index 0000000..14c0b6c
--- /dev/null
+++ b/include/span.h
@@ -0,0 +1,94 @@
+/***
+ * Copyright 2020 HAProxy Technologies
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _OPENTRACING_C_WRAPPER_SPAN_H_
+#define _OPENTRACING_C_WRAPPER_SPAN_H_
+
+#define OT_LF(a) { fields[a].key, str_value[a] }
+
+
+class otc_hash {
+ public:
+ size_t operator() (int64_t key) const { return key; }
+};
+
+
+class otc_equal_to {
+ public:
+ bool operator() (int64_t a, int64_t b) const { return a == b; }
+};
+
+
+# ifdef OT_THREADS_NO_LOCKING
+template<typename T>
+ using Handle = std::unordered_map<
+ int64_t,
+ std::unique_ptr<T>,
+ otc_hash,
+ otc_equal_to
+ >;
+struct HandleData {
+ int64_t key;
+ int64_t alloc_fail_cnt;
+ int64_t erase_cnt;
+ int64_t destroy_cnt;
+};
+
+# define OT_LOCK_GUARD(a,...)
+# define OT_LOCK(a,b)
+
+extern thread_local Handle<opentracing::Span> ot_span_handle;
+extern thread_local Handle<opentracing::SpanContext> ot_span_context_handle;
+extern struct HandleData ot_span;
+extern struct HandleData ot_span_context;
+# else
+template<typename T> struct Handle {
+ std::unordered_map<
+ int64_t,
+ std::unique_ptr<T>,
+ otc_hash,
+ otc_equal_to
+ > handle;
+ int64_t key;
+ int64_t alloc_fail_cnt;
+ int64_t erase_cnt;
+ int64_t destroy_cnt;
+ std::mutex mutex;
+};
+
+# define ot_span_handle ot_span.handle
+# define ot_span_context_handle ot_span_context.handle
+# define OT_LOCK_GUARD(a,...) const std::lock_guard<std::mutex> guard_##a(ot_##a.mutex, ##__VA_ARGS__)
+# define OT_LOCK(a,b) std::lock(ot_##a.mutex, ot_##b.mutex); OT_LOCK_GUARD(a, std::adopt_lock); OT_LOCK_GUARD(b, std::adopt_lock);
+
+extern struct Handle<opentracing::Span> ot_span;
+extern struct Handle<opentracing::SpanContext> ot_span_context;
+# endif /* OT_THREADS_NO_LOCKING */
+
+
+struct otc_span *ot_span_new(void);
+void ot_nolock_span_destroy(struct otc_span **span);
+struct otc_span_context *ot_span_context_new(const struct otc_span *span);
+
+#endif /* _OPENTRACING_C_WRAPPER_SPAN_H_ */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ *
+ * vi: noexpandtab shiftwidth=8 tabstop=8
+ */
diff --git a/include/tracer.h b/include/tracer.h
new file mode 100644
index 0000000..371f2b5
--- /dev/null
+++ b/include/tracer.h
@@ -0,0 +1,133 @@
+/***
+ * Copyright 2020 HAProxy Technologies
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _OPENTRACING_C_WRAPPER_TRACER_H_
+#define _OPENTRACING_C_WRAPPER_TRACER_H_
+
+using TextMap = std::unordered_map<std::string, std::string>;
+
+
+class TextMapCarrier : public opentracing::TextMapReader, public opentracing::TextMapWriter {
+ public:
+ TextMapCarrier(TextMap &text_map) : tm_data(text_map) {}
+
+ /***
+ * TextMapWriter: Set a key:value pair to the carrier. Multiple calls
+ * to Set() for the same key leads to undefined behavior.
+ */
+ opentracing::expected<void> Set(opentracing::string_view key, opentracing::string_view value) const override
+ {
+ tm_data[key] = value;
+
+ return {};
+ }
+
+ /***
+ * TextMapReader: LookupKey() returns the value for the specified
+ * key if available. If no such key is present, it returns
+ * key_not_found_error.
+ */
+ opentracing::expected<opentracing::string_view> LookupKey(opentracing::string_view key) const override
+ {
+ auto iter = tm_data.find(key);
+ if (iter != tm_data.end())
+ return opentracing::string_view{iter->second};
+
+ return opentracing::make_unexpected(opentracing::key_not_found_error);
+ }
+
+ /***
+ * TextMapReader: ForeachKey() returns TextMap contents via repeated
+ * calls to the f() function. If any call to f() returns an error,
+ * ForeachKey() terminates and returns that error.
+ */
+ opentracing::expected<void> ForeachKey(std::function<opentracing::expected<void>(opentracing::string_view key, opentracing::string_view value)> f) const override
+ {
+ for (const auto &text_map : tm_data) {
+ auto result = f(text_map.first, text_map.second);
+ if (!result)
+ return result;
+ }
+
+ return {};
+ }
+
+ private:
+ TextMap &tm_data;
+};
+
+
+class HTTPHeadersCarrier : public opentracing::HTTPHeadersReader, public opentracing::HTTPHeadersWriter {
+ public:
+ HTTPHeadersCarrier(TextMap &text_map) : tm_data(text_map) {}
+
+ /***
+ * HTTPHeadersWriter: Set a key:value pair to the carrier. Multiple calls
+ * to Set() for the same key leads to undefined behavior.
+ */
+ opentracing::expected<void> Set(opentracing::string_view key, opentracing::string_view value) const override
+ {
+ tm_data[key] = value;
+
+ return {};
+ }
+
+ /***
+ * HTTPHeadersReader: LookupKey() returns the value for the specified
+ * key if available. If no such key is present, it returns
+ * key_not_found_error.
+ */
+ opentracing::expected<opentracing::string_view> LookupKey(opentracing::string_view key) const override
+ {
+ auto iter = tm_data.find(key);
+ if (iter != tm_data.end())
+ return opentracing::string_view{iter->second};
+
+ return opentracing::make_unexpected(opentracing::key_not_found_error);
+ }
+
+ /***
+ * HTTPHeadersReader: ForeachKey() returns TextMap contents via repeated
+ * calls to the f() function. If any call to f() returns an error,
+ * ForeachKey() terminates and returns that error.
+ */
+ opentracing::expected<void> ForeachKey(std::function<opentracing::expected<void>(opentracing::string_view key, opentracing::string_view value)> f) const override
+ {
+ for (const auto &text_map : tm_data) {
+ auto result = f(text_map.first, text_map.second);
+ if (!result)
+ return result;
+ }
+
+ return {};
+ }
+
+ private:
+ TextMap &tm_data;
+};
+
+
+struct otc_tracer *ot_tracer_new(void);
+
+#endif /* _OPENTRACING_C_WRAPPER_TRACER_H_ */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ *
+ * vi: noexpandtab shiftwidth=8 tabstop=8
+ */
diff --git a/include/util.h b/include/util.h
new file mode 100644
index 0000000..50a4109
--- /dev/null
+++ b/include/util.h
@@ -0,0 +1,46 @@
+/***
+ * Copyright 2020 HAProxy Technologies
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _OPENTRACING_C_WRAPPER_UTIL_H_
+#define _OPENTRACING_C_WRAPPER_UTIL_H_
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+
+/* Parameter 'p' must not be in parentheses! */
+#define OT_TEXT_MAP_SIZE(p,n) (sizeof(text_map->p) * (text_map->size + (n)))
+
+
+extern otc_ext_malloc_t otc_ext_malloc;
+extern otc_ext_free_t otc_ext_free;
+
+
+std::chrono::microseconds timespec_to_duration_us(const struct timespec *ts);
+std::chrono::nanoseconds timespec_to_duration(const struct timespec *ts);
+const char *otc_strerror(int errnum);
+
+#endif /* _OPENTRACING_C_WRAPPER_UTIL_H_ */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ *
+ * vi: noexpandtab shiftwidth=8 tabstop=8
+ */
diff --git a/include/version.h.in b/include/version.h.in
new file mode 100644
index 0000000..ea00000
--- /dev/null
+++ b/include/version.h.in
@@ -0,0 +1,19 @@
+#ifndef _OPENTRACING_C_WRAPPER_VERSION_H_
+#define _OPENTRACING_C_WRAPPER_VERSION_H_
+
+#define PACKAGE_AUTHOR "Miroslav Zagorac <mzagorac@haproxy.com>"
+#define PACKAGE_CPP_FLAGS "@CPPFLAGS@"
+#define PACKAGE_DEFS "@DEFS@"
+#define PACKAGE_C_FLAGS "@CFLAGS@"
+#define PACKAGE_CONFIGURE_OPTIONS "@CONFIGURE_OPTIONS@"
+
+#endif /* _OPENTRACING_C_WRAPPER_VERSION_H_ */
+
+/*
+ * Local variables:
+ * c-indent-level: 8
+ * c-basic-offset: 8
+ * End:
+ *
+ * vi: noexpandtab shiftwidth=8 tabstop=8
+ */