Skip to content

Commit 4d2648f

Browse files
authored
Upgrade dependencies and adapt the codes. (#57)
1 parent 733d4f3 commit 4d2648f

11 files changed

Lines changed: 307 additions & 309 deletions

File tree

Cargo.lock

Lines changed: 181 additions & 165 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,28 @@ name = "skywalking_agent"
3636
crate-type = ["lib", "cdylib"]
3737

3838
[dependencies]
39-
anyhow = { version = "1.0.68", features = ["backtrace"] }
39+
anyhow = { version = "1.0.69", features = ["backtrace"] }
4040
bincode = "1.3.3"
41-
chrono = "0.4.23"
41+
chrono = "0.4.24"
4242
dashmap = "5.4.0"
43-
futures-util = "0.3.25"
43+
futures-util = "0.3.27"
4444
hostname = "0.3.1"
45-
libc = "0.2.139"
46-
once_cell = "1.17.0"
45+
libc = "0.2.140"
46+
once_cell = "1.17.1"
4747
phper = "0.10.2"
48-
prost = "0.11.6"
49-
serde_json = { version = "1.0.91", features = ["preserve_order"] }
50-
skywalking = { version = "0.5.0", features = ["management"] }
51-
systemstat = "0.2.2"
52-
thiserror = "1.0.38"
53-
tokio = { version = "1.24.2", features = ["full"] }
54-
tokio-stream = "0.1.11"
48+
prost = "0.11.8"
49+
serde_json = { version = "1.0.94", features = ["preserve_order"] }
50+
skywalking = { version = "0.6.0", features = ["management"] }
51+
systemstat = "0.2.3"
52+
thiserror = "1.0.39"
53+
tokio = { version = "1.26.0", features = ["full"] }
54+
tokio-stream = "0.1.12"
5555
tonic = { version = "0.8.3", features = ["tls"] }
5656
tracing = { version = "0.1.37", features = ["attributes"] }
5757
tracing-subscriber = "0.3.16"
5858
url = "2.3.1"
5959

6060
[dev-dependencies]
61-
axum = "0.6.2"
61+
axum = "0.6.11"
6262
fastcgi-client = "0.8.0"
63-
reqwest = { version = "0.11.13", features = ["trust-dns", "json", "stream"] }
63+
reqwest = { version = "0.11.14", features = ["trust-dns", "json", "stream"] }

scripts/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ license = "Apache-2.0"
2525
publish = false
2626

2727
[dependencies]
28-
anyhow = "1.0.68"
29-
chrono = "0.4.23"
30-
clap = { version = "4.0.32", features = ["derive"] }
31-
serde = { version = "1.0.152", features = ["derive"] }
32-
tera = "1.17.1"
28+
anyhow = "1.0.69"
29+
chrono = "0.4.24"
30+
clap = { version = "4.1.8", features = ["derive"] }
31+
serde = { version = "1.0.155", features = ["derive"] }
32+
tera = "1.18.0"
3333
tracing = "0.1.37"
3434
tracing-subscriber = "0.3.16"

src/plugin/plugin_curl.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ impl CurlPlugin {
158158
Ok(ctx.create_exit_span(url.path(), peer))
159159
})?;
160160

161-
span.with_span_object_mut(|span| {
162-
span.component_id = COMPONENT_PHP_CURL_ID;
163-
span.add_tag("url", raw_url);
164-
});
161+
let mut span_object = span.span_object_mut();
162+
span_object.component_id = COMPONENT_PHP_CURL_ID;
163+
span_object.add_tag("url", raw_url);
164+
drop(span_object);
165165

