Skip to content

Commit fedb047

Browse files
Leonardo Alminanaedsiper
authored andcommitted
in_opentelemetry: restored previous default profiles as text behavior
for the moment, ingesting profiles through the appropriate pipeline is opt-in since that would limit the processing and routing options. Signed-off-by: Leonardo Alminana <[email protected]>
1 parent d0c7f0e commit fedb047

File tree

3 files changed

+80
-4
lines changed

3 files changed

+80
-4
lines changed

plugins/in_opentelemetry/opentelemetry.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ static struct flb_config_map config_map[] = {
208208
"feel free to test it but please do not enable this in production " \
209209
"environments"
210210
},
211+
{
212+
FLB_CONFIG_MAP_BOOL, "encode_profiles_as_text", "true",
213+
0, FLB_TRUE, offsetof(struct flb_opentelemetry, encode_profiles_as_text),
214+
"Encode profiles received as text and ingest them in the logging pipeline"
215+
},
211216

212217
{
213218
FLB_CONFIG_MAP_SIZE, "buffer_max_size", HTTP_BUFFER_MAX_SIZE,

plugins/in_opentelemetry/opentelemetry.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct flb_opentelemetry {
3939
int tag_from_uri;
4040
flb_sds_t logs_metadata_key;
4141
int profile_support_enabled;
42+
int encode_profiles_as_text;
4243

4344
struct flb_input_instance *ins;
4445

plugins/in_opentelemetry/opentelemetry_prot.c

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2670,6 +2670,69 @@ static int process_payload_logs_ng(struct flb_opentelemetry *ctx,
26702670
return ret;
26712671
}
26722672

2673+
static int ingest_profiles_context_as_log_entry(struct flb_opentelemetry *ctx,
2674+
flb_sds_t tag,
2675+
struct cprof *profiles_context)
2676+
{
2677+
cfl_sds_t text_encoded_profiles_context;
2678+
struct flb_log_event_encoder *encoder;
2679+
int ret;
2680+
2681+
encoder = flb_log_event_encoder_create(FLB_LOG_EVENT_FORMAT_FLUENT_BIT_V2);
2682+
2683+
if (encoder == NULL) {
2684+
return -1;
2685+
}
2686+
2687+
ret = cprof_encode_text_create(&text_encoded_profiles_context, profiles_context);
2688+
2689+
if (ret != CPROF_ENCODE_TEXT_SUCCESS) {
2690+
flb_log_event_encoder_destroy(encoder);
2691+
2692+
return -2;
2693+
}
2694+
2695+
flb_log_event_encoder_begin_record(encoder);
2696+
2697+
flb_log_event_encoder_set_current_timestamp(encoder);
2698+
2699+
ret = flb_log_event_encoder_append_body_values(
2700+
encoder,
2701+
FLB_LOG_EVENT_CSTRING_VALUE("Profile"),
2702+
FLB_LOG_EVENT_STRING_VALUE(text_encoded_profiles_context,
2703+
cfl_sds_len(text_encoded_profiles_context)));
2704+
2705+
cprof_encode_text_destroy(text_encoded_profiles_context);
2706+
2707+
if (ret != FLB_EVENT_ENCODER_SUCCESS) {
2708+
flb_log_event_encoder_destroy(encoder);
2709+
2710+
return -3;
2711+
}
2712+
2713+
ret = flb_log_event_encoder_commit_record(encoder);
2714+
2715+
if (ret != FLB_EVENT_ENCODER_SUCCESS) {
2716+
flb_log_event_encoder_destroy(encoder);
2717+
2718+
return -4;
2719+
}
2720+
2721+
ret = flb_input_log_append(ctx->ins,
2722+
tag,
2723+
flb_sds_len(tag),
2724+
encoder->output_buffer,
2725+
encoder->output_length);
2726+
2727+
flb_log_event_encoder_destroy(encoder);
2728+
2729+
if (ret != FLB_EVENT_ENCODER_SUCCESS) {
2730+
return -5;
2731+
}
2732+
2733+
return 0;
2734+
}
2735+
26732736
static int process_payload_profiles_ng(struct flb_opentelemetry *ctx,
26742737
flb_sds_t tag,
26752738
struct flb_http_request *request,
@@ -2719,10 +2782,17 @@ static int process_payload_profiles_ng(struct flb_opentelemetry *ctx,
27192782
return -1;
27202783
}
27212784

2722-
ret = flb_input_profiles_append(ctx->ins,
2723-
tag,
2724-
flb_sds_len(tag),
2725-
profiles_context);
2785+
if (ctx->encode_profiles_as_text) {
2786+
ret = ingest_profiles_context_as_log_entry(ctx,
2787+
tag,
2788+
profiles_context);
2789+
}
2790+
else {
2791+
ret = flb_input_profiles_append(ctx->ins,
2792+
tag,
2793+
flb_sds_len(tag),
2794+
profiles_context);
2795+
}
27262796

27272797
cprof_decode_opentelemetry_destroy(profiles_context);
27282798

0 commit comments

Comments
 (0)