Skip to content

opentelemetry: fix support for schema_url in opentelemetry plugins (backport of #10201). #10202

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

Open
wants to merge 4 commits into
base: 3.2
Choose a base branch
from
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
10 changes: 10 additions & 0 deletions plugins/in_opentelemetry/opentelemetry_logs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,16 @@ static int binary_payload_to_msgpack(struct flb_opentelemetry *ctx,
if (scope && (scope->name || scope->version || scope->n_attributes > 0)) {
flb_mp_map_header_init(&mh_tmp, &mp_pck);

if (scope_log->schema_url && strlen(scope_log->schema_url) > 0) {
flb_mp_map_header_append(&mh_tmp);
msgpack_pack_str(&mp_pck, 10);
msgpack_pack_str_body(&mp_pck, "schema_url", 10);

len = strlen(scope_log->schema_url);
msgpack_pack_str(&mp_pck, len);
msgpack_pack_str_body(&mp_pck, scope_log->schema_url, len);
}

if (scope->name && strlen(scope->name) > 0) {
flb_mp_map_header_append(&mh_tmp);
msgpack_pack_str(&mp_pck, 4);
Expand Down
1 change: 1 addition & 0 deletions plugins/out_opentelemetry/opentelemetry.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ struct opentelemetry_context {
struct flb_record_accessor *ra_scope_name;
struct flb_record_accessor *ra_scope_version;
struct flb_record_accessor *ra_scope_attr;
struct flb_record_accessor *ra_scope_schema_url;

/* log: metadata components coming from OTLP */
struct flb_record_accessor *ra_log_meta_otlp_observed_ts;
Expand Down
8 changes: 8 additions & 0 deletions plugins/out_opentelemetry/opentelemetry_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,11 @@ struct opentelemetry_context *flb_opentelemetry_context_create(struct flb_output
flb_plg_error(ins, "failed to create record accessor for scope attributes");
}

ctx->ra_scope_schema_url = flb_ra_create("$scope['schema_url']", FLB_FALSE);
if (ctx->ra_scope_schema_url == NULL) {
flb_plg_error(ins, "failed to create record accessor for resource schema url");
}

/* log metadata under $otlp (set by in_opentelemetry) */

ctx->ra_log_meta_otlp_observed_ts = flb_ra_create("$otlp['observed_timestamp']", FLB_FALSE);
Expand Down Expand Up @@ -696,6 +701,9 @@ void flb_opentelemetry_context_destroy(struct opentelemetry_context *ctx)
if (ctx->ra_scope_attr) {
flb_ra_destroy(ctx->ra_scope_attr);
}
if (ctx->ra_scope_schema_url) {
flb_ra_destroy(ctx->ra_scope_schema_url);
}

if (ctx->ra_log_meta_otlp_observed_ts) {
flb_ra_destroy(ctx->ra_log_meta_otlp_observed_ts);
Expand Down
31 changes: 31 additions & 0 deletions plugins/out_opentelemetry/opentelemetry_logs.c
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,34 @@ static int set_resource_schema_url(struct flb_record_accessor *ra,
return 0;
}

static int set_scope_schema_url(struct flb_record_accessor *ra,
msgpack_object *map,
Opentelemetry__Proto__Logs__V1__ScopeLogs *scope_log)
{

struct flb_ra_value *ra_val;

ra_val = flb_ra_get_value_object(ra, *map);
if (ra_val == NULL) {
return -1;
}

if (ra_val->o.type != MSGPACK_OBJECT_STR) {
flb_ra_key_value_destroy(ra_val);
return -1;
}

scope_log->schema_url = flb_sds_create_len(ra_val->o.via.str.ptr,
ra_val->o.via.str.size);
flb_ra_key_value_destroy(ra_val);

if (!scope_log->schema_url) {
return -1;
}

return 0;
}

static int set_scope_name(struct flb_record_accessor *ra,
msgpack_object *map,
Opentelemetry__Proto__Common__V1__InstrumentationScope *scope)
Expand Down Expand Up @@ -1079,6 +1107,9 @@ int otel_process_logs(struct flb_event_chunk *event_chunk,

/* group body: $scope['attributes'] */
set_scope_attributes(ctx->ra_scope_attr, event.body, scope_log->scope);

/* group body: $scope['schema_url'] */
set_scope_schema_url(ctx->ra_scope_schema_url, event.body, scope_log);
}

ret = FLB_OK;
Expand Down
Loading