Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions plugins/processor_content_modifier/cm.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ enum {
CM_CONTEXT_OTEL_SCOPE_NAME,
CM_CONTEXT_OTEL_SCOPE_VERSION,
CM_CONTEXT_OTEL_SCOPE_ATTR,
CM_CONTEXT_OTEL_LOG_ATTR,

/* Metrics */
CM_CONTEXT_METRIC_NAME,
Expand Down
3 changes: 3 additions & 0 deletions plugins/processor_content_modifier/cm_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ static int set_context(struct content_modifier_ctx *ctx)
else if (strcasecmp(ctx->context_str, "otel_scope_attributes") == 0) {
context = CM_CONTEXT_OTEL_SCOPE_ATTR;
}
else if (strcasecmp(ctx->context_str, "otel_log_attributes") == 0) {
context = CM_CONTEXT_OTEL_LOG_ATTR;
}
else if (strcasecmp(ctx->context_str, "otel_scope_name") == 0) {
}
else if (strcasecmp(ctx->context_str, "otel_scope_version") == 0) {
Expand Down
57 changes: 57 additions & 0 deletions plugins/processor_content_modifier/cm_logs.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,51 @@ static struct cfl_variant *otel_get_scope(struct flb_mp_chunk_record *record)
return cm_otel_get_scope_metadata(CM_TELEMETRY_LOGS, kvlist);
}

static struct cfl_variant *otel_get_log_attributes(struct flb_mp_chunk_record *record)
{
int ret;
struct cfl_object *obj;
struct cfl_variant *var;
struct cfl_kvpair *kvpair;
struct cfl_kvlist *kvlist;
struct cfl_kvlist *kvlist_tmp;

obj = record->cobj_metadata;
if (!obj || !obj->variant || obj->variant->type != CFL_VARIANT_KVLIST) {
return NULL;
}

kvlist = obj->variant->data.as_kvlist;

var = cfl_kvlist_fetch(kvlist, "otlp");
if (var) {
if (var->type != CFL_VARIANT_KVLIST) {
return NULL;
}
}
else {
kvlist_tmp = cfl_kvlist_create();
if (!kvlist_tmp) {
return NULL;
}

ret = cfl_kvlist_insert_kvlist_s(kvlist, "otlp", 4, kvlist_tmp);
if (ret != 0) {
cfl_kvlist_destroy(kvlist_tmp);
return NULL;
Comment on lines +324 to +326

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid double-freeing otlp kvlist on insert failure

When cfl_kvlist_insert_kvlist_s fails here, it already destroys the wrapped variant (and therefore the kvlist_tmp payload) before returning non-zero (lib/cfl/src/cfl_kvlist.c calls cfl_variant_destroy in its error path). Calling cfl_kvlist_destroy(kvlist_tmp) again in this branch introduces a double free that can crash the process under allocation/insert failure conditions (e.g., memory pressure).

Useful? React with 👍 / 👎.

}

kvpair = cfl_list_entry_last(&kvlist->list, struct cfl_kvpair, _head);
if (!kvpair) {
return NULL;
}

var = kvpair->val;
}

return cm_otel_get_or_create_attributes(var->data.as_kvlist);
}

int cm_logs_process(struct flb_processor_instance *ins,
struct content_modifier_ctx *ctx,
struct flb_mp_chunk_cobj *chunk_cobj,
Expand Down Expand Up @@ -360,6 +405,18 @@ int cm_logs_process(struct flb_processor_instance *ins,
obj_static.variant = var;
obj = &obj_static;
}
else if (ctx->context_type == CM_CONTEXT_OTEL_LOG_ATTR &&
record_type == FLB_LOG_EVENT_NORMAL) {

var = otel_get_log_attributes(record);
if (!var) {
continue;
}

obj_static.type = CFL_VARIANT_KVLIST;
obj_static.variant = var;
obj = &obj_static;
}

if (!obj) {
continue;
Expand Down
3 changes: 2 additions & 1 deletion plugins/processor_content_modifier/cm_opentelemetry.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

#include <cfl/cfl.h>

struct cfl_variant *cm_otel_get_or_create_attributes(struct cfl_kvlist *kvlist);
struct cfl_variant *cm_otel_get_attributes(int telemetry_type, int context, struct cfl_kvlist *kvlist);
struct cfl_variant *cm_otel_get_scope_metadata(int telemetry_type, struct cfl_kvlist *kvlist);

#endif
#endif
Loading
Loading