|
@@ -57,6 +57,7 @@
|
|
|
#endif // __cplusplus
|
|
|
|
|
|
#include "ErrorCode.h"
|
|
|
+#include "httpTrace_define.hpp"
|
|
|
|
|
|
#ifndef MODULE_VERSION_FULL
|
|
|
#define MODULE_VERSION_FULL "0.0.0"
|
|
@@ -395,25 +396,24 @@ struct CLightPackInfo
|
|
|
|
|
|
SPBASE_API CSimpleStringA uuid4_generateStr(int len);
|
|
|
|
|
|
-struct linkContext
|
|
|
-{
|
|
|
+struct linkContext {
|
|
|
CSimpleStringA bussinessId;
|
|
|
CSimpleStringA traceId;
|
|
|
CSimpleStringA spanId;
|
|
|
CSimpleStringA parentSpanId;
|
|
|
+ CSimpleStringA timestamp; // 新增的 timestamp 字段
|
|
|
|
|
|
- linkContext():bussinessId(true), traceId(true), spanId(true), parentSpanId(true){}
|
|
|
- linkContext(CSimpleStringA t_bussinessId, CSimpleStringA t_traceId, CSimpleStringA t_spanId, CSimpleStringA t_parentSpanId) {
|
|
|
- bussinessId = t_bussinessId;
|
|
|
- traceId = t_traceId;
|
|
|
- spanId = t_spanId;
|
|
|
- parentSpanId = t_parentSpanId;
|
|
|
+ linkContext() : bussinessId(true), traceId(true), spanId(true), parentSpanId(true) {
|
|
|
+ updateTimestamp(); // 初始化时生成时间戳
|
|
|
}
|
|
|
|
|
|
- void Init(const char* t_bussId, const char* t_traceId, const char* t_spanId, const char* t_parentSpanId)
|
|
|
- {
|
|
|
- if (t_bussId && t_traceId && t_spanId && t_parentSpanId)
|
|
|
- {
|
|
|
+ linkContext(CSimpleStringA t_bussinessId, CSimpleStringA t_traceId, CSimpleStringA t_spanId, CSimpleStringA t_parentSpanId)
|
|
|
+ : bussinessId(t_bussinessId), traceId(t_traceId), spanId(t_spanId), parentSpanId(t_parentSpanId) {
|
|
|
+ updateTimestamp(); // 初始化时生成时间戳
|
|
|
+ }
|
|
|
+
|
|
|
+ void Init(const char* t_bussId, const char* t_traceId, const char* t_spanId, const char* t_parentSpanId) {
|
|
|
+ if (t_bussId && t_traceId && t_spanId && t_parentSpanId) {
|
|
|
char copy_bussId[LINKINFO_BUSSID_LEN + 1], copy_traceId[LINKINFO_TRACEID_LEN + 1];
|
|
|
char copy_spanId[LINKINFO_SPANID_LEN + 1], copy_parentSpanId[LINKINFO_PARENTSPANID_LEN + 1];
|
|
|
memset(copy_bussId, 0, sizeof(copy_bussId));
|
|
@@ -428,21 +428,47 @@ struct linkContext
|
|
|
traceId = copy_traceId;
|
|
|
spanId = copy_spanId;
|
|
|
parentSpanId = copy_parentSpanId;
|
|
|
+ updateTimestamp(); // 初始化时生成时间戳
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ void updateTimestamp()
|
|
|
+ {
|
|
|
+ time_t timestamp_seconds = time(NULL);
|
|
|
+
|
|
|
+ // 将时间戳转换为字符串
|
|
|
+ timestamp = CSimpleStringA::Format("%ld", timestamp_seconds);
|
|
|
+ }
|
|
|
+ HttpClientTraceLink convertToHttpClientTraceLink()
|
|
|
+ {
|
|
|
+ HttpClientTraceLink traceLink;
|
|
|
+ memset(&traceLink, 0, sizeof(traceLink)); // 初始化结构体
|
|
|
+
|
|
|
+ // 复制字段数据
|
|
|
+ strncpy(traceLink.X_B3_BusinessId, bussinessId.GetData(), sizeof(traceLink.X_B3_BusinessId) - 1);
|
|
|
+ strncpy(traceLink.X_B3_TraceId, traceId.GetData(), sizeof(traceLink.X_B3_TraceId) - 1);
|
|
|
+ strncpy(traceLink.X_B3_SpanId, spanId.GetData(), sizeof(traceLink.X_B3_SpanId) - 1);
|
|
|
+ strncpy(traceLink.X_B3_ParentSpanId, parentSpanId.GetData(), sizeof(traceLink.X_B3_ParentSpanId) - 1);
|
|
|
+ strncpy(traceLink.X_B3_Timestamp, timestamp.GetData(), sizeof(traceLink.X_B3_Timestamp) - 1);
|
|
|
+
|
|
|
+ return traceLink; // 返回结构体副本
|
|
|
+ }
|
|
|
+
|
|
|
linkContext& operator=(const linkContext& tmp) {
|
|
|
bussinessId = tmp.bussinessId;
|
|
|
traceId = tmp.traceId;
|
|
|
spanId = tmp.spanId;
|
|
|
parentSpanId = tmp.parentSpanId;
|
|
|
+ timestamp = tmp.timestamp;
|
|
|
return *this;
|
|
|
}
|
|
|
+
|
|
|
void clear() {
|
|
|
bussinessId = "";
|
|
|
traceId = "";
|
|
|
spanId = "";
|
|
|
parentSpanId = "";
|
|
|
+ timestamp = "";
|
|
|
}
|
|
|
|
|
|
linkContext upgradeLink() const {
|
|
@@ -458,6 +484,7 @@ struct linkContext
|
|
|
else {
|
|
|
spanId = uuid4_generateStr(LINKINFO_SPANID_LEN);
|
|
|
parentSpanId = spanId;
|
|
|
+ updateTimestamp(); // 更新时生成时间戳
|
|
|
return *this;
|
|
|
}
|
|
|
}
|
|
@@ -471,6 +498,15 @@ struct linkContext
|
|
|
traceId = uuid4_generateStr(LINKINFO_TRACEID_LEN);
|
|
|
spanId = uuid4_generateStr(LINKINFO_SPANID_LEN);
|
|
|
parentSpanId = "0";
|
|
|
+ updateTimestamp(); // 自动生成时生成时间戳
|
|
|
+ }
|
|
|
+
|
|
|
+ void AutoGenerate(CSimpleString t_bussinessId) {
|
|
|
+ bussinessId = t_bussinessId;
|
|
|
+ traceId = uuid4_generateStr(LINKINFO_TRACEID_LEN);
|
|
|
+ spanId = uuid4_generateStr(LINKINFO_SPANID_LEN);
|
|
|
+ parentSpanId = "0";
|
|
|
+ updateTimestamp(); // 自动生成时生成时间戳
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -1557,6 +1593,12 @@ private:
|
|
|
const DbgToBeidou& operator=(const DbgToBeidou&) { return *this; };
|
|
|
};
|
|
|
|
|
|
+#define PROCESS_LINK_CONTEXT(linkName) \
|
|
|
+ linkContext linkContextVar; \
|
|
|
+ linkContextVar.AutoGenerate(linkName); \
|
|
|
+ DbgToBeidou(linkContextVar, __FUNCTION__)(); \
|
|
|
+ linkContextVar.upgradeLinkAndSave(); \
|
|
|
+ HttpClientTraceLink nextLink = linkContextVar.convertToHttpClientTraceLink();
|
|
|
|
|
|
class SPBASE_API DbgWithLink {
|
|
|
public:
|