Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
parity
Mirrored projects
jsonrpsee
Commits
37474f45
Unverified
Commit
37474f45
authored
Oct 15, 2021
by
Niklas Adolfsson
Committed by
GitHub
Oct 15, 2021
Browse files
switch to the tracing crate (#525)
parent
af16b390
Changes
28
Hide whitespace changes
Inline
Side-by-side
examples/Cargo.toml
View file @
37474f45
...
...
@@ -10,7 +10,8 @@ publish = false
anyhow
=
"1"
env_logger
=
"0.9"
jsonrpsee
=
{
path
=
"../jsonrpsee"
,
features
=
["full"]
}
log
=
"0.4"
tracing
=
"0.1"
tracing-subscriber
=
"0.2"
tokio
=
{
version
=
"1"
,
features
=
["full"]
}
[[example]]
...
...
examples/http.rs
View file @
37474f45
...
...
@@ -34,7 +34,9 @@ use std::net::SocketAddr;
#[tokio::main]
async
fn
main
()
->
anyhow
::
Result
<
()
>
{
env_logger
::
init
();
// init tracing `FmtSubscriber`.
let
subscriber
=
tracing_subscriber
::
FmtSubscriber
::
new
();
tracing
::
subscriber
::
set_global_default
(
subscriber
)
.expect
(
"setting default subscriber failed"
);
let
(
server_addr
,
_handle
)
=
run_server
()
.await
?
;
let
url
=
format!
(
"http://{}"
,
server_addr
);
...
...
@@ -42,7 +44,7 @@ async fn main() -> anyhow::Result<()> {
let
client
=
HttpClientBuilder
::
default
()
.build
(
url
)
?
;
let
params
=
rpc_params!
(
1_u64
,
2
,
3
);
let
response
:
Result
<
String
,
_
>
=
client
.request
(
"say_hello"
,
params
)
.await
;
println
!
(
"r: {:?}"
,
response
);
tracing
::
info
!
(
"r: {:?}"
,
response
);
Ok
(())
}
...
...
examples/proc_macro.rs
View file @
37474f45
...
...
@@ -72,7 +72,9 @@ impl RpcServer<ExampleHash, ExampleStorageKey> for RpcServerImpl {
#[tokio::main]
async
fn
main
()
->
anyhow
::
Result
<
()
>
{
env_logger
::
init
();
// init tracing `FmtSubscriber`.
let
subscriber
=
tracing_subscriber
::
FmtSubscriber
::
builder
()
.finish
();
tracing
::
subscriber
::
set_global_default
(
subscriber
)
.expect
(
"setting default subscriber failed"
);
let
(
server_addr
,
_handle
)
=
run_server
()
.await
?
;
let
url
=
format!
(
"ws://{}"
,
server_addr
);
...
...
examples/ws.rs
View file @
37474f45
...
...
@@ -33,13 +33,16 @@ use std::net::SocketAddr;
#[tokio::main]
async
fn
main
()
->
anyhow
::
Result
<
()
>
{
env_logger
::
init
();
// init tracing `FmtSubscriber`.
let
subscriber
=
tracing_subscriber
::
FmtSubscriber
::
builder
()
.finish
();
tracing
::
subscriber
::
set_global_default
(
subscriber
)
.expect
(
"setting default subscriber failed"
);
let
addr
=
run_server
()
.await
?
;
let
url
=
format!
(
"ws://{}"
,
addr
);
let
client
=
WsClientBuilder
::
default
()
.build
(
&
url
)
.await
?
;
let
response
:
String
=
client
.request
(
"say_hello"
,
None
)
.await
?
;
println!
(
"r
: {:?}"
,
response
);
tracing
::
info!
(
"response
: {:?}"
,
response
);
Ok
(())
}
...
...
examples/ws_sub_with_params.rs
View file @
37474f45
...
...
@@ -34,7 +34,10 @@ use std::net::SocketAddr;
#[tokio::main]
async
fn
main
()
->
anyhow
::
Result
<
()
>
{
env_logger
::
init
();
// init tracing `FmtSubscriber`.
let
subscriber
=
tracing_subscriber
::
FmtSubscriber
::
builder
()
.finish
();
tracing
::
subscriber
::
set_global_default
(
subscriber
)
.expect
(
"setting default subscriber failed"
);
let
addr
=
run_server
()
.await
?
;
let
url
=
format!
(
"ws://{}"
,
addr
);
...
...
@@ -43,12 +46,12 @@ async fn main() -> anyhow::Result<()> {
// Subscription with a single parameter
let
mut
sub_params_one
=
client
.subscribe
::
<
Option
<
char
>>
(
"sub_one_param"
,
rpc_params!
[
3
],
"unsub_one_param"
)
.await
?
;
println
!
(
"subscription with one param: {:?}"
,
sub_params_one
.next
()
.await
);
tracing
::
info
!
(
"subscription with one param: {:?}"
,
sub_params_one
.next
()
.await
);
// Subscription with multiple parameters
let
mut
sub_params_two
=
client
.subscribe
::
<
String
>
(
"sub_params_two"
,
rpc_params!
[
2
,
5
],
"unsub_params_two"
)
.await
?
;
println
!
(
"subscription with two params: {:?}"
,
sub_params_two
.next
()
.await
);
tracing
::
info
!
(
"subscription with two params: {:?}"
,
sub_params_two
.next
()
.await
);
Ok
(())
}
...
...
examples/ws_subscription.rs
View file @
37474f45
...
...
@@ -32,10 +32,14 @@ use jsonrpsee::{
};
use
std
::
net
::
SocketAddr
;
const
NUM_SUBSCRIPTION_RESPONSES
:
usize
=
5
;
#[tokio::main]
async
fn
main
()
->
anyhow
::
Result
<
()
>
{
const
NUM_SUBSCRIPTION_RESPONSES
:
usize
=
5
;
env_logger
::
init
();
// init tracing `FmtSubscriber`.
let
subscriber
=
tracing_subscriber
::
FmtSubscriber
::
builder
()
.finish
();
tracing
::
subscriber
::
set_global_default
(
subscriber
)
.expect
(
"setting default subscriber failed"
);
let
addr
=
run_server
()
.await
?
;
let
url
=
format!
(
"ws://{}"
,
addr
);
...
...
@@ -46,7 +50,7 @@ async fn main() -> anyhow::Result<()> {
let
mut
i
=
0
;
while
i
<=
NUM_SUBSCRIPTION_RESPONSES
{
let
r
=
subscribe_hello
.next
()
.await
;
println
!
(
"received {:?}"
,
r
);
tracing
::
info
!
(
"received {:?}"
,
r
);
i
+=
1
;
}
...
...
http-client/Cargo.toml
View file @
37474f45
...
...
@@ -15,7 +15,7 @@ hyper-rustls = "0.22"
hyper
=
{
version
=
"0.14.10"
,
features
=
[
"client"
,
"http1"
,
"http2"
,
"tcp"
]
}
jsonrpsee-types
=
{
path
=
"../types"
,
version
=
"0.4.1"
}
jsonrpsee-utils
=
{
path
=
"../utils"
,
version
=
"0.4.1"
,
features
=
["http-helpers"]
}
lo
g
=
"0.
4
"
tracin
g
=
"0.
1
"
serde
=
{
version
=
"1.0"
,
default-features
=
false
,
features
=
["derive"]
}
serde_json
=
"1.0"
tokio
=
{
version
=
"1"
,
features
=
["time"]
}
...
...
http-client/src/transport.rs
View file @
37474f45
...
...
@@ -39,7 +39,7 @@ impl HttpTransportClient {
}
async
fn
inner_send
(
&
self
,
body
:
String
)
->
Result
<
hyper
::
Response
<
hyper
::
Body
>
,
Error
>
{
lo
g
::
debug!
(
"send: {}"
,
body
);
tracin
g
::
debug!
(
"send: {}"
,
body
);
if
body
.len
()
>
self
.max_request_body_size
as
usize
{
return
Err
(
Error
::
RequestTooLarge
);
...
...
http-server/Cargo.toml
View file @
37474f45
...
...
@@ -17,7 +17,7 @@ jsonrpsee-types = { path = "../types", version = "0.4.1" }
jsonrpsee-utils
=
{
path
=
"../utils"
,
version
=
"0.4.1"
,
features
=
[
"server"
,
"http-helpers"
]
}
globset
=
"0.4"
lazy_static
=
"1.4"
lo
g
=
"0.
4
"
tracin
g
=
"0.
1
"
serde_json
=
"1"
socket2
=
"0.4"
tokio
=
{
version
=
"1"
,
features
=
[
"rt-multi-thread"
,
"macros"
]
}
...
...
http-server/src/access_control/matcher.rs
View file @
37474f45
...
...
@@ -25,8 +25,8 @@
// DEALINGS IN THE SOFTWARE.
use
globset
::{
GlobBuilder
,
GlobMatcher
};
use
log
::
warn
;
use
std
::{
fmt
,
hash
};
use
tracing
::
warn
;
/// Pattern that can be matched to string.
pub
(
crate
)
trait
Pattern
{
...
...
http-server/src/server.rs
View file @
37474f45
...
...
@@ -222,7 +222,7 @@ impl Server {
Err
(
GenericTransportError
::
TooLarge
)
=>
return
Ok
::
<
_
,
HyperError
>
(
response
::
too_large
()),
Err
(
GenericTransportError
::
Malformed
)
=>
return
Ok
::
<
_
,
HyperError
>
(
response
::
malformed
()),
Err
(
GenericTransportError
::
Inner
(
e
))
=>
{
lo
g
::
error!
(
"Internal error reading request body: {}"
,
e
);
tracin
g
::
error!
(
"Internal error reading request body: {}"
,
e
);
return
Ok
::
<
_
,
HyperError
>
(
response
::
internal_error
());
}
};
...
...
@@ -281,7 +281,7 @@ impl Server {
}
else
{
collect_batch_response
(
rx
)
.await
};
lo
g
::
debug!
(
"[service_fn] sending back: {:?}"
,
&
response
[
..
cmp
::
min
(
response
.len
(),
1024
)]);
tracin
g
::
debug!
(
"[service_fn] sending back: {:?}"
,
&
response
[
..
cmp
::
min
(
response
.len
(),
1024
)]);
Ok
::
<
_
,
HyperError
>
(
response
::
ok_response
(
response
))
}
}))
...
...
proc-macros/Cargo.toml
View file @
37474f45
...
...
@@ -17,7 +17,7 @@ proc-macro2 = "1.0"
quote
=
"1.0"
syn
=
{
version
=
"1.0"
,
default-features
=
false
,
features
=
[
"extra-traits"
,
"full"
,
"visit"
,
"parsing"
]
}
proc-macro-crate
=
"1"
lo
g
=
"0.
4
"
tracin
g
=
"0.
1
"
[dev-dependencies]
jsonrpsee
=
{
path
=
"../jsonrpsee"
,
features
=
["full"]
}
...
...
proc-macros/src/render_server.rs
View file @
37474f45
...
...
@@ -294,7 +294,7 @@ impl RpcDescription {
let
#
name
:
#
ty
=
match
seq
.optional_next
()
{
Ok
(
v
)
=>
v
,
Err
(
e
)
=>
{
lo
g
::
error!
(
concat!
(
"Error parsing optional
\"
"
,
stringify!
(
#
name
),
"
\"
as
\"
"
,
stringify!
(
#
ty
),
"
\"
: {:?}"
),
e
);
tracin
g
::
error!
(
concat!
(
"Error parsing optional
\"
"
,
stringify!
(
#
name
),
"
\"
as
\"
"
,
stringify!
(
#
ty
),
"
\"
: {:?}"
),
e
);
return
Err
(
e
.into
())
}
};
...
...
@@ -304,7 +304,7 @@ impl RpcDescription {
let
#
name
:
#
ty
=
match
seq
.next
()
{
Ok
(
v
)
=>
v
,
Err
(
e
)
=>
{
lo
g
::
error!
(
concat!
(
"Error parsing
\"
"
,
stringify!
(
#
name
),
"
\"
as
\"
"
,
stringify!
(
#
ty
),
"
\"
: {:?}"
),
e
);
tracin
g
::
error!
(
concat!
(
"Error parsing
\"
"
,
stringify!
(
#
name
),
"
\"
as
\"
"
,
stringify!
(
#
ty
),
"
\"
: {:?}"
),
e
);
return
Err
(
e
.into
())
}
};
...
...
test-utils/Cargo.toml
View file @
37474f45
...
...
@@ -12,7 +12,7 @@ anyhow = "1"
futures-channel
=
"0.3.14"
futures-util
=
"0.3.14"
hyper
=
{
version
=
"0.14.10"
,
features
=
["full"]
}
lo
g
=
"0.
4
"
tracin
g
=
"0.
1
"
serde
=
{
version
=
"1"
,
default-features
=
false
,
features
=
["derive"]
}
serde_json
=
"1"
soketto
=
{
version
=
"0.7"
,
features
=
["http"]
}
...
...
test-utils/src/mocks.rs
View file @
37474f45
...
...
@@ -278,12 +278,12 @@ async fn connection_task(socket: tokio::net::TcpStream, mode: ServerMode, mut ex
match
&
mode
{
ServerMode
::
Subscription
{
subscription_response
,
..
}
=>
{
if
let
Err
(
e
)
=
sender
.send_text
(
&
subscription_response
)
.await
{
lo
g
::
warn!
(
"send response to subscription: {:?}"
,
e
);
tracin
g
::
warn!
(
"send response to subscription: {:?}"
,
e
);
}
},
ServerMode
::
Notification
(
n
)
=>
{
if
let
Err
(
e
)
=
sender
.send_text
(
&
n
)
.await
{
lo
g
::
warn!
(
"send notification: {:?}"
,
e
);
tracin
g
::
warn!
(
"send notification: {:?}"
,
e
);
}
},
_
=>
{}
...
...
@@ -296,12 +296,12 @@ async fn connection_task(socket: tokio::net::TcpStream, mode: ServerMode, mut ex
match
&
mode
{
ServerMode
::
Response
(
r
)
=>
{
if
let
Err
(
e
)
=
sender
.send_text
(
&
r
)
.await
{
lo
g
::
warn!
(
"send response to request error: {:?}"
,
e
);
tracin
g
::
warn!
(
"send response to request error: {:?}"
,
e
);
}
},
ServerMode
::
Subscription
{
subscription_id
,
..
}
=>
{
if
let
Err
(
e
)
=
sender
.send_text
(
&
subscription_id
)
.await
{
lo
g
::
warn!
(
"send subscription id error: {:?}"
,
e
);
tracin
g
::
warn!
(
"send subscription id error: {:?}"
,
e
);
}
},
_
=>
{}
...
...
@@ -340,7 +340,7 @@ async fn handler(
other_server
:
String
,
)
->
Result
<
hyper
::
Response
<
Body
>
,
soketto
::
BoxedError
>
{
if
is_upgrade_request
(
&
req
)
{
lo
g
::
debug!
(
"{:?}"
,
req
);
tracin
g
::
debug!
(
"{:?}"
,
req
);
match
req
.uri
()
.path
()
{
"/myblock/two"
=>
{
...
...
tests/Cargo.toml
View file @
37474f45
...
...
@@ -13,4 +13,4 @@ futures = { version = "0.3.14", default-features = false, features = ["std"] }
jsonrpsee
=
{
path
=
"../jsonrpsee"
,
features
=
["full"]
}
tokio
=
{
version
=
"1"
,
features
=
["full"]
}
serde_json
=
"1"
lo
g
=
"0.
4
"
tracin
g
=
"0.
1
"
types/Cargo.toml
View file @
37474f45
...
...
@@ -15,7 +15,7 @@ anyhow = "1"
beef
=
{
version
=
"0.5.1"
,
features
=
["impl_serde"]
}
futures-channel
=
{
version
=
"0.3.14"
,
features
=
["sink"]
}
futures-util
=
{
version
=
"0.3.14"
,
default-features
=
false
,
features
=
[
"std"
,
"sink"
,
"channel"
]
}
lo
g
=
{
version
=
"0.
4
"
,
default-features
=
false
}
tracin
g
=
{
version
=
"0.
1
"
,
default-features
=
false
}
serde
=
{
version
=
"1"
,
default-features
=
false
,
features
=
["derive"]
}
serde_json
=
{
version
=
"1"
,
default-features
=
false
,
features
=
[
"alloc"
,
"raw_value"
,
"std"
]
}
thiserror
=
"1.0"
...
...
types/src/v2/params.rs
View file @
37474f45
...
...
@@ -158,18 +158,18 @@ impl<'a> ParamsSequence<'a> {
T
:
Deserialize
<
'a
>
,
{
let
mut
json
=
self
.0
;
lo
g
::
trace!
(
"[next_inner] Params JSON: {:?}"
,
json
);
tracin
g
::
trace!
(
"[next_inner] Params JSON: {:?}"
,
json
);
match
json
.as_bytes
()
.get
(
0
)
?
{
b']'
=>
{
self
.0
=
""
;
lo
g
::
trace!
(
"[next_inner] Reached end of sequence."
);
tracin
g
::
trace!
(
"[next_inner] Reached end of sequence."
);
return
None
;
}
b'['
|
b','
=>
json
=
&
json
[
1
..
],
_
=>
{
let
errmsg
=
format!
(
"Invalid params. Expected one of '[', ']' or ',' but found {:?}"
,
json
);
lo
g
::
error!
(
"[next_inner] {}"
,
errmsg
);
tracin
g
::
error!
(
"[next_inner] {}"
,
errmsg
);
return
Some
(
Err
(
CallError
::
InvalidParams
(
anyhow!
(
errmsg
))));
}
}
...
...
@@ -183,7 +183,7 @@ impl<'a> ParamsSequence<'a> {
Some
(
Ok
(
value
))
}
Err
(
e
)
=>
{
lo
g
::
error!
(
tracin
g
::
error!
(
"[next_inner] Deserialization to {:?} failed. Error: {:?}, input JSON: {:?}"
,
std
::
any
::
type_name
::
<
T
>
(),
e
,
...
...
utils/Cargo.toml
View file @
37474f45
...
...
@@ -14,7 +14,7 @@ futures-channel = { version = "0.3.14", default-features = false, optional = tru
futures-util
=
{
version
=
"0.3.14"
,
default-features
=
false
,
optional
=
true
}
hyper
=
{
version
=
"0.14.10"
,
default-features
=
false
,
features
=
["stream"]
,
optional
=
true
}
jsonrpsee-types
=
{
path
=
"../types"
,
version
=
"0.4.1"
,
optional
=
true
}
lo
g
=
{
version
=
"0.
4
"
,
optional
=
true
}
tracin
g
=
{
version
=
"0.
1
"
,
optional
=
true
}
rustc-hash
=
{
version
=
"1"
,
optional
=
true
}
rand
=
{
version
=
"0.8"
,
optional
=
true
}
serde
=
{
version
=
"1.0"
,
default-features
=
false
,
features
=
["derive"]
,
optional
=
true
}
...
...
@@ -33,7 +33,7 @@ server = [
"rustc-hash"
,
"serde"
,
"serde_json"
,
"
lo
g"
,
"
tracin
g"
,
"parking_lot"
,
"rand"
,
"tokio"
,
...
...
utils/src/server/helpers.rs
View file @
37474f45
...
...
@@ -39,14 +39,14 @@ pub fn send_response(id: Id, tx: &MethodSink, result: impl Serialize) {
let
json
=
match
serde_json
::
to_string
(
&
Response
{
jsonrpc
:
TwoPointZero
,
id
:
id
.clone
(),
result
})
{
Ok
(
json
)
=>
json
,
Err
(
err
)
=>
{
lo
g
::
error!
(
"Error serializing response: {:?}"
,
err
);
tracin
g
::
error!
(
"Error serializing response: {:?}"
,
err
);
return
send_error
(
id
,
tx
,
ErrorCode
::
InternalError
.into
());
}
};
if
let
Err
(
err
)
=
tx
.unbounded_send
(
json
)
{
lo
g
::
error!
(
"Error sending response to the client: {:?}"
,
err
)
tracin
g
::
error!
(
"Error sending response to the client: {:?}"
,
err
)
}
}
...
...
@@ -55,14 +55,14 @@ pub fn send_error(id: Id, tx: &MethodSink, error: ErrorObject) {
let
json
=
match
serde_json
::
to_string
(
&
RpcError
{
jsonrpc
:
TwoPointZero
,
error
,
id
})
{
Ok
(
json
)
=>
json
,
Err
(
err
)
=>
{
lo
g
::
error!
(
"Error serializing error message: {:?}"
,
err
);
tracin
g
::
error!
(
"Error serializing error message: {:?}"
,
err
);
return
;
}
};
if
let
Err
(
err
)
=
tx
.unbounded_send
(
json
)
{
lo
g
::
error!
(
"Could not send error response to the client: {:?}"
,
err
)
tracin
g
::
error!
(
"Could not send error response to the client: {:?}"
,
err
)
}
}
...
...
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment