Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Agent] feature support sw3 #4595

Merged
merged 2 commits into from Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions agent/src/config/handler.rs
Expand Up @@ -645,6 +645,7 @@ pub enum TraceType {
XB3,
XB3Span,
Uber,
Sw3,
Sw6,
Sw8,
TraceParent,
Expand All @@ -657,6 +658,7 @@ pub enum TraceType {
const TRACE_TYPE_XB3: &str = "x-b3-traceid";
const TRACE_TYPE_XB3SPAN: &str = "x-b3-spanid";
const TRACE_TYPE_UBER: &str = "uber-trace-id";
const TRACE_TYPE_SW3: &str = "sw3";
const TRACE_TYPE_SW6: &str = "sw6";
const TRACE_TYPE_SW8: &str = "sw8";
const TRACE_TYPE_TRACE_PARENT: &str = "traceparent";
Expand All @@ -676,6 +678,7 @@ impl From<&str> for TraceType {
TRACE_TYPE_XB3 => TraceType::XB3,
TRACE_TYPE_XB3SPAN => TraceType::XB3Span,
TRACE_TYPE_UBER => TraceType::Uber,
TRACE_TYPE_SW3 => TraceType::Sw3,
TRACE_TYPE_SW6 => TraceType::Sw6,
TRACE_TYPE_SW8 => TraceType::Sw8,
TRACE_TYPE_TRACE_PARENT => TraceType::TraceParent,
Expand Down Expand Up @@ -706,6 +709,7 @@ impl TraceType {
TraceType::XB3 => context.to_ascii_lowercase() == TRACE_TYPE_XB3,
TraceType::XB3Span => context.to_ascii_lowercase() == TRACE_TYPE_XB3SPAN,
TraceType::Uber => context.to_ascii_lowercase() == TRACE_TYPE_UBER,
TraceType::Sw3 => context.to_ascii_lowercase() == TRACE_TYPE_SW3,
TraceType::Sw6 => context.to_ascii_lowercase() == TRACE_TYPE_SW6,
TraceType::Sw8 => context.to_ascii_lowercase() == TRACE_TYPE_SW8,
TraceType::TraceParent => context.to_ascii_lowercase() == TRACE_TYPE_TRACE_PARENT,
Expand All @@ -723,6 +727,7 @@ impl TraceType {
&TraceType::XB3 => TRACE_TYPE_XB3.into(),
&TraceType::XB3Span => TRACE_TYPE_XB3SPAN.into(),
&TraceType::Uber => TRACE_TYPE_UBER.into(),
&TraceType::Sw3 => TRACE_TYPE_SW3.into(),
&TraceType::Sw6 => TRACE_TYPE_SW6.into(),
&TraceType::Sw8 => TRACE_TYPE_SW8.into(),
&TraceType::TraceParent => TRACE_TYPE_TRACE_PARENT.into(),
Expand All @@ -738,6 +743,7 @@ impl TraceType {
TraceType::XB3 => TRACE_TYPE_XB3.to_string(),
TraceType::XB3Span => TRACE_TYPE_XB3SPAN.to_string(),
TraceType::Uber => TRACE_TYPE_UBER.to_string(),
TraceType::Sw3 => TRACE_TYPE_SW3.to_string(),
TraceType::Sw6 => TRACE_TYPE_SW6.to_string(),
TraceType::Sw8 => TRACE_TYPE_SW8.to_string(),
TraceType::TraceParent => TRACE_TYPE_TRACE_PARENT.to_string(),
Expand Down
19 changes: 19 additions & 0 deletions agent/src/flow_generator/protocol_logs/http.rs
Expand Up @@ -987,6 +987,24 @@ impl HttpLog {
None
}

// sw3: SEGMENTID|SPANID|100|100|#IPPORT|#PARENT_ENDPOINT|#ENDPOINT|TRACEID|SAMPLING
// sw3的value全部使用'|'分隔,TRACEID后为SAMPLE字段取值范围仅有0或1,可能不存在
// 提取`TRACEID`展示为HTTP日志中的`TraceID`字段
// 提取`SEGMENTID-SPANID`展示为HTTP日志中的`SpanID`字段
fn decode_skywalking3_id(value: &str, id_type: u8) -> Option<String> {
let segs: Vec<&str> = value.split("|").collect();
if segs.len() > 7 {
if id_type == Self::TRACE_ID {
return Some(segs[7].to_string());
}
if id_type == Self::SPAN_ID {
return Some(format!("{}-{}", segs[0], segs[1]));
}
}

None
}

// sw6: 1-TRACEID-SEGMENTID-3-5-2-IPPORT-ENTRYURI-PARENTURI
// sw8: 1-TRACEID-SEGMENTID-3-PARENT_SERVICE-PARENT_INSTANCE-PARENT_ENDPOINT-IPPORT
// sw6和sw8的value全部使用'-'分隔,TRACEID前为SAMPLE字段取值范围仅有0或1
Expand Down Expand Up @@ -1037,6 +1055,7 @@ impl HttpLog {
Some(payload.to_owned())
}
TraceType::Uber => Self::decode_uber_id(payload, id_type),
TraceType::Sw3 => Self::decode_skywalking3_id(payload, id_type),
TraceType::Sw6 | TraceType::Sw8 => Self::decode_skywalking_id(payload, id_type),
TraceType::TraceParent => Self::decode_traceparent(payload, id_type),
TraceType::NewRpcTraceContext => {
Expand Down
20 changes: 20 additions & 0 deletions agent/src/flow_generator/protocol_logs/rpc/dubbo.rs
Expand Up @@ -338,6 +338,7 @@ impl DubboLog {
// 注意 dubbo trace id 解析是区分大小写的
fn decode_trace_id(payload: &Cow<'_, str>, trace_type: &TraceType, info: &mut DubboInfo) {
let tag = match trace_type {
TraceType::Sw3 => TraceType::Sw3.to_string(),
TraceType::Sw8 => TraceType::Sw8.to_string(),
TraceType::Customize(tag) => tag.to_string(),
_ => return,
Expand Down Expand Up @@ -376,6 +377,15 @@ impl DubboLog {
}

match trace_type {
TraceType::Sw3 => {
// sw3: SEGMENTID|SPANID|100|100|#IPPORT|#PARENT_ENDPOINT|#ENDPOINT|TRACEID|SAMPLING
if info.trace_id.len() > 2 {
let segs: Vec<&str> = info.trace_id.split("|").collect();
if segs.len() > 7 {
info.trace_id = segs[7].to_string();
}
}
}
TraceType::Sw8 => {
if info.trace_id.len() > 2 {
if let Some(index) = info.trace_id[2..].find("-") {
Expand All @@ -391,6 +401,7 @@ impl DubboLog {
fn decode_span_id(payload: &Cow<'_, str>, trace_type: &TraceType, info: &mut DubboInfo) {
let tag = match trace_type {
TraceType::Customize(tag) => tag.to_string(),
TraceType::Sw3 => TraceType::Sw3.to_string(),
TraceType::Sw8 => TraceType::Sw8.to_string(),
_ => return,
};
Expand Down Expand Up @@ -428,6 +439,15 @@ impl DubboLog {
}

match trace_type {
TraceType::Sw3 => {
// sw3: SEGMENTID|SPANID|100|100|#IPPORT|#PARENT_ENDPOINT|#ENDPOINT|TRACEID|SAMPLING
if info.span_id.len() > 2 {
let segs: Vec<&str> = info.span_id.split("|").collect();
if segs.len() > 3 {
info.span_id = format!("{}-{}", segs[0], segs[1]);
}
}
}
TraceType::Sw8 => {
// Format:
// sw8: 1-TRACEID-SEGMENTID-3-PARENT_SERVICE-PARENT_INSTANCE-PARENT_ENDPOINT-IPPORT
Expand Down