diff --git a/plugins/in_opentelemetry/opentelemetry_prot.c b/plugins/in_opentelemetry/opentelemetry_prot.c index 0de3c3b1221..f6b6f3396d2 100644 --- a/plugins/in_opentelemetry/opentelemetry_prot.c +++ b/plugins/in_opentelemetry/opentelemetry_prot.c @@ -2175,6 +2175,12 @@ static int process_payload_metrics_ng(struct flb_opentelemetry *ctx, offset = 0; + if (request->content_type == NULL) { + flb_error("[otel] content type missing"); + + return -1; + } + if (strcasecmp(request->content_type, "application/grpc") == 0) { if (cfl_sds_len(request->body) < 5) { return -1; @@ -2185,12 +2191,18 @@ static int process_payload_metrics_ng(struct flb_opentelemetry *ctx, cfl_sds_len(request->body) - 5, &offset); } - else { + else if (strcasecmp(request->content_type, "application/x-protobuf") == 0 || + strcasecmp(request->content_type, "application/json") == 0) { result = cmt_decode_opentelemetry_create(&decoded_contexts, request->body, cfl_sds_len(request->body), &offset); } + else { + flb_plg_error(ctx->ins, "Unsupported content type %s", request->content_type); + + return -1; + } if (result == CMT_DECODE_OPENTELEMETRY_SUCCESS) { cfl_list_foreach(iterator, &decoded_contexts) { @@ -2221,6 +2233,12 @@ static int process_payload_traces_proto_ng(struct flb_opentelemetry *ctx, offset = 0; + if (request->content_type == NULL) { + flb_error("[otel] content type missing"); + + return -1; + } + if (strcasecmp(request->content_type, "application/grpc") == 0) { if (cfl_sds_len(request->body) < 5) { return -1; @@ -2231,12 +2249,18 @@ static int process_payload_traces_proto_ng(struct flb_opentelemetry *ctx, cfl_sds_len(request->body) - 5, &offset); } - else { + else if (strcasecmp(request->content_type, "application/x-protobuf") == 0 || + strcasecmp(request->content_type, "application/json") == 0) { result = ctr_decode_opentelemetry_create(&decoded_context, request->body, cfl_sds_len(request->body), &offset); } + else { + flb_plg_error(ctx->ins, "Unsupported content type %s", request->content_type); + + return -1; + } if (result == 0) { result = flb_input_trace_append(ctx->ins, NULL, 0, decoded_context);