Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in_opentelemetry: logs: add missing checks for resource and scope #10077

Merged
merged 2 commits into from
Mar 14, 2025
Merged
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
55 changes: 31 additions & 24 deletions plugins/in_opentelemetry/opentelemetry_logs.c
Original file line number Diff line number Diff line change
Expand Up @@ -764,12 +764,14 @@ static int process_json_payload_resource_logs_entry(struct flb_opentelemetry *ct
}

/* resource dropped_attributers_count */
result = find_map_entry_by_key(resource, "droppedAttributesCount", 0, FLB_TRUE);
if (result >= 0) {
obj = resource->ptr[result].val;
flb_log_event_encoder_append_body_values(encoder,
FLB_LOG_EVENT_CSTRING_VALUE("dropped_attributes_count"),
FLB_LOG_EVENT_MSGPACK_OBJECT_VALUE(&obj));
if (resource) {
result = find_map_entry_by_key(resource, "droppedAttributesCount", 0, FLB_TRUE);
if (result >= 0) {
obj = resource->ptr[result].val;
flb_log_event_encoder_append_body_values(encoder,
FLB_LOG_EVENT_CSTRING_VALUE("dropped_attributes_count"),
FLB_LOG_EVENT_MSGPACK_OBJECT_VALUE(&obj));
}
}

/* close resource map */
Expand Down Expand Up @@ -1299,28 +1301,28 @@ static int binary_payload_to_msgpack(struct flb_opentelemetry *ctx,
msgpack_pack_str_body(&mp_pck, "resource", 8);

flb_mp_map_header_init(&mh_tmp, &mp_pck);
if (resource) {
/* look for OTel resource attributes */
if (resource->n_attributes > 0 && resource->attributes) {
flb_mp_map_header_append(&mh_tmp);
msgpack_pack_str(&mp_pck, 10);
msgpack_pack_str_body(&mp_pck, "attributes", 10);

/* look for OTel resource attributes */
if (resource->n_attributes > 0 && resource->attributes) {
flb_mp_map_header_append(&mh_tmp);
msgpack_pack_str(&mp_pck, 10);
msgpack_pack_str_body(&mp_pck, "attributes", 10);

ret = otel_pack_kvarray(&mp_pck,
resource->attributes,
resource->n_attributes);
if (ret != 0) {
return ret;
ret = otel_pack_kvarray(&mp_pck,
resource->attributes,
resource->n_attributes);
if (ret != 0) {
return ret;
}
}
}

if (resource->dropped_attributes_count > 0) {
flb_mp_map_header_append(&mh_tmp);
msgpack_pack_str(&mp_pck, 24);
msgpack_pack_str_body(&mp_pck, "dropped_attributes_count", 24);
msgpack_pack_uint64(&mp_pck, resource->dropped_attributes_count);
if (resource->dropped_attributes_count > 0) {
flb_mp_map_header_append(&mh_tmp);
msgpack_pack_str(&mp_pck, 24);
msgpack_pack_str_body(&mp_pck, "dropped_attributes_count", 24);
msgpack_pack_uint64(&mp_pck, resource->dropped_attributes_count);
}
}

flb_mp_map_header_end(&mh_tmp);

if (resource_log->schema_url) {
Expand All @@ -1340,6 +1342,7 @@ static int binary_payload_to_msgpack(struct flb_opentelemetry *ctx,

/* Scope */
scope = scope_log->scope;

if (scope && (scope->name || scope->version || scope->n_attributes > 0)) {
flb_mp_map_header_init(&mh_tmp, &mp_pck);

Expand Down Expand Up @@ -1384,6 +1387,10 @@ static int binary_payload_to_msgpack(struct flb_opentelemetry *ctx,

flb_mp_map_header_end(&mh_tmp);
}
else {
/* set an empty scope */
msgpack_pack_map(&mp_pck, 0);
}

flb_mp_map_header_end(&mh);

Expand Down
Loading