diff --git a/plugins/out_stackdriver/stackdriver.c b/plugins/out_stackdriver/stackdriver.c index 997ec2f5de5..79813ec2cf1 100644 --- a/plugins/out_stackdriver/stackdriver.c +++ b/plugins/out_stackdriver/stackdriver.c @@ -1288,6 +1288,7 @@ static int pack_json_payload(int insert_id_extracted, ctx->labels_key, ctx->severity_key, ctx->trace_key, + ctx->span_id_key, ctx->log_name_key, stream /* more special fields are required to be added, but, if this grows with more @@ -1465,6 +1466,10 @@ static flb_sds_t stackdriver_format(struct flb_stackdriver *ctx, char stackdriver_trace[PATH_MAX]; const char *new_trace; + /* Parameters for spanID */ + int spanid_extracted = FLB_FALSE; + flb_sds_t spanid; + /* Parameters for log name */ int log_name_extracted = FLB_FALSE; flb_sds_t log_name = NULL; @@ -1817,6 +1822,7 @@ static flb_sds_t stackdriver_format(struct flb_stackdriver *ctx, * "jsonPayload": {...}, * "timestamp": "...", * "trace": "..." + * "spanId": "..." * } */ entry_size = 3; @@ -1837,6 +1843,14 @@ static flb_sds_t stackdriver_format(struct flb_stackdriver *ctx, entry_size += 1; } + /* Extract spanid */ + spanid_extracted = FLB_FALSE; + if (ctx->span_id_key + && get_string(&spanid, obj, ctx->span_id_key) == 0) { + spanid_extracted = FLB_TRUE; + entry_size += 1; + } + /* Extract log name */ log_name_extracted = FLB_FALSE; if (ctx->log_name_key @@ -1941,6 +1955,16 @@ static flb_sds_t stackdriver_format(struct flb_stackdriver *ctx, flb_sds_destroy(trace); } + /* Add spanId into the log entry */ + if (spanid_extracted == FLB_TRUE) { + msgpack_pack_str(&mp_pck, 6); + msgpack_pack_str_body(&mp_pck, "spanId", 6); + len = flb_sds_len(spanid); + msgpack_pack_str(&mp_pck, len); + msgpack_pack_str_body(&mp_pck, spanid, len); + flb_sds_destroy(spanid); + } + /* Add insertId field into the log entry */ if (insert_id_extracted == FLB_TRUE) { msgpack_pack_str(&mp_pck, 8); diff --git a/plugins/out_stackdriver/stackdriver.h b/plugins/out_stackdriver/stackdriver.h index 58ca39c4236..e21778153b5 100644 --- a/plugins/out_stackdriver/stackdriver.h +++ b/plugins/out_stackdriver/stackdriver.h @@ -54,6 +54,7 @@ #define DEFAULT_LABELS_KEY "logging.googleapis.com/labels" #define DEFAULT_SEVERITY_KEY "logging.googleapis.com/severity" #define DEFAULT_TRACE_KEY "logging.googleapis.com/trace" +#define DEFAULT_SPANID_KEY "logging.googleapis.com/spanId" #define DEFAULT_LOG_NAME_KEY "logging.googleapis.com/logName" #define DEFAULT_INSERT_ID_KEY "logging.googleapis.com/insertId" #define SOURCELOCATION_FIELD_IN_JSON "logging.googleapis.com/sourceLocation" @@ -130,6 +131,7 @@ struct flb_stackdriver { flb_sds_t resource; flb_sds_t severity_key; flb_sds_t trace_key; + flb_sds_t span_id_key; flb_sds_t log_name_key; flb_sds_t http_request_key; int http_request_key_size; diff --git a/plugins/out_stackdriver/stackdriver_conf.c b/plugins/out_stackdriver/stackdriver_conf.c index d1d99c52334..43647e089a6 100644 --- a/plugins/out_stackdriver/stackdriver_conf.c +++ b/plugins/out_stackdriver/stackdriver_conf.c @@ -314,6 +314,14 @@ struct flb_stackdriver *flb_stackdriver_conf_create(struct flb_output_instance * ctx->trace_key = flb_sds_create(DEFAULT_TRACE_KEY); } + tmp = flb_output_get_property("span_id_key", ins); + if (tmp) { + ctx->span_id_key = flb_sds_create(tmp); + } + else { + ctx->span_id_key = flb_sds_create(DEFAULT_SPANID_KEY); + } + tmp = flb_output_get_property("log_name_key", ins); if (tmp) { ctx->log_name_key = flb_sds_create(tmp); @@ -525,6 +533,7 @@ int flb_stackdriver_conf_destroy(struct flb_stackdriver *ctx) flb_sds_destroy(ctx->resource); flb_sds_destroy(ctx->severity_key); flb_sds_destroy(ctx->trace_key); + flb_sds_destroy(ctx->span_id_key); flb_sds_destroy(ctx->log_name_key); flb_sds_destroy(ctx->http_request_key); flb_sds_destroy(ctx->labels_key); diff --git a/tests/runtime/data/stackdriver/stackdriver_test_trace.h b/tests/runtime/data/stackdriver/stackdriver_test_trace.h index 15c7bc911ba..44cf011398d 100644 --- a/tests/runtime/data/stackdriver/stackdriver_test_trace.h +++ b/tests/runtime/data/stackdriver/stackdriver_test_trace.h @@ -2,5 +2,6 @@ "1591111124," \ "{" \ "\"trace\": \"test-trace-id-xyz\"" \ + "\"spanId\": \"test-span-id-abc\"" \ "}]" - \ No newline at end of file +