Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
495618a
opentelemetry: add OTLP JSON and protobuf encoders
edsiper Mar 27, 2026
1a12b8f
pack: add otlp_json and otlp_proto formats
edsiper Mar 27, 2026
4d1fb12
pack_json: use pre-processor conditionals for JSON backend
edsiper Mar 27, 2026
ceddbcb
json: new JSON API writer with SIMD and fallback backends
edsiper Mar 27, 2026
9b89564
lib: cmetrics: upgrade to v2.1.0
edsiper Mar 27, 2026
00b2ef1
lib: ctraces: upgrade to v0.7.1
edsiper Mar 27, 2026
0cf39bd
out_stdout: add format otlp json
edsiper Mar 27, 2026
f6800af
out_kafka: add support for OTLP json
edsiper Mar 27, 2026
a1ae9ea
tests: internal: opentelemetry: add format options
edsiper Mar 27, 2026
fe26ec8
build: wire yyjson backend support
edsiper Mar 27, 2026
0ea28bd
oauth2_jwt: use generic JSON pack API
edsiper Mar 27, 2026
4db7393
parser_json: use generic JSON pack API
edsiper Mar 27, 2026
346b8b7
tests: mp: use generic JSON pack API
edsiper Mar 27, 2026
18db0af
out_stdout: fix buffer release
edsiper Mar 27, 2026
1e94703
opentelemetry: merge metrics contexts before protobuf encoding
edsiper Mar 27, 2026
dd8d418
tests: add metrics OTLP protobuf multi-context regression
edsiper Mar 27, 2026
3eb1237
lib: cmetrics: upgrade to v2.1.1
edsiper Mar 27, 2026
7ac632e
opentelemetry: fix C89 loop declarations
edsiper Mar 27, 2026
f3c89ce
input_metric: rotate metric chunks after append
edsiper Mar 27, 2026
bef3946
tests: runtime: log_to_metrics: makes checks binary-safe
edsiper Mar 27, 2026
7f4b071
time: fix nanosecond conversion from uint64
edsiper Mar 27, 2026
b8bdc81
out_kafka: fix OTLP trace EOF handling and event types
edsiper Mar 27, 2026
9db55b9
out_stdout: fix prettified OTLP JSON buffer cleanup
edsiper Mar 27, 2026
0aad83f
json: validate mutable document inputs and ownership
edsiper Mar 27, 2026
a27a6f5
opentelemetry: validate OTLP msgpack keys and binary IDs
edsiper Mar 27, 2026
a106869
tests: internal: opentelemetry: harden setup and cleanup
edsiper Mar 27, 2026
8c69b3d
input: add lock for metric chunk table
edsiper Mar 27, 2026
0b4d464
input_chunk: lock metric chunk table updates
edsiper Mar 27, 2026
00ffa56
input_metric: lock metric chunk table access
edsiper Mar 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -723,15 +723,20 @@ endif()
# ring buffer library
add_subdirectory(${FLB_PATH_LIB_RING_BUFFER} EXCLUDE_FROM_ALL)

# yyson
add_subdirectory(${FLB_PATH_LIB_YYJSON} EXCLUDE_FROM_ALL)
if (TARGET yyjson AND NOT FLB_COVERAGE AND
CMAKE_C_COMPILER_ID MATCHES "GNU|Clang|AppleClang|Intel")
# yyjson's O0 reader can exceed the default coroutine stack budget.
# Keep debug symbols, but force enough optimization to shrink the frame.
target_compile_options(yyjson PRIVATE
$<$<AND:$<COMPILE_LANGUAGE:C>,$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>>:-Og>
)
# yyjson
option(FLB_YYJSON "Enable yyjson backend" ON)
if(FLB_YYJSON)
add_subdirectory(${FLB_PATH_LIB_YYJSON} EXCLUDE_FROM_ALL)
FLB_DEFINITION(FLB_HAVE_YYJSON)

if (TARGET yyjson AND NOT FLB_COVERAGE AND
CMAKE_C_COMPILER_ID MATCHES "GNU|Clang|AppleClang|Intel")
# yyjson's O0 reader can exceed the default coroutine stack budget.
# Keep debug symbols, but force enough optimization to shrink the frame.
target_compile_options(yyjson PRIVATE
$<$<AND:$<COMPILE_LANGUAGE:C>,$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>>:-Og>
)
endif()
endif()

