Skip to content

Commit

Permalink
Merge pull request #58 from skunkteam/paco/instrument-with-debug-log-…
Browse files Browse the repository at this point in the history
…level

Instrument with Debug log level
  • Loading branch information
pavadeli authored Mar 22, 2024
2 parents 58140ff + 6028656 commit a67e02d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 33 deletions.
32 changes: 16 additions & 16 deletions crates/emulator-grpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct FirestoreEmulator {
#[async_trait]
impl Firestore for FirestoreEmulator {
/// Gets a single document.
#[instrument(level = Level::TRACE, skip_all, err)]
#[instrument(level = Level::DEBUG, skip_all, err)]
async fn get_document(
&self,
request: Request<GetDocumentRequest>,
Expand Down Expand Up @@ -76,7 +76,7 @@ impl Firestore for FirestoreEmulator {
///
/// Documents returned by this method are not guaranteed to be returned in the
/// same order that they were requested.
#[instrument(level = Level::TRACE, skip_all, fields(
#[instrument(level = Level::DEBUG, skip_all, fields(
count = request.get_ref().documents.len(),
in_txn = display(is_txn(&request.get_ref().consistency_selector))
), err)]
Expand Down Expand Up @@ -144,7 +144,7 @@ impl Firestore for FirestoreEmulator {
}

/// Commits a transaction, while optionally updating documents.
#[instrument(level = Level::TRACE, skip_all, fields(
#[instrument(level = Level::DEBUG, skip_all, fields(
count = request.get_ref().writes.len(),
in_txn = !request.get_ref().transaction.is_empty(),
), err)]
Expand Down Expand Up @@ -172,7 +172,7 @@ impl Firestore for FirestoreEmulator {
}

