sp_rpc/
tracing.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// 	http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18//! Types for working with tracing data
19
20use serde::{Deserialize, Serialize};
21
22use rustc_hash::FxHashMap;
23
24/// Container for all related spans and events for the block being traced.
25#[derive(Serialize, Deserialize, Clone, Debug)]
26#[serde(rename_all = "camelCase")]
27pub struct BlockTrace {
28	/// Hash of the block being traced
29	pub block_hash: String,
30	/// Parent hash
31	pub parent_hash: String,
32	/// Module targets that were recorded by the tracing subscriber.
33	/// Empty string means record all targets.
34	pub tracing_targets: String,
35	/// Storage key targets used to filter out events that do not have one of the storage keys.
36	/// Empty string means do not filter out any events.
37	pub storage_keys: String,
38	/// Method targets used to filter out events that do not have one of the event method.
39	/// Empty string means do not filter out any events.
40	pub methods: String,
41	/// Vec of tracing spans
42	pub spans: Vec<Span>,
43	/// Vec of tracing events
44	pub events: Vec<Event>,
45}
46
47/// Represents a tracing event, complete with recorded data.
48#[derive(Serialize, Deserialize, Clone, Debug)]
49#[serde(rename_all = "camelCase")]
50pub struct Event {
51	/// Event target
52	pub target: String,
53	/// Associated data
54	pub data: Data,
55	/// Parent id, if it exists
56	pub parent_id: Option<u64>,
57}
58
59/// Represents a single instance of a tracing span.
60///
61/// Exiting a span does not imply that the span will not be re-entered.
62#[derive(Serialize, Deserialize, Clone, Debug)]
63#[serde(rename_all = "camelCase")]
64pub struct Span {
65	/// id for this span
66	pub id: u64,
67	/// id of the parent span, if any
68	pub parent_id: Option<u64>,
69	/// Name of this span
70	pub name: String,
71	/// Target, typically module
72	pub target: String,
73	/// Indicates if the span is from wasm
74	pub wasm: bool,
75}
76
77/// Holds associated values for a tracing span.
78#[derive(Serialize, Deserialize, Default, Clone, Debug)]
79#[serde(rename_all = "camelCase")]
80pub struct Data {
81	/// HashMap of `String` values recorded while tracing
82	pub string_values: FxHashMap<String, String>,
83}
84
85/// Error response for the `state_traceBlock` RPC.
86#[derive(Serialize, Deserialize, Default, Clone, Debug)]
87#[serde(rename_all = "camelCase")]
88pub struct TraceError {
89	/// Error message
90	pub error: String,
91}
92
93/// Response for the `state_traceBlock` RPC.
94#[derive(Serialize, Deserialize, Clone, Debug)]
95#[serde(rename_all = "camelCase")]
96pub enum TraceBlockResponse {
97	/// Error block tracing response
98	TraceError(TraceError),
99	/// Successful block tracing response
100	BlockTrace(BlockTrace),
101}