From 34a2cd02ab4e8c512cc23911a3885ed8914e0c0c Mon Sep 17 00:00:00 2001 From: Takahiro Yamashita Date: Sat, 4 Nov 2023 09:10:29 +0900 Subject: [PATCH] in_opentelemetry: support tag_from_uri Signed-off-by: Takahiro Yamashita --- plugins/in_opentelemetry/opentelemetry.c | 5 +++++ plugins/in_opentelemetry/opentelemetry.h | 1 + plugins/in_opentelemetry/opentelemetry_prot.c | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/in_opentelemetry/opentelemetry.c b/plugins/in_opentelemetry/opentelemetry.c index 5cd26f8e69f..46ff4cc6812 100644 --- a/plugins/in_opentelemetry/opentelemetry.c +++ b/plugins/in_opentelemetry/opentelemetry.c @@ -169,6 +169,11 @@ static struct flb_config_map config_map[] = { 0, FLB_TRUE, offsetof(struct flb_opentelemetry, tag_key), "" }, + { + FLB_CONFIG_MAP_BOOL, "tag_from_uri", "true", + 0, FLB_TRUE, offsetof(struct flb_opentelemetry, tag_from_uri), + "If true, tag will be created from uri. e.g. v1_metrics from /v1/metrics ." + }, { FLB_CONFIG_MAP_INT, "successful_response_code", "201", 0, FLB_TRUE, offsetof(struct flb_opentelemetry, successful_response_code), diff --git a/plugins/in_opentelemetry/opentelemetry.h b/plugins/in_opentelemetry/opentelemetry.h index 512f2ab6fd7..57d8df86c69 100644 --- a/plugins/in_opentelemetry/opentelemetry.h +++ b/plugins/in_opentelemetry/opentelemetry.h @@ -35,6 +35,7 @@ struct flb_opentelemetry { flb_sds_t tcp_port; const char *tag_key; bool raw_traces; + int tag_from_uri; size_t buffer_max_size; /* Maximum buffer size */ size_t buffer_chunk_size; /* Chunk allocation size */ diff --git a/plugins/in_opentelemetry/opentelemetry_prot.c b/plugins/in_opentelemetry/opentelemetry_prot.c index 478f24ee7cd..d73f82d87ce 100644 --- a/plugins/in_opentelemetry/opentelemetry_prot.c +++ b/plugins/in_opentelemetry/opentelemetry_prot.c @@ -1578,8 +1578,8 @@ int opentelemetry_prot_handle(struct flb_opentelemetry *ctx, struct http_conn *c /* Compose the query string using the URI */ len = strlen(uri); - if (len == 1) { - tag = NULL; /* use default tag */ + if (ctx->tag_from_uri != FLB_TRUE) { + tag = flb_sds_create(ctx->ins->tag); } else { tag = flb_sds_create_size(len);