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

out_opentelemetry: fix handling of multiple scopes #8933

Merged
merged 1 commit into from
Jun 10, 2024
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
39 changes: 25 additions & 14 deletions plugins/out_opentelemetry/opentelemetry_logs.c
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,8 @@ int otel_process_logs(struct flb_event_chunk *event_chunk,
int log_record_count;
int max_scopes;
int max_resources;
int64_t prev_group_resource_id = -1;
int64_t prev_group_scope_id = -1;
int64_t resource_id = -1;
int64_t scope_id = -1;
int64_t tmp_resource_id = -1;
Expand Down Expand Up @@ -805,9 +807,14 @@ int otel_process_logs(struct flb_event_chunk *event_chunk,
continue;
}

if (resource_id == -1 && prev_group_resource_id >= 0 && prev_group_resource_id == tmp_resource_id) {
/* continue with the previous resource */
resource_id = prev_group_resource_id;
scope_id = prev_group_scope_id;
}

/* if we have a new resource_id, start a new resource context */
if (resource_id != tmp_resource_id) {

if (export_logs.n_resource_logs >= max_resources) {
flb_plg_error(ctx->ins, "max resources limit reached");
ret = FLB_ERROR;
Expand Down Expand Up @@ -847,15 +854,17 @@ int otel_process_logs(struct flb_event_chunk *event_chunk,
set_resource_schema_url(ctx->ra_resource_schema_url, event.body, resource_log);

/* prepare the scopes */
scope_logs = flb_calloc(100, sizeof(Opentelemetry__Proto__Logs__V1__ScopeLogs *));
if (!scope_logs) {
flb_errno();
ret = FLB_RETRY;
break;
}
if (!resource_log->scope_logs) {
scope_logs = flb_calloc(100, sizeof(Opentelemetry__Proto__Logs__V1__ScopeLogs *));
if (!scope_logs) {
flb_errno();
ret = FLB_RETRY;
break;
}

resource_log->scope_logs = scope_logs;
resource_log->n_scope_logs = 0;
resource_log->scope_logs = scope_logs;
resource_log->n_scope_logs = 0;
}

/* update the current resource_id */
resource_id = tmp_resource_id;
Expand Down Expand Up @@ -893,12 +902,12 @@ int otel_process_logs(struct flb_event_chunk *event_chunk,
flb_errno();
return -2;
}
log_record_count = 0;

scope_log->log_records = log_records;
scope_logs[resource_log->n_scope_logs] = scope_log;
resource_log->scope_logs[resource_log->n_scope_logs] = scope_log;
resource_log->n_scope_logs++;


/* group body: $scope['name'] */
set_scope_name(ctx->ra_scope_name, event.body, scope_log->scope);

Expand All @@ -911,13 +920,14 @@ int otel_process_logs(struct flb_event_chunk *event_chunk,

ret = FLB_OK;

if (record_type == FLB_LOG_EVENT_GROUP_START) {
continue;
}
/* since we are starting a new group, just continue with the next record */
continue;
}
else if (record_type == FLB_LOG_EVENT_GROUP_END) {
/* do nothing */
ret = FLB_OK;
prev_group_resource_id = resource_id;
prev_group_scope_id = scope_id;
resource_id = -1;
scope_id = -1;
continue;
Expand All @@ -944,6 +954,7 @@ int otel_process_logs(struct flb_event_chunk *event_chunk,
ret = FLB_RETRY;
break;
}

log_records[log_record_count] = log_record;
opentelemetry__proto__logs__v1__log_record__init(log_record);

Expand Down
Loading