From c2dd630868eb49b94460c8753fd7a48f5612540d Mon Sep 17 00:00:00 2001 From: Miguel Fernandez Date: Wed, 18 Jan 2023 16:36:55 +0100 Subject: [PATCH] Change Into -> From impl traits --- .../core/src/interactive_transactions/mod.rs | 12 ++++++------ query-engine/query-engine/src/server/mod.rs | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/query-engine/core/src/interactive_transactions/mod.rs b/query-engine/core/src/interactive_transactions/mod.rs index 7f38562f674f..e43a7ae50b26 100644 --- a/query-engine/core/src/interactive_transactions/mod.rs +++ b/query-engine/core/src/interactive_transactions/mod.rs @@ -74,7 +74,7 @@ impl Display for TxId { } } -impl Into for TxId { +impl From for opentelemetry::Context { // This is a bit of a hack, but it's the only way to have a default trace span for a whole // transaction when no traceparent is propagated from the client. // @@ -87,8 +87,8 @@ impl Into for TxId { // // By generating this "fake" traceparent based on the transaction id, we can have a common trace_id // for all transaction operations. - fn into(self) -> opentelemetry::Context { - let trace_id: opentelemetry::trace::TraceId = self.into(); + fn from(id: TxId) -> Self { + let trace_id: opentelemetry::trace::TraceId = id.into(); let traceparent = format!("00-{}-0000000000000001-01", trace_id); let extractor: HashMap = HashMap::from_iter(vec![("traceparent".to_string(), traceparent)]); @@ -96,7 +96,7 @@ impl Into for TxId { } } -impl Into for TxId { +impl From for opentelemetry::trace::TraceId { // in order to convert a TxId (a 48 bytes cuid) into a TraceId (16 bytes), we remove the first byte, // (always 'c') and get the next 16 bytes, which are random enough to be used as a trace id. // this is a typical cuid: "c-lct0q6ma-0004-rb04-h6en1roa" @@ -108,9 +108,9 @@ impl Into for TxId { // - least significative 8 bytes. Totally random. // // We want the most entropic slice of 16 bytes that's deterministicly determined - fn into(self) -> opentelemetry::trace::TraceId { + fn from(id: TxId) -> Self { let mut buffer = [0; 16]; - let tx_id_bytes = self.0.as_bytes(); + let tx_id_bytes = id.0.as_bytes(); let len = tx_id_bytes.len(); // bytes [len-20 to len-12): least significative 4 bytes of the timestamp + 4 bytes counter diff --git a/query-engine/query-engine/src/server/mod.rs b/query-engine/query-engine/src/server/mod.rs index d370b8c7432d..61dbda7d1bf1 100644 --- a/query-engine/query-engine/src/server/mod.rs +++ b/query-engine/query-engine/src/server/mod.rs @@ -327,7 +327,7 @@ async fn transaction_commit_handler( span: _, trace_id: _, capture_config, - } = ServerExecutionContext::builder(&req.headers()) + } = ServerExecutionContext::builder(req.headers()) .with_tx_id(tx_id.clone()) .build(); @@ -359,7 +359,7 @@ async fn transaction_rollback_handler( span: _, trace_id: _, capture_config, - } = ServerExecutionContext::builder(&req.headers()) + } = ServerExecutionContext::builder(req.headers()) .with_tx_id(tx_id.clone()) .build();