/// Creates a new document.
#[instrument(level = Level::TRACE, skip_all, err)]
#[instrument(level = Level::DEBUG, skip_all, err)]
async fn create_document(
&self,
_request: Request<CreateDocumentRequest>,
Expand All @@ -181,7 +181,7 @@ impl Firestore for FirestoreEmulator {
}

/// Lists documents.
#[instrument(level = Level::TRACE, skip_all, fields(request = ?request.get_ref()), err)]
#[instrument(level = Level::DEBUG, skip_all, fields(request = ?request.get_ref()), err)]
async fn list_documents(
&self,
request: Request<ListDocumentsRequest>,
Expand Down Expand Up @@ -245,7 +245,7 @@ impl Firestore for FirestoreEmulator {
}

/// Updates or inserts a document.
#[instrument(level = Level::TRACE, skip_all, err)]
#[instrument(level = Level::DEBUG, skip_all, err)]
async fn update_document(
&self,
_request: Request<UpdateDocumentRequest>,
Expand All @@ -254,7 +254,7 @@ impl Firestore for FirestoreEmulator {
}

/// Deletes a document.
#[instrument(level = Level::TRACE, skip_all, err)]
#[instrument(level = Level::DEBUG, skip_all, err)]
async fn delete_document(
&self,
_request: Request<DeleteDocumentRequest>,
Expand All @@ -263,7 +263,7 @@ impl Firestore for FirestoreEmulator {
}

/// Starts a new transaction.
#[instrument(level = Level::TRACE, skip_all, err)]
#[instrument(level = Level::DEBUG, skip_all, err)]
async fn begin_transaction(
&self,
request: Request<BeginTransactionRequest>,
Expand All @@ -284,7 +284,7 @@ impl Firestore for FirestoreEmulator {
}

/// Rolls back a transaction.
#[instrument(level = Level::TRACE, skip_all, err)]
#[instrument(level = Level::DEBUG, skip_all, err)]
async fn rollback(&self, request: Request<RollbackRequest>) -> Result<Response<Empty>> {
let RollbackRequest {
database,
Expand All @@ -299,7 +299,7 @@ impl Firestore for FirestoreEmulator {
type RunQueryStream = BoxStream<'static, Result<RunQueryResponse>>;

/// Runs a query.
#[instrument(level = Level::TRACE, skip_all, err)]
#[instrument(level = Level::DEBUG, skip_all, err)]
async fn run_query(
&self,
request: Request<RunQueryRequest>,
Expand Down Expand Up @@ -364,7 +364,7 @@ impl Firestore for FirestoreEmulator {
/// -- Return the number of documents in table given a filter.
/// SELECT COUNT(*) FROM ( SELECT * FROM k where a = true );
/// ```
#[instrument(level = Level::TRACE, skip_all, err)]
#[instrument(level = Level::DEBUG, skip_all, err)]
async fn run_aggregation_query(
&self,
request: Request<RunAggregationQueryRequest>,
Expand Down Expand Up @@ -424,7 +424,7 @@ impl Firestore for FirestoreEmulator {
/// Partitions a query by returning partition cursors that can be used to run
/// the query in parallel. The returned partition cursors are split points that
/// can be used by RunQuery as starting/end points for the query results.
#[instrument(level = Level::TRACE, skip_all, err)]
#[instrument(level = Level::DEBUG, skip_all, err)]
async fn partition_query(
&self,
_request: Request<PartitionQueryRequest>,
Expand All @@ -437,7 +437,7 @@ impl Firestore for FirestoreEmulator {

/// Streams batches of document updates and deletes, in order. This method is
/// only available via gRPC or WebChannel (not REST).
#[instrument(level = Level::TRACE, skip_all, err)]
#[instrument(level = Level::DEBUG, skip_all, err)]
async fn write(
&self,
_request: Request<tonic::Streaming<WriteRequest>>,
Expand All @@ -450,7 +450,7 @@ impl Firestore for FirestoreEmulator {

/// Listens to changes. This method is only available via gRPC or WebChannel
/// (not REST).
#[instrument(level = Level::TRACE, skip_all, err)]
#[instrument(level = Level::DEBUG, skip_all, err)]
async fn listen(
&self,
request: Request<tonic::Streaming<ListenRequest>>,
Expand All @@ -463,7 +463,7 @@ impl Firestore for FirestoreEmulator {
}

/// Lists all the collection IDs underneath a document.
#[instrument(level = Level::TRACE, skip_all, err)]
#[instrument(level = Level::DEBUG, skip_all, err)]
async fn list_collection_ids(
&self,
request: Request<ListCollectionIdsRequest>,
Expand Down Expand Up @@ -503,7 +503,7 @@ impl Firestore for FirestoreEmulator {
///
/// If you require an atomically applied set of writes, use
/// [Commit][google.firestore.v1.Firestore.Commit] instead.
#[instrument(level = Level::TRACE, skip_all, err)]
#[instrument(level = Level::DEBUG, skip_all, err)]
async fn batch_write(
&self,
request: Request<BatchWriteRequest>,
Expand Down
14 changes: 7 additions & 7 deletions crates/firestore-database/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl FirestoreDatabase {
})
}

#[instrument(level = Level::TRACE, skip_all, err, fields(in_txn = consistency.is_transaction(), found))]
#[instrument(level = Level::DEBUG, skip_all, err, fields(in_txn = consistency.is_transaction(), found))]
pub async fn get_doc(
&self,
name: &DocumentRef,
Expand Down Expand Up @@ -148,7 +148,7 @@ impl FirestoreDatabase {
/// Get all the collections that reside directly under the given parent. This means that:
/// - the IDs will not contain a `/`
/// - the result will be empty if `parent` is a [`Ref::Collection`].
#[instrument(level = Level::TRACE, skip_all)]
#[instrument(level = Level::DEBUG, skip_all)]
pub async fn get_collection_ids(&self, parent: &Ref) -> Result<BTreeSet<String>> {
// Cannot use `filter_map` because of the `await`.
let mut result = BTreeSet::new();
Expand All @@ -173,7 +173,7 @@ impl FirestoreDatabase {
/// This means that:
/// - the IDs will not contain a `/`
/// - IDs may point to documents that do not exist.
#[instrument(level = Level::TRACE, skip_all)]
#[instrument(level = Level::DEBUG, skip_all)]
pub async fn get_document_ids(&self, parent: &CollectionRef) -> Result<BTreeSet<String>> {
// Cannot use `filter_map` because of the `await`.
let mut result = BTreeSet::new();
Expand Down Expand Up @@ -203,7 +203,7 @@ impl FirestoreDatabase {
.collect_vec()
}

#[instrument(level = Level::TRACE, skip_all, err)]
#[instrument(level = Level::DEBUG, skip_all, err)]
pub async fn run_query(&self, query: &mut Query) -> Result<Vec<Document>> {
debug!(?query);
let result = query.once(self).await?;
Expand All @@ -214,7 +214,7 @@ impl FirestoreDatabase {
.collect())
}

#[instrument(level = Level::TRACE, skip_all, err)]
#[instrument(level = Level::DEBUG, skip_all, err)]
pub async fn run_aggregation_query(
&self,
parent: Ref,
Expand Down Expand Up @@ -316,7 +316,7 @@ impl FirestoreDatabase {
Ok(result)
}

#[instrument(level = Level::TRACE, skip_all, err)]
#[instrument(level = Level::DEBUG, skip_all, err)]
pub async fn commit(
self: &Arc<Self>,
writes: Vec<Write>,
Expand Down Expand Up @@ -360,7 +360,7 @@ impl FirestoreDatabase {
Ok((time, write_results))
}

#[instrument(level = Level::TRACE, skip_all, err)]
#[instrument(level = Level::DEBUG, skip_all, err)]
pub async fn perform_write(
&self,
write: Write,
Expand Down
2 changes: 1 addition & 1 deletion crates/firestore-database/src/database/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct Collection {
}

impl Collection {
#[instrument(level = Level::TRACE, skip_all)]
#[instrument(level = Level::DEBUG, skip_all)]
pub fn new(project: &'static FirestoreProject, name: CollectionRef) -> Self {
Self {
project,
Expand Down
4 changes: 2 additions & 2 deletions crates/firestore-database/src/database/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl DocumentContents {
/// Add a new version with the given `update_time`, if the given `fields` are identical to the
/// last version, it will return [`Err`] with the update time ([`Timestamp`]) of the last
/// version.
#[instrument(level = Level::TRACE, skip_all, fields(
#[instrument(level = Level::DEBUG, skip_all, fields(
doc_name = %self.name,
time = display(&update_time),
))]
Expand Down Expand Up @@ -247,7 +247,7 @@ pub struct OwnedDocumentContentsReadGuard {
pub(crate) type OwnedDocumentContentsWriteGuard = OwnedRwLockWriteGuard<DocumentContents>;

impl OwnedDocumentContentsReadGuard {
#[instrument(level = Level::TRACE, skip_all, err)]
#[instrument(level = Level::DEBUG, skip_all, err)]
pub async fn upgrade(self) -> Result<OwnedDocumentContentsWriteGuard> {
debug!(name = %self.meta.name);
let check_time = self.guard.last_updated();
Expand Down
2 changes: 1 addition & 1 deletion crates/firestore-database/src/database/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl Transaction {
}
}

#[instrument(level = Level::TRACE, skip_all)]
#[instrument(level = Level::DEBUG, skip_all)]
pub async fn read_doc(
&self,
name: &DocumentRef,
Expand Down
13 changes: 7 additions & 6 deletions crates/firestore-database/src/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl Listener {
ReceiverStream::new(rx)
}

#[instrument(level = Level::TRACE, name = "listener", skip_all, fields(id = self.id), err)]
#[instrument(level = Level::DEBUG, name = "listener", skip_all, fields(id = self.id), err)]
async fn go(
mut self,
mut request_stream: impl tokio_stream::Stream<Item = ListenRequest> + Send + Unpin,
Expand Down Expand Up @@ -128,7 +128,7 @@ impl Listener {
}
}

#[instrument(level = Level::TRACE, skip_all, err)]
#[instrument(level = Level::DEBUG, skip_all, err)]
async fn process_request(&mut self, msg: ListenRequest) -> Result<()> {
let ListenRequest {
database,
Expand Down Expand Up @@ -186,7 +186,7 @@ impl Listener {
Ok(())
}

#[instrument(level = Level::TRACE, skip_all, err)]
#[instrument(level = Level::DEBUG, skip_all, err)]
async fn process_event(&mut self, event: &DatabaseEvent) -> Result<()> {
// We rely on the fact that this function will complete before any other events are
// processed. That's why we know for sure that the output stream is not used for
Expand Down Expand Up @@ -230,6 +230,7 @@ impl Listener {
Ok(())
}

#[instrument(level = Level::DEBUG, skip_all, err)]
async fn set_document(
&mut self,
database: &FirestoreDatabase,
Expand Down Expand Up @@ -302,7 +303,7 @@ impl Listener {
Ok(())
}

#[instrument(level = Level::TRACE, skip_all, err)]
#[instrument(level = Level::DEBUG, skip_all, err)]
async fn set_query(&mut self, database: &FirestoreDatabase, query: Query) -> Result<()> {
// We rely on the fact that this function will complete before any other events are
// processed. That's why we know for sure that the output stream is not used for
Expand Down Expand Up @@ -372,7 +373,7 @@ impl Listener {
Ok(())
}

#[instrument(level = Level::TRACE, skip_all, fields(message = display(show_response_type(&response_type))), err)]
#[instrument(level = Level::DEBUG, skip_all, fields(message = display(show_response_type(&response_type))), err)]
async fn send(&self, response_type: ResponseType) -> Result<()> {
self.sender
.send(Ok(ListenResponse {
Expand All @@ -382,7 +383,7 @@ impl Listener {
.map_err(|_| GenericDatabaseError::cancelled("stream closed"))
}

#[instrument(level = Level::TRACE, skip(self), err)]
#[instrument(level = Level::DEBUG, skip(self), err)]
async fn send_err(&self, err: GenericDatabaseError) -> Result<()> {
self.sender
.send(Err(err))
Expand Down

0 comments on commit a67e02d

Please sign in to comment.