diff --git a/plugins/out_opentelemetry/opentelemetry.c b/plugins/out_opentelemetry/opentelemetry.c index 6f7ab568a29..cc5680ba3b2 100644 --- a/plugins/out_opentelemetry/opentelemetry.c +++ b/plugins/out_opentelemetry/opentelemetry.c @@ -326,7 +326,7 @@ static int process_metrics(struct flb_event_chunk *event_chunk, result = opentelemetry_http_post(ctx, buf, flb_sds_len(buf), event_chunk->tag, flb_sds_len(event_chunk->tag), - ctx->metrics_uri); + ctx->metrics_uri_sanitized); /* Debug http_post() result statuses */ if (result == FLB_OK) { @@ -416,7 +416,7 @@ static int process_traces(struct flb_event_chunk *event_chunk, result = opentelemetry_http_post(ctx, buf, flb_sds_len(buf), event_chunk->tag, flb_sds_len(event_chunk->tag), - ctx->traces_uri); + ctx->traces_uri_sanitized); /* Debug http_post() result statuses */ if (result == FLB_OK) { diff --git a/plugins/out_opentelemetry/opentelemetry.h b/plugins/out_opentelemetry/opentelemetry.h index a4e188f3708..a43d4184caf 100644 --- a/plugins/out_opentelemetry/opentelemetry.h +++ b/plugins/out_opentelemetry/opentelemetry.h @@ -53,9 +53,13 @@ struct opentelemetry_context { int proxy_port; /* HTTP URI */ + char *traces_uri_sanitized; + char *metrics_uri_sanitized; + char *logs_uri_sanitized; char *traces_uri; char *metrics_uri; char *logs_uri; + char *host; int port; diff --git a/plugins/out_opentelemetry/opentelemetry_conf.c b/plugins/out_opentelemetry/opentelemetry_conf.c index ec44ca02e37..80a193d37b5 100644 --- a/plugins/out_opentelemetry/opentelemetry_conf.c +++ b/plugins/out_opentelemetry/opentelemetry_conf.c @@ -325,29 +325,49 @@ struct opentelemetry_context *flb_opentelemetry_context_create(struct flb_output return NULL; } - logs_uri = sanitize_uri(ctx->logs_uri); - traces_uri = sanitize_uri(ctx->traces_uri); - metrics_uri = sanitize_uri(ctx->metrics_uri); - ctx->u = upstream; ctx->host = ins->host.name; ctx->port = ins->host.port; + ctx->logs_uri_sanitized = sanitize_uri(ctx->logs_uri); + ctx->traces_uri_sanitized = sanitize_uri(ctx->traces_uri); + ctx->metrics_uri_sanitized = sanitize_uri(ctx->metrics_uri); - /* Logs Properties */ - if (logs_uri == NULL) { + if (ctx->logs_uri_sanitized == NULL) { flb_plg_trace(ctx->ins, "Could not allocate memory for sanitized " "log endpoint uri"); + + flb_opentelemetry_context_destroy(ctx); + + return NULL; } - else { - ctx->logs_uri = logs_uri; + + if (ctx->traces_uri_sanitized == NULL) { + flb_plg_trace(ctx->ins, + "Could not allocate memory for sanitized " + "trace endpoint uri"); + + flb_opentelemetry_context_destroy(ctx); + + return NULL; + } + + if (ctx->metrics_uri_sanitized == NULL) { + flb_plg_trace(ctx->ins, + "Could not allocate memory for sanitized " + "metric endpoint uri"); + + flb_opentelemetry_context_destroy(ctx); + + return NULL; } /* list of 'logs_body_key' */ ret = log_body_key_list_create(ctx); if (ret != 0) { flb_opentelemetry_context_destroy(ctx); + return NULL; } @@ -364,25 +384,6 @@ struct opentelemetry_context *flb_opentelemetry_context_create(struct flb_output return NULL; } - if (traces_uri == NULL) { - flb_plg_trace(ctx->ins, - "Could not allocate memory for sanitized " - "trace endpoint uri"); - } - else { - ctx->traces_uri = traces_uri; - } - - if (metrics_uri == NULL) { - flb_plg_trace(ctx->ins, - "Could not allocate memory for sanitized " - "metric endpoint uri"); - } - else { - ctx->metrics_uri = metrics_uri; - } - - /* Set instance flags into upstream */ flb_output_upstream_set(ctx->u, ins); @@ -554,6 +555,18 @@ void flb_opentelemetry_context_destroy(struct opentelemetry_context *ctx) flb_upstream_destroy(ctx->u); } + if (ctx->logs_uri_sanitized != NULL) { + flb_free(ctx->logs_uri_sanitized); + } + + if (ctx->traces_uri_sanitized != NULL) { + flb_free(ctx->traces_uri_sanitized); + } + + if (ctx->metrics_uri_sanitized != NULL) { + flb_free(ctx->metrics_uri_sanitized); + } + /* release log_body_key_list */ log_body_key_list_destroy(ctx); diff --git a/plugins/out_opentelemetry/opentelemetry_logs.c b/plugins/out_opentelemetry/opentelemetry_logs.c index d7b7cea2fb3..f02a21b46fd 100644 --- a/plugins/out_opentelemetry/opentelemetry_logs.c +++ b/plugins/out_opentelemetry/opentelemetry_logs.c @@ -773,7 +773,7 @@ static int logs_flush_to_otel(struct opentelemetry_context *ctx, struct flb_even ret = opentelemetry_http_post(ctx, body, len, event_chunk->tag, flb_sds_len(event_chunk->tag), - ctx->logs_uri); + ctx->logs_uri_sanitized); flb_free(body); return ret;