|
37 | 37 | #include <ctraces/ctraces.h> |
38 | 38 | #include <ctraces/ctr_decode_msgpack.h> |
39 | 39 |
|
| 40 | +#include <cprofiles/cprofiles.h> |
| 41 | +#include <cprofiles/cprof_decode_msgpack.h> |
| 42 | +#include <cprofiles/cprof_encode_opentelemetry.h> |
| 43 | + |
40 | 44 | extern cfl_sds_t cmt_encode_opentelemetry_create(struct cmt *cmt); |
41 | 45 | extern void cmt_encode_opentelemetry_destroy(cfl_sds_t text); |
42 | 46 |
|
@@ -643,6 +647,88 @@ static int process_traces(struct flb_event_chunk *event_chunk, |
643 | 647 | return result; |
644 | 648 | } |
645 | 649 |
|
| 650 | +static int process_profiles(struct flb_event_chunk *event_chunk, |
| 651 | + struct flb_output_flush *out_flush, |
| 652 | + struct flb_input_instance *ins, void *out_context, |
| 653 | + struct flb_config *config) |
| 654 | +{ |
| 655 | + int ret; |
| 656 | + int result; |
| 657 | + cfl_sds_t encoded_chunk; |
| 658 | + flb_sds_t buf = NULL; |
| 659 | + size_t off = 0; |
| 660 | + struct cprof *profiles_context; |
| 661 | + struct opentelemetry_context *ctx = out_context; |
| 662 | + |
| 663 | + /* Initialize vars */ |
| 664 | + ctx = out_context; |
| 665 | + result = FLB_OK; |
| 666 | + |
| 667 | + buf = flb_sds_create_size(event_chunk->size); |
| 668 | + if (!buf) { |
| 669 | + flb_plg_error(ctx->ins, "could not allocate outgoing buffer"); |
| 670 | + return FLB_RETRY; |
| 671 | + } |
| 672 | + |
| 673 | + flb_plg_debug(ctx->ins, "cprofiles msgpack size: %lu", |
| 674 | + event_chunk->size); |
| 675 | + |
| 676 | + while (cprof_decode_msgpack_create(&profiles_context, |
| 677 | + (unsigned char *) event_chunk->data, |
| 678 | + event_chunk->size, &off) == 0) { |
| 679 | + /* Create a OpenTelemetry payload */ |
| 680 | + ret = cprof_encode_opentelemetry_create(&encoded_chunk, profiles_context); |
| 681 | + if (ret != CPROF_ENCODE_OPENTELEMETRY_SUCCESS) { |
| 682 | + flb_plg_error(ctx->ins, |
| 683 | + "Error encoding context as opentelemetry"); |
| 684 | + result = FLB_ERROR; |
| 685 | + cprof_decode_msgpack_destroy(profiles_context); |
| 686 | + goto exit; |
| 687 | + } |
| 688 | + |
| 689 | + /* concat buffer */ |
| 690 | + ret = flb_sds_cat_safe(&buf, encoded_chunk, flb_sds_len(encoded_chunk)); |
| 691 | + if (ret != 0) { |
| 692 | + flb_plg_error(ctx->ins, "Error appending encoded profiles to buffer"); |
| 693 | + result = FLB_ERROR; |
| 694 | + cprof_encode_opentelemetry_destroy(encoded_chunk); |
| 695 | + cprof_decode_msgpack_destroy(profiles_context); |
| 696 | + goto exit; |
| 697 | + } |
| 698 | + |
| 699 | + /* release */ |
| 700 | + cprof_encode_opentelemetry_destroy(encoded_chunk); |
| 701 | + cprof_decode_msgpack_destroy(profiles_context); |
| 702 | + } |
| 703 | + |
| 704 | + flb_plg_debug(ctx->ins, "final payload size: %lu", flb_sds_len(buf)); |
| 705 | + if (buf && flb_sds_len(buf) > 0) { |
| 706 | + /* Send HTTP request */ |
| 707 | + result = opentelemetry_post(ctx, buf, flb_sds_len(buf), |
| 708 | + event_chunk->tag, |
| 709 | + flb_sds_len(event_chunk->tag), |
| 710 | + ctx->profiles_uri_sanitized, |
| 711 | + ctx->grpc_profiles_uri); |
| 712 | + |
| 713 | + /* Debug http_post() result statuses */ |
| 714 | + if (result == FLB_OK) { |
| 715 | + flb_plg_debug(ctx->ins, "http_post result FLB_OK"); |
| 716 | + } |
| 717 | + else if (result == FLB_ERROR) { |
| 718 | + flb_plg_debug(ctx->ins, "http_post result FLB_ERROR"); |
| 719 | + } |
| 720 | + else if (result == FLB_RETRY) { |
| 721 | + flb_plg_debug(ctx->ins, "http_post result FLB_RETRY"); |
| 722 | + } |
| 723 | + } |
| 724 | + |
| 725 | +exit: |
| 726 | + if (buf) { |
| 727 | + flb_sds_destroy(buf); |
| 728 | + } |
| 729 | + return result; |
| 730 | +} |
| 731 | + |
646 | 732 | static int cb_opentelemetry_exit(void *data, struct flb_config *config) |
647 | 733 | { |
648 | 734 | struct opentelemetry_context *ctx; |
@@ -690,6 +776,9 @@ static void cb_opentelemetry_flush(struct flb_event_chunk *event_chunk, |
690 | 776 | else if (event_chunk->type == FLB_INPUT_TRACES){ |
691 | 777 | result = process_traces(event_chunk, out_flush, ins, out_context, config); |
692 | 778 | } |
| 779 | + else if (event_chunk->type == FLB_INPUT_PROFILES){ |
| 780 | + result = process_profiles(event_chunk, out_flush, ins, out_context, config); |
| 781 | + } |
693 | 782 |
|
694 | 783 | FLB_OUTPUT_RETURN(result); |
695 | 784 | } |
@@ -788,11 +877,24 @@ static struct flb_config_map config_map[] = { |
788 | 877 | "Specify an optional HTTP URI for the target OTel endpoint." |
789 | 878 | }, |
790 | 879 | { |
791 | | - FLB_CONFIG_MAP_STR, "grpc_traces_uri", "/opentelemetry.proto.collector.trace.v1.TraceService/Export", |
| 880 | + FLB_CONFIG_MAP_STR, "grpc_traces_uri", |
| 881 | + "/opentelemetry.proto.collector.trace.v1.TraceService/Export", |
792 | 882 | 0, FLB_TRUE, offsetof(struct opentelemetry_context, grpc_traces_uri), |
793 | 883 | "Specify an optional gRPC URI for the target OTel endpoint." |
794 | 884 | }, |
795 | 885 |
|
| 886 | + { |
| 887 | + FLB_CONFIG_MAP_STR, "profiles_uri", "/v1development/profiles", |
| 888 | + 0, FLB_TRUE, offsetof(struct opentelemetry_context, profiles_uri), |
| 889 | + "Specify an optional HTTP URI for the profiles OTel endpoint." |
| 890 | + }, |
| 891 | + { |
| 892 | + FLB_CONFIG_MAP_STR, "grpc_profiles_uri", |
| 893 | + "/opentelemetry.proto.collector.profiles.v1experimental.ProfilesService/Export", |
| 894 | + 0, FLB_TRUE, offsetof(struct opentelemetry_context, grpc_profiles_uri), |
| 895 | + "Specify an optional gRPC URI for the profiles OTel endpoint." |
| 896 | + }, |
| 897 | + |
796 | 898 | { |
797 | 899 | FLB_CONFIG_MAP_BOOL, "log_response_payload", "true", |
798 | 900 | 0, FLB_TRUE, offsetof(struct opentelemetry_context, log_response_payload), |
@@ -886,7 +988,7 @@ struct flb_output_plugin out_opentelemetry_plugin = { |
886 | 988 | .cb_flush = cb_opentelemetry_flush, |
887 | 989 | .cb_exit = cb_opentelemetry_exit, |
888 | 990 | .config_map = config_map, |
889 | | - .event_type = FLB_OUTPUT_LOGS | FLB_OUTPUT_METRICS | FLB_OUTPUT_TRACES, |
| 991 | + .event_type = FLB_OUTPUT_LOGS | FLB_OUTPUT_METRICS | FLB_OUTPUT_TRACES | FLB_OUTPUT_PROFILES, |
890 | 992 | .flags = FLB_OUTPUT_NET | FLB_IO_OPT_TLS, |
891 | 993 |
|
892 | 994 | .test_formatter.callback = opentelemetry_format_test, |
|
0 commit comments