# Avro
Expand Down
5 changes: 4 additions & 1 deletion cmake/headers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ include_directories(
${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_CTRACES}/include
${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_CPROFILES}/include
${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_RING_BUFFER}/lwrb/src/include
${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_YYJSON}/src
${FLB_PATH_ROOT_BINARY_DIR}/${FLB_PATH_LIB_JANSSON}/include
${FLB_PATH_ROOT_BINARY_DIR}/lib/cmetrics
${FLB_PATH_ROOT_BINARY_DIR}/lib/cprofiles/include
Expand All @@ -45,6 +44,10 @@ include_directories(
${FLB_PATH_ROOT_BINARY_DIR}/lib/monkey/include/monkey/
)

if(FLB_YYJSON)
include_directories(${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_YYJSON}/src)
endif()

if(FLB_UTF8_ENCODER)
include_directories(${FLB_PATH_ROOT_SOURCE}/${FLB_PATH_LIB_TUTF8E}/include)
endif()
Expand Down
1 change: 1 addition & 0 deletions include/fluent-bit/flb_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ struct flb_input_instance {
struct flb_hash_table *ht_metric_chunks;
struct flb_hash_table *ht_trace_chunks;
struct flb_hash_table *ht_profile_chunks;
pthread_mutex_t metrics_chunk_lock;

/* TLS settings */
int use_tls; /* bool, try to use TLS for I/O */
Expand Down
106 changes: 106 additions & 0 deletions include/fluent-bit/flb_json.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/* Fluent Bit
* ==========
* Copyright (C) 2015-2026 The Fluent Bit Authors
*
* 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 FLB_JSON_H
#define FLB_JSON_H

#include <stddef.h>

struct flb_json_doc;
struct flb_json_val;
struct flb_json_mut_doc;
struct flb_json_mut_val;

struct flb_json_doc *flb_json_read(const char *input, size_t length);
void flb_json_doc_destroy(struct flb_json_doc *document);
struct flb_json_val *flb_json_doc_get_root(struct flb_json_doc *document);
char *flb_json_write(struct flb_json_doc *document, size_t *length);
char *flb_json_write_pretty(struct flb_json_doc *document, size_t *length);
char *flb_json_prettify(const char *input, size_t input_length, size_t *length);
struct flb_json_val *flb_json_obj_get(struct flb_json_val *value,
const char *key);
size_t flb_json_arr_size(struct flb_json_val *value);
struct flb_json_val *flb_json_arr_get(struct flb_json_val *value, size_t index);

struct flb_json_mut_doc *flb_json_mut_doc_create(void);
void flb_json_mut_doc_destroy(struct flb_json_mut_doc *document);
void flb_json_mut_doc_set_root(struct flb_json_mut_doc *document,
struct flb_json_mut_val *root);
char *flb_json_mut_write(struct flb_json_mut_doc *document, size_t *length);
char *flb_json_mut_write_pretty(struct flb_json_mut_doc *document, size_t *length);

struct flb_json_mut_val *flb_json_mut_obj(struct flb_json_mut_doc *document);
struct flb_json_mut_val *flb_json_mut_arr(struct flb_json_mut_doc *document);
struct flb_json_mut_val *flb_json_mut_strncpy(struct flb_json_mut_doc *document,
const char *value,
size_t length);
struct flb_json_mut_val *flb_json_val_mut_copy(struct flb_json_mut_doc *target,
struct flb_json_val *source);

int flb_json_mut_arr_add_real(struct flb_json_mut_doc *document,
struct flb_json_mut_val *array,
double value);
int flb_json_mut_arr_add_strncpy(struct flb_json_mut_doc *document,
struct flb_json_mut_val *array,
const char *value,
size_t length);
int flb_json_mut_arr_add_val(struct flb_json_mut_val *array,
struct flb_json_mut_val *value);
size_t flb_json_mut_arr_size(struct flb_json_mut_val *array);

int flb_json_mut_obj_add_bool(struct flb_json_mut_doc *document,
struct flb_json_mut_val *object,
const char *key,
int value);
int flb_json_mut_obj_add_int(struct flb_json_mut_doc *document,
struct flb_json_mut_val *object,
const char *key,
long long value);
int flb_json_mut_obj_add_real(struct flb_json_mut_doc *document,
struct flb_json_mut_val *object,
const char *key,
double value);
int flb_json_mut_obj_add_str(struct flb_json_mut_doc *document,
struct flb_json_mut_val *object,
const char *key,
const char *value);
int flb_json_mut_obj_add_strcpy(struct flb_json_mut_doc *document,
struct flb_json_mut_val *object,
const char *key,
const char *value);
int flb_json_mut_obj_add_strn(struct flb_json_mut_doc *document,
struct flb_json_mut_val *object,
const char *key,
const char *value,
size_t length);
int flb_json_mut_obj_add_strncpy(struct flb_json_mut_doc *document,
struct flb_json_mut_val *object,
const char *key,
const char *value,
size_t length);
int flb_json_mut_obj_add_uint(struct flb_json_mut_doc *document,
struct flb_json_mut_val *object,
const char *key,
unsigned long long value);
int flb_json_mut_obj_add_val(struct flb_json_mut_doc *document,
struct flb_json_mut_val *object,
const char *key,
struct flb_json_mut_val *value);

#endif
71 changes: 71 additions & 0 deletions include/fluent-bit/flb_opentelemetry.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define FLB_OPENTELEMETRY_H

#include <fluent-bit/flb_log_event_encoder.h>
#include <fluent-bit/flb_sds.h>
#include <cfl/cfl.h>
#include <msgpack.h>
#include <stdint.h>
Expand Down Expand Up @@ -92,6 +93,32 @@ struct flb_otel_error_map {
int code;
};

struct cmt;
struct ctrace;
struct flb_log_event;

enum flb_opentelemetry_otlp_json_result {
FLB_OPENTELEMETRY_OTLP_JSON_SUCCESS = 0,
FLB_OPENTELEMETRY_OTLP_JSON_INVALID_ARGUMENT = -1,
FLB_OPENTELEMETRY_OTLP_JSON_NOT_SUPPORTED = -2,
FLB_OPENTELEMETRY_OTLP_JSON_INVALID_LOG_EVENT = -3
};

enum flb_opentelemetry_otlp_proto_result {
FLB_OPENTELEMETRY_OTLP_PROTO_SUCCESS = 0,
FLB_OPENTELEMETRY_OTLP_PROTO_INVALID_ARGUMENT = -1,
FLB_OPENTELEMETRY_OTLP_PROTO_NOT_SUPPORTED = -2,
FLB_OPENTELEMETRY_OTLP_PROTO_INVALID_LOG_EVENT = -3
};

struct flb_opentelemetry_otlp_json_options {
int logs_require_otel_metadata;
const char *logs_body_key;
const char **logs_body_keys;
size_t logs_body_key_count;
int logs_body_key_attributes;
};

static struct flb_otel_error_map otel_error_map[] = {
{"FLB_OTEL_RESOURCE_INVALID_ATTRIBUTE", FLB_OTEL_RESOURCE_INVALID_ATTRIBUTE},
{"FLB_OTEL_LOGS_ERR_UNEXPECTED_ROOT_OBJECT_TYPE", FLB_OTEL_LOGS_ERR_UNEXPECTED_ROOT_OBJECT_TYPE},
Expand Down Expand Up @@ -180,6 +207,50 @@ int flb_opentelemetry_metrics_json_to_cmt(struct cfl_list *context_list,
struct ctrace *flb_opentelemetry_json_traces_to_ctrace(const char *body, size_t len,
int *error_status);

/*
* OTLP JSON encoding entry points shared by outputs and processors.
* Traces and metrics are intentionally typed to keep transport plugins
* independent from OpenTelemetry schema details.
*/
flb_sds_t flb_opentelemetry_traces_to_otlp_json(struct ctrace *context,
int *result);

flb_sds_t flb_opentelemetry_traces_msgpack_to_otlp_json(const void *data,
size_t size,
int *result);

flb_sds_t flb_opentelemetry_metrics_to_otlp_json(struct cmt *context,
int *result);

flb_sds_t flb_opentelemetry_metrics_msgpack_to_otlp_json(const void *data,
size_t size,
int *result);

flb_sds_t flb_opentelemetry_logs_to_otlp_json(const void *event_chunk_data,
size_t event_chunk_size,
struct flb_opentelemetry_otlp_json_options *options,
int *result);

flb_sds_t flb_opentelemetry_traces_to_otlp_proto(struct ctrace *context,
int *result);

flb_sds_t flb_opentelemetry_metrics_to_otlp_proto(struct cmt *context,
int *result);

flb_sds_t flb_opentelemetry_metrics_msgpack_to_otlp_proto(const void *data,
size_t size,
int *result);

flb_sds_t flb_opentelemetry_logs_to_otlp_proto(const void *event_chunk_data,
size_t event_chunk_size,
struct flb_opentelemetry_otlp_json_options *options,
int *result);

int flb_opentelemetry_log_is_otlp(struct flb_log_event *log_event);

int flb_opentelemetry_logs_chunk_is_otlp(const void *event_chunk_data,
size_t event_chunk_size);

/* OpenTelemetry utils */
int flb_otel_utils_find_map_entry_by_key(msgpack_object_map *map,
char *key,
Expand Down
6 changes: 4 additions & 2 deletions include/fluent-bit/flb_pack.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
#include <fluent-bit/flb_config.h>

#include <msgpack.h>
#include <yyjson.h>

/* JSON types */
#define FLB_PACK_JSON_UNDEFINED JSMN_UNDEFINED
#define FLB_PACK_JSON_OBJECT JSMN_OBJECT
Expand Down Expand Up @@ -60,6 +58,8 @@
#define FLB_PACK_JSON_FORMAT_JSON 1
#define FLB_PACK_JSON_FORMAT_STREAM 2
#define FLB_PACK_JSON_FORMAT_LINES 3
#define FLB_PACK_JSON_FORMAT_OTLP 4
#define FLB_PACK_JSON_FORMAT_OTLP_PRETTY 5

struct flb_pack_state {
int multiple; /* support multiple jsons? */
Expand All @@ -81,11 +81,13 @@ int flb_pack_json(const char *js, size_t len, char **buffer, size_t *size,
int *root_type, size_t *consumed);
int flb_pack_json_recs(const char *js, size_t len, char **buffer, size_t *size,
int *root_type, int *out_records, size_t *consumed);
#ifdef FLB_HAVE_YYJSON
int flb_pack_json_yyjson(const char *js, size_t len, char **buffer, size_t *size,
int *root_type, size_t *consumed);
int flb_pack_json_recs_yyjson(const char *js, size_t len, char **buffer,
size_t *size, int *root_type, int *out_records,
size_t *consumed);
#endif

int flb_pack_state_init(struct flb_pack_state *s);
void flb_pack_state_reset(struct flb_pack_state *s);
Expand Down
2 changes: 1 addition & 1 deletion include/fluent-bit/flb_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static inline void flb_time_copy(struct flb_time *dst, struct flb_time *src)
static inline void flb_time_from_uint64(struct flb_time *dst, uint64_t value)
{
dst->tm.tv_sec = (long) (value / 1000000000L);
dst->tm.tv_nsec = (long) (value - dst->tm.tv_sec);
dst->tm.tv_nsec = (long) (value - ((uint64_t) dst->tm.tv_sec * 1000000000L));
}

static inline void flb_time_from_double(struct flb_time *dst, double d)
Expand Down
4 changes: 2 additions & 2 deletions lib/cmetrics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# CMetrics Version
set(CMT_VERSION_MAJOR 2)
set(CMT_VERSION_MINOR 0)
set(CMT_VERSION_PATCH 5)
set(CMT_VERSION_MINOR 1)
set(CMT_VERSION_PATCH 1)
set(CMT_VERSION_STR "${CMT_VERSION_MAJOR}.${CMT_VERSION_MINOR}.${CMT_VERSION_PATCH}")

# Include helpers
Expand Down
Loading
Loading