166166
let sw_header = RequestContext::try_with_global_ctx(request_id, |ctx| {
167167
Ok(encode_propagation(ctx, url.path(), peer))
@@ -200,14 +200,13 @@ impl CurlPlugin {
200200
.as_z_str()
201201
.context("curl_error is not string")?
202202
.to_str()?;
203-
span.with_span_object_mut(|span| {
204-
span.is_error = true;
205-
span.add_log(vec![("CURL_ERROR", curl_error)]);
206-
});
203+
let mut span_object = span.span_object_mut();
204+
span_object.is_error = true;
205+
span_object.add_log(vec![("CURL_ERROR", curl_error)]);
207206
} else if http_code >= 400 {
208-
span.with_span_object_mut(|span| span.is_error = true);
207+
span.span_object_mut().is_error = true;
209208
} else {
210-
span.with_span_object_mut(|span| span.is_error = false);
209+
span.span_object_mut().is_error = false;
211210
}
212211

213212
Ok(())

src/plugin/plugin_memcached.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,7 @@ fn after_hook(
308308
let mut span = span.downcast::<Span>().expect("Downcast to Span failed");
309309
if let Some(b) = return_value.as_bool() {
310310
if !b {
311-
span.with_span_object_mut(|span| {
312-
span.is_error = true;
313-
});
311+
span.span_object_mut().is_error = true;
314312

315313
let this = get_this_mut(execute_data)?;
316314
let code = this.call(&"getResultCode".to_ascii_lowercase(), [])?;
@@ -343,21 +341,20 @@ fn create_exit_span<'a>(
343341
let mut span =
344342
ctx.create_exit_span(&format!("{}->{}", class_name, function_name), remote_peer);
345343

346-
span.with_span_object_mut(|obj| {
347-
obj.set_span_layer(SpanLayer::Cache);
348-
obj.component_id = COMPONENT_PHP_MEMCACHED_ID;
349-
obj.add_tag(TAG_CACHE_TYPE, "memcache");
350-
351-
if let Some(cmd) = tag_info.cmd {
352-
obj.add_tag(TAG_CACHE_CMD, cmd);
353-
}
354-
if let Some(op) = &tag_info.op {
355-
obj.add_tag(TAG_CACHE_OP, op.to_string());
356-
};
357-
if let Some(key) = key {
358-
obj.add_tag(TAG_CACHE_KEY, key)
359-
}
360-
});
344+
let mut span_object = span.span_object_mut();
345+
span_object.set_span_layer(SpanLayer::Cache);
346+
span_object.component_id = COMPONENT_PHP_MEMCACHED_ID;
347+
span_object.add_tag(TAG_CACHE_TYPE, "memcache");
348+
if let Some(cmd) = tag_info.cmd {
349+
span_object.add_tag(TAG_CACHE_CMD, cmd);
350+
}
351+
if let Some(op) = &tag_info.op {
352+
span_object.add_tag(TAG_CACHE_OP, op.to_string());
353+
};
354+
if let Some(key) = key {
355+
span_object.add_tag(TAG_CACHE_KEY, key)
356+
}
357+
drop(span_object);
361358

362359
Ok(span)
363360
})

src/plugin/plugin_mysqli.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,13 @@ fn create_mysqli_exit_span(
132132
&format!("{}->{}", class_name, function_name),
133133
&format!("{}:{}", info.hostname, info.port),
134134
);
135-
span.with_span_object_mut(|obj| {
136-
obj.set_span_layer(SpanLayer::Database);
137-
obj.component_id = COMPONENT_PHP_MYSQLI_ID;
138-
obj.add_tag("db.type", "mysql");
139-
});
135+
136+
let mut span_object = span.span_object_mut();
137+
span_object.set_span_layer(SpanLayer::Database);
138+
span_object.component_id = COMPONENT_PHP_MYSQLI_ID;
139+
span_object.add_tag("db.type", "mysql");
140+
drop(span_object);
141+
140142
Ok(span)
141143
})
142144
}

src/plugin/plugin_pdo.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,9 @@ fn after_hook_when_false(this: &mut ZObj, span: &mut Span) -> crate::Result<()>
223223
};
224224
let error = get_error_info_item(info, 2)?.expect_z_str()?.to_str()?;
225225

226-
span.with_span_object_mut(|span| {
227-
span.is_error = true;
228-
span.add_log([("SQLSTATE", state), ("Error Code", code), ("Error", error)]);
229-
});
226+
let mut span_object = span.span_object_mut();
227+
span_object.is_error = true;
228+
span_object.add_log([("SQLSTATE", state), ("Error Code", code), ("Error", error)]);
230229

