1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
//! Metrics collection for Delta Kernel operations.
//!
//! This module provides metrics tracking for various Delta operations including
//! snapshot creation, scans, and transactions. Metrics are collected during operations
//! and reported as events via the `MetricsReporter` trait.
//!
//! Each operation (Snapshot, Transaction, Scan) is assigned a unique operation ID ([`MetricId`])
//! when it starts, and all subsequent events for that operation reference this ID.
//! This allows reporters to correlate events and track operation lifecycles.
//!
//! # Example: Implementing a Custom MetricsReporter
//!
//! ```
//! use delta_kernel::metrics::{MetricsReporter, MetricEvent};
//!
//! #[derive(Debug)]
//! struct LoggingReporter;
//!
//! impl MetricsReporter for LoggingReporter {
//! fn report(&self, event: MetricEvent) {
//! match event {
//! MetricEvent::LogSegmentLoadSuccess(e) => {
//! println!("Log segment loaded in {:?}: {} commits", e.duration, e.num_commit_files);
//! }
//! MetricEvent::SnapshotBuildSuccess(e) => {
//! println!("Snapshot completed: v{} in {:?}", e.version, e.duration);
//! }
//! MetricEvent::SnapshotBuildFailure(e) => {
//! println!("Snapshot failed: {}", e.operation_id);
//! }
//! _ => {}
//! }
//! }
//! }
//! ```
//!
//! # Example: Implementing a Composite Reporter
//!
//! If you need to send metrics to multiple destinations, you can create a composite reporter:
//!
//! ```
//! use std::sync::Arc;
//! use delta_kernel::metrics::{MetricsReporter, MetricEvent};
//!
//! #[derive(Debug)]
//! struct CompositeReporter {
//! reporters: Vec<Arc<dyn MetricsReporter>>,
//! }
//!
//! impl MetricsReporter for CompositeReporter {
//! fn report(&self, event: MetricEvent) {
//! for reporter in &self.reporters {
//! reporter.report(event.clone());
//! }
//! }
//! }
//! ```
//!
//! # Handler Metrics
//!
//! Storage, JSON, and Parquet handler operations emit one event per read or copy
//! operation, fired when the returned iterator is exhausted or dropped:
//! `StorageListCompleted` / `StorageReadCompleted` / `StorageCopyCompleted` for storage,
//! `JsonReadCompleted` for `JsonHandler::read_json_files`, and `ParquetReadCompleted`
//! for `ParquetHandler::read_parquet_files`. `DefaultEngine` wraps its three handlers
//! in [`MeteredStorageHandler`], [`MeteredJsonHandler`], and [`MeteredParquetHandler`]
//! at construction; any other engine gets the same coverage by wrapping its [`Engine`]
//! in [`MeteredDeltaEngine`].
//!
//! These metrics are standalone and track aggregate handler performance without
//! correlating to specific Snapshot/Transaction operations.
//!
//! [`Engine`]: crate::Engine
pub
pub
use Arc;
pub use ;
pub use MeteredDeltaEngine;
pub use MeteredJsonHandler;
pub use MeteredParquetHandler;
pub use MeteredStorageHandler;
pub use PrecountedMetricsIterator;
pub use ;
pub use ;
use Subscriber;
use ;
use LookupSpan;
/// Extension trait that adds [`with_metrics_reporter_layer`] to any compatible tracing subscriber.
///
/// Only implemented for subscribers that also implement [`LookupSpan`], which is required by
/// [`ReportGeneratorLayer`] to store and retrieve per-span state.
///
/// [`with_metrics_reporter_layer`]: WithMetricsReporterLayer::with_metrics_reporter_layer