231230
Ok(())
232231
}
@@ -252,12 +251,14 @@ fn create_exit_span_with_dsn(
252251
RequestContext::try_with_global_ctx(request_id, |ctx| {
253252
let mut span =
254253
ctx.create_exit_span(&format!("{}->{}", class_name, function_name), &dsn.peer);
255-
span.with_span_object_mut(|obj| {
256-
obj.set_span_layer(SpanLayer::Database);
257-
obj.component_id = COMPONENT_PHP_PDO_ID;
258-
obj.add_tag(TAG_DB_TYPE, &dsn.db_type);
259-
obj.add_tag("db.data_source", &dsn.data_source);
260-
});
254+
255+
let mut span_object = span.span_object_mut();
256+
span_object.set_span_layer(SpanLayer::Database);
257+
span_object.component_id = COMPONENT_PHP_PDO_ID;
258+
span_object.add_tag(TAG_DB_TYPE, &dsn.db_type);
259+
span_object.add_tag("db.data_source", &dsn.data_source);
260+
drop(span_object);
261+
261262
Ok(span)
262263
})
263264
}

src/plugin/plugin_predis.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -222,18 +222,18 @@ impl PredisPlugin {
222222
))
223223
})?;
224224

225-
span.with_span_object_mut(|span| {
226-
span.set_span_layer(SpanLayer::Cache);
227-
span.component_id = COMPONENT_PHP_PREDIS_ID;
228-
span.add_tag(TAG_CACHE_TYPE, "redis");
229-
span.add_tag(TAG_CACHE_CMD, cmd);
230-
if let Some(op) = op {
231-
span.add_tag(TAG_CACHE_OP, op);
232-
};
233-
if let Some(key) = key {
234-
span.add_tag(TAG_CACHE_KEY, key)
235-
}
236-
});
225+
let mut span_object = span.span_object_mut();
226+
span_object.set_span_layer(SpanLayer::Cache);
227+
span_object.component_id = COMPONENT_PHP_PREDIS_ID;
228+
span_object.add_tag(TAG_CACHE_TYPE, "redis");
229+
span_object.add_tag(TAG_CACHE_CMD, cmd);
230+
if let Some(op) = op {
231+
span_object.add_tag(TAG_CACHE_OP, op);
232+
};
233+
if let Some(key) = key {
234+
span_object.add_tag(TAG_CACHE_KEY, key)
235+
}
236+
drop(span_object);
237237

238238
Ok(Box::new(span))
239239
}),
@@ -242,7 +242,7 @@ impl PredisPlugin {
242242

243243
let typ = return_value.get_type_info();
244244
if typ.is_null() || typ.is_false() {
245-
span.with_span_object_mut(|span| span.is_error = true);
245+
span.span_object_mut().is_error = true;
246246
}
247247

248248
Ok(())

src/plugin/plugin_redis.rs

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,11 @@ impl RedisPlugin {
260260
Ok(ctx.create_exit_span(&format!("{}->{}", class_name, function_name), &addr))
261261
})?;
262262

263-
span.with_span_object_mut(|span| {
264-
span.set_span_layer(SpanLayer::Cache);
265-
span.component_id = COMPONENT_PHP_REDIS_ID;
266-
span.add_tag(TAG_CACHE_TYPE, "redis");
267-
});
263+
let mut span_object = span.span_object_mut();
264+
span_object.set_span_layer(SpanLayer::Cache);
265+
span_object.component_id = COMPONENT_PHP_REDIS_ID;
266+
span_object.add_tag(TAG_CACHE_TYPE, "redis");
267+
drop(span_object);
268268

269269
Ok(Box::new(span))
270270
}),
@@ -306,21 +306,21 @@ impl RedisPlugin {
306306
Ok(ctx.create_exit_span(&format!("{}->{}", class_name, function_name), &peer))
307307
})?;
308308

309-
span.with_span_object_mut(|span| {
310-
span.set_span_layer(SpanLayer::Cache);
311-
span.component_id = COMPONENT_PHP_REDIS_ID;
312-
span.add_tag(TAG_CACHE_TYPE, "redis");
313-
span.add_tag(
314-
TAG_CACHE_CMD,
315-
*REDIS_ALL_MAPPING.get(function_name_key).unwrap(),
316-
);
317-
if let Some(op) = op {
318-
span.add_tag(TAG_CACHE_OP, op);
319-
}
320-
if let Some(key) = key {
321-
span.add_tag(TAG_CACHE_KEY, key)
322-
}
323-
});
309+
let mut span_object = span.span_object_mut();
310+
span_object.set_span_layer(SpanLayer::Cache);
311+
span_object.component_id = COMPONENT_PHP_REDIS_ID;
312+
span_object.add_tag(TAG_CACHE_TYPE, "redis");
313+
span_object.add_tag(
314+
TAG_CACHE_CMD,
315+
*REDIS_ALL_MAPPING.get(function_name_key).unwrap(),
316+
);
317+
if let Some(op) = op {
318+
span_object.add_tag(TAG_CACHE_OP, op);
319+
}
320+
if let Some(key) = key {
321+
span_object.add_tag(TAG_CACHE_KEY, key)
322+
}
323+
drop(span_object);
324324

325325
Ok(Box::new(span))
326326
}),
@@ -362,22 +362,21 @@ fn after_hook(
362362

363363
let ex = unsafe { ZObj::try_from_mut_ptr(eg!(exception)) };
364364
if let Some(ex) = ex {
365-
span.with_span_object_mut(|span| {
366-
span.is_error = true;
365+
let mut span_object = span.span_object_mut();
366+
span_object.is_error = true;
367367

368-
let mut logs = Vec::new();
369-
if let Ok(class_name) = ex.get_class().get_name().to_str() {
370-
logs.push(("Exception Class", class_name.to_owned()));
371-
}
372-
if let Some(message) = ex.get_property("message").as_z_str() {
373-
if let Ok(message) = message.to_str() {
374-
logs.push(("Exception Message", message.to_owned()));
375-
}
376-
}
377-
if !logs.is_empty() {
378-
span.add_log(logs);
368+
let mut logs = Vec::new();
369+
if let Ok(class_name) = ex.get_class().get_name().to_str() {
370+
logs.push(("Exception Class", class_name.to_owned()));
371+
}
372+
if let Some(message) = ex.get_property("message").as_z_str() {
373+
if let Ok(message) = message.to_str() {
374+
logs.push(("Exception Message", message.to_owned()));
379375
}
380-
});
376+
}
377+
if !logs.is_empty() {
378+
span_object.add_log(logs);
379+
}
381380
}
382381

383382
Ok(())

src/request.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,12 @@ fn create_request_context(
252252
Some(propagation) => ctx.create_entry_span_with_propagation(&operation_name, &propagation),
253253
None => ctx.create_entry_span(&operation_name),
254254
};
255-
span.with_span_object_mut(|span| {
256-
span.component_id = COMPONENT_PHP_ID;
257-
span.add_tag("url", uri);
258-
span.add_tag("http.method", method);
259-
});
255+
256+
let mut span_object = span.span_object_mut();
257+
span_object.component_id = COMPONENT_PHP_ID;
258+
span_object.add_tag("url", uri);
259+
span_object.add_tag("http.method", method);
260+
drop(span_object);
260261

261262
RequestContext::set_global(
262263
request_id,
@@ -277,7 +278,7 @@ fn finish_request_context(request_id: Option<i64>, status_code: i32) -> crate::R
277278

278279
entry_span.add_tag("http.status_code", &status_code.to_string());
279280
if status_code >= 400 {
280-
entry_span.with_span_object_mut(|span| span.is_error = true);
281+
entry_span.span_object_mut().is_error = true;
281282
}
282283

283284
drop(entry_span);

0 commit comments

Comments
 (0)