diff --git a/Cargo.lock b/Cargo.lock index 4bdd7c083..8712dde8d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3004,7 +3004,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -4372,9 +4372,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.197" +version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" dependencies = [ "serde_derive", ] @@ -4390,9 +4390,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.197" +version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" dependencies = [ "proc-macro2", "quote", @@ -4401,11 +4401,12 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.120" +version = "1.0.127" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e0d21c9a8cae1235ad58a00c11cb40d4b1e5c784f1ef2c537876ed6ffd8b7c5" +checksum = "8043c06d9f82bd7271361ed64f415fe5e12a77fdb52e573e7f06a516dea329ad" dependencies = [ "itoa", + "memchr", "ryu", "serde", ] @@ -5054,6 +5055,8 @@ dependencies = [ "once_cell", "pretty_assertions", "proptest", + "serde", + "serde_json", "test-case", ] diff --git a/LICENSE-3rdparty.yml b/LICENSE-3rdparty.yml index 06367ca92..f56fff815 100644 --- a/LICENSE-3rdparty.yml +++ b/LICENSE-3rdparty.yml @@ -21631,9 +21631,9 @@ third_party_libraries: - package_name: ring package_version: 0.17.8 repository: https://github.com/briansmith/ring - license: License specified in file ($CARGO_HOME/registry/src/github.com-1ecc6299db9ec823/ring-0.17.8/LICENSE) + license: License specified in file ($CARGO_HOME/registry/src/index.crates.io-6f17d22bba15001f/ring-0.17.8/LICENSE) licenses: - - license: License specified in file ($CARGO_HOME/registry/src/github.com-1ecc6299db9ec823/ring-0.17.8/LICENSE) + - license: License specified in file ($CARGO_HOME/registry/src/index.crates.io-6f17d22bba15001f/ring-0.17.8/LICENSE) text: "Note that it is easy for this file to get out of sync with the licenses in the\nsource code files. It's recommended to compare the licenses in the source code\nwith what's mentioned here.\n\n*ring* is derived from BoringSSL, so the licensing situation in *ring* is\nsimilar to BoringSSL.\n\n*ring* uses an ISC-style license like BoringSSL for code in new files,\nincluding in particular all the Rust code:\n\n Copyright 2015-2016 Brian Smith.\n\n Permission to use, copy, modify, and/or distribute this software for any\n purpose with or without fee is hereby granted, provided that the above\n copyright notice and this permission notice appear in all copies.\n\n THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHORS DISCLAIM ALL WARRANTIES\n WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\n MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY\n SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\n WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION\n OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN\n CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n\nBoringSSL is a fork of OpenSSL. As such, large parts of it fall under OpenSSL\nlicensing. Files that are completely new have a Google copyright and an ISC\nlicense. This license is reproduced at the bottom of this file.\n\nContributors to BoringSSL are required to follow the CLA rules for Chromium:\nhttps://cla.developers.google.com/clas\n\nFiles in third_party/ have their own licenses, as described therein. The MIT\nlicense, for third_party/fiat, which, unlike other third_party directories, is\ncompiled into non-test libraries, is included below.\n\nThe OpenSSL toolkit stays under a dual license, i.e. both the conditions of the\nOpenSSL License and the original SSLeay license apply to the toolkit. See below\nfor the actual license texts. Actually both licenses are BSD-style Open Source\nlicenses. In case of any license issues related to OpenSSL please contact\nopenssl-core@openssl.org.\n\nThe following are Google-internal bug numbers where explicit permission from\nsome authors is recorded for use of their work:\n 27287199\n 27287880\n 27287883\n\n OpenSSL License\n ---------------\n\n/* ====================================================================\n * Copyright (c) 1998-2011 The OpenSSL Project. All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions\n * are met:\n *\n * 1. Redistributions of source code must retain the above copyright\n * notice, this list of conditions and the following disclaimer. \n *\n * 2. Redistributions in binary form must reproduce the above copyright\n * notice, this list of conditions and the following disclaimer in\n * the documentation and/or other materials provided with the\n * distribution.\n *\n * 3. All advertising materials mentioning features or use of this\n * software must display the following acknowledgment:\n * \"This product includes software developed by the OpenSSL Project\n * for use in the OpenSSL Toolkit. (http://www.openssl.org/)\"\n *\n * 4. The names \"OpenSSL Toolkit\" and \"OpenSSL Project\" must not be used to\n * endorse or promote products derived from this software without\n * prior written permission. For written permission, please contact\n * openssl-core@openssl.org.\n *\n * 5. Products derived from this software may not be called \"OpenSSL\"\n * nor may \"OpenSSL\" appear in their names without prior written\n * permission of the OpenSSL Project.\n *\n * 6. Redistributions of any form whatsoever must retain the following\n * acknowledgment:\n * \"This product includes software developed by the OpenSSL Project\n * for use in the OpenSSL Toolkit (http://www.openssl.org/)\"\n *\n * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY\n * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR\n * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\n * OF THE POSSIBILITY OF SUCH DAMAGE.\n * ====================================================================\n *\n * This product includes cryptographic software written by Eric Young\n * (eay@cryptsoft.com). This product includes software written by Tim\n * Hudson (tjh@cryptsoft.com).\n *\n */\n\n Original SSLeay License\n -----------------------\n\n/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)\n * All rights reserved.\n *\n * This package is an SSL implementation written\n * by Eric Young (eay@cryptsoft.com).\n * The implementation was written so as to conform with Netscapes SSL.\n * \n * This library is free for commercial and non-commercial use as long as\n * the following conditions are aheared to. The following conditions\n * apply to all code found in this distribution, be it the RC4, RSA,\n * lhash, DES, etc., code; not just the SSL code. The SSL documentation\n * included with this distribution is covered by the same copyright terms\n * except that the holder is Tim Hudson (tjh@cryptsoft.com).\n * \n * Copyright remains Eric Young's, and as such any Copyright notices in\n * the code are not to be removed.\n * If this package is used in a product, Eric Young should be given attribution\n * as the author of the parts of the library used.\n * This can be in the form of a textual message at program startup or\n * in documentation (online or textual) provided with the package.\n * \n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions\n * are met:\n * 1. Redistributions of source code must retain the copyright\n * notice, this list of conditions and the following disclaimer.\n * 2. Redistributions in binary form must reproduce the above copyright\n * notice, this list of conditions and the following disclaimer in the\n * documentation and/or other materials provided with the distribution.\n * 3. All advertising materials mentioning features or use of this software\n * must display the following acknowledgement:\n * \"This product includes cryptographic software written by\n * Eric Young (eay@cryptsoft.com)\"\n * The word 'cryptographic' can be left out if the rouines from the library\n * being used are not cryptographic related :-).\n * 4. If you include any Windows specific code (or a derivative thereof) from \n * the apps directory (application code) you must include an acknowledgement:\n * \"This product includes software written by Tim Hudson (tjh@cryptsoft.com)\"\n * \n * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND\n * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\n * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n * SUCH DAMAGE.\n * \n * The licence and distribution terms for any publically available version or\n * derivative of this code cannot be changed. i.e. this code cannot simply be\n * copied and put under another distribution licence\n * [including the GNU Public Licence.]\n */\n\n\nISC license used for completely new code in BoringSSL:\n\n/* Copyright (c) 2015, Google Inc.\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES\n * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\n * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\n * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\n * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION\n * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN\n * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */\n\n\nThe code in third_party/fiat carries the MIT license:\n\nCopyright (c) 2015-2016 the fiat-crypto authors (see\nhttps://github.com/mit-plv/fiat-crypto/blob/master/AUTHORS).\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n" - package_name: rmp package_version: 0.8.14 @@ -23629,7 +23629,7 @@ third_party_libraries: - license: BSD-3-Clause text: NOT FOUND - package_name: serde - package_version: 1.0.197 + package_version: 1.0.209 repository: https://github.com/serde-rs/serde license: MIT OR Apache-2.0 licenses: @@ -24045,7 +24045,7 @@ third_party_libraries: END OF TERMS AND CONDITIONS - package_name: serde_derive - package_version: 1.0.197 + package_version: 1.0.209 repository: https://github.com/serde-rs/serde license: MIT OR Apache-2.0 licenses: @@ -24253,7 +24253,7 @@ third_party_libraries: END OF TERMS AND CONDITIONS - package_name: serde_json - package_version: 1.0.120 + package_version: 1.0.127 repository: https://github.com/serde-rs/json license: MIT OR Apache-2.0 licenses: diff --git a/tinybytes/Cargo.toml b/tinybytes/Cargo.toml index 647ef7e33..3fa1b3adb 100644 --- a/tinybytes/Cargo.toml +++ b/tinybytes/Cargo.toml @@ -14,3 +14,11 @@ once_cell = "1.8" pretty_assertions = "1.3" proptest = {version = "1.5", features = ["std"], default-features = false} test-case = "2.2" +serde_json = "1.0.127" + +[dependencies] +serde = { version = "1.0.209", optional = true } + +[features] +bytes_string = [] +serialization = ["serde"] diff --git a/trace-utils/src/no_alloc_string.rs b/tinybytes/src/bytes_string.rs similarity index 57% rename from trace-utils/src/no_alloc_string.rs rename to tinybytes/src/bytes_string.rs index 820d8d23b..8af6036a4 100644 --- a/trace-utils/src/no_alloc_string.rs +++ b/tinybytes/src/bytes_string.rs @@ -1,12 +1,18 @@ +// Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/ +// SPDX-License-Identifier: Apache-2.0 + +use crate::Bytes; +#[cfg(all(feature = "bytes_string", feature = "serde"))] use serde::ser::{Serialize, Serializer}; use std::borrow::Borrow; use std::str::Utf8Error; -use tinybytes; +#[cfg(feature = "bytes_string")] pub struct BufferWrapper { - buffer: tinybytes::Bytes, + buffer: Bytes, } +#[cfg(feature = "bytes_string")] impl BufferWrapper { /// Creates a new `BufferWrapper` from a `tinybytes::Bytes` instance. /// @@ -17,35 +23,32 @@ impl BufferWrapper { /// # Returns /// /// A new `BufferWrapper` instance containing the provided buffer. - pub fn new(buffer: tinybytes::Bytes) -> Self { + pub fn new(buffer: Bytes) -> Self { BufferWrapper { buffer } } - /// Creates a `NoAllocString` from a slice of bytes within the wrapped buffer. + /// Creates a `BytesString` from a slice of bytes within the wrapped buffer. /// /// This function validates that the provided slice is valid UTF-8. If the slice is not valid /// UTF-8, an error is returned. /// /// # Arguments /// - /// * `slice` - A byte slice that will be converted into a `NoAllocString`. + /// * `slice` - A byte slice that will be converted into a `BytesString`. /// /// # Returns /// - /// A `Result` containing the `NoAllocString` if the slice is valid UTF-8, or a `Utf8Error` if + /// A `Result` containing the `BytesString` if the slice is valid UTF-8, or a `Utf8Error` if /// the slice is not valid UTF-8. /// /// # Errors /// /// Returns a `Utf8Error` if the bytes are not valid UTF-8. - pub fn create_no_alloc_string( - &self, - slice: &[u8], - ) -> Result { - NoAllocString::from_bytes(self.buffer.slice_ref(slice).expect("Invalid slice")) + pub fn create_bytes_string(&self, slice: &[u8]) -> Result { + BytesString::from_bytes(self.buffer.slice_ref(slice).expect("Invalid slice")) } - /// Creates a `NoAllocString` from a slice of bytes within the wrapped buffer without validating + /// Creates a `BytesString` from a slice of bytes within the wrapped buffer without validating /// the bytes. /// /// This function does not perform any validation on the provided bytes, and assumes that the @@ -53,98 +56,101 @@ impl BufferWrapper { /// /// # Arguments /// - /// * `slice` - A byte slice that will be converted into a `NoAllocString`. + /// * `slice` - A byte slice that will be converted into a `BytesString`. /// /// # Safety /// /// This function is unsafe because it assumes the bytes are valid UTF-8. If the bytes are not /// valid UTF-8, the behavior is undefined. - pub unsafe fn create_no_alloc_string_unchecked(&self, slice: &[u8]) -> NoAllocString { - NoAllocString::from_bytes_unchecked(self.buffer.slice_ref(slice).expect("Invalid slice")) + pub unsafe fn create_bytes_string_unchecked(&self, slice: &[u8]) -> BytesString { + BytesString::from_bytes_unchecked(self.buffer.slice_ref(slice).expect("Invalid slice")) } } +#[cfg(feature = "bytes_string")] #[derive(Clone, Debug, Eq, Hash, PartialEq)] -pub struct NoAllocString { - bytes: tinybytes::Bytes, +pub struct BytesString { + bytes: Bytes, } -impl Serialize for NoAllocString { +#[cfg(all(feature = "bytes_string", feature = "serde"))] +impl Serialize for BytesString { fn serialize(&self, serializer: S) -> Result where S: Serializer, { // This should be safe because we have already validated that the bytes are valid UTF-8 when - // creating the NoAllocString. + // creating the BytesString. unsafe { serializer.serialize_str(self.as_str_unchecked()) } } } -impl NoAllocString { - /// Creates a `NoAllocString` from a slice of bytes. +#[cfg(feature = "bytes_string")] +impl BytesString { + /// Creates a `BytesString` from a slice of bytes. /// /// This function validates that the provided slice is valid UTF-8. If the slice is not valid /// UTF-8, an error is returned. /// /// # Arguments /// - /// * `slice` - A byte slice that will be converted into a `NoAllocString`. + /// * `slice` - A byte slice that will be converted into a `BytesString`. /// /// # Returns /// - /// A `Result` containing the `NoAllocString` if the slice is valid UTF-8, or a `Utf8Error` if + /// A `Result` containing the `BytesString` if the slice is valid UTF-8, or a `Utf8Error` if /// the slice is not valid UTF-8. /// /// # Errors /// /// Returns a `Utf8Error` if the bytes are not valid UTF-8. - pub fn from_slice(slice: &[u8]) -> Result { + pub fn from_slice(slice: &[u8]) -> Result { std::str::from_utf8(slice)?; - Ok(NoAllocString { - bytes: tinybytes::Bytes::copy_from_slice(slice), + Ok(BytesString { + bytes: Bytes::copy_from_slice(slice), }) } - /// Creates a `NoAllocString` from a `tinybytes::Bytes` instance. + /// Creates a `BytesString` from a `tinybytes::Bytes` instance. /// /// This function validates that the provided `Bytes` instance contains valid UTF-8 data. If the /// data is not valid UTF-8, an error is returned. /// /// # Arguments /// - /// * `bytes` - A `tinybytes::Bytes` instance that will be converted into a `NoAllocString`. + /// * `bytes` - A `tinybytes::Bytes` instance that will be converted into a `BytesString`. /// /// # Returns /// - /// A `Result` containing the `NoAllocString` if the bytes are valid UTF-8, or a `Utf8Error` if + /// A `Result` containing the `BytesString` if the bytes are valid UTF-8, or a `Utf8Error` if /// the bytes are not valid UTF-8. /// /// # Errors /// /// Returns a `Utf8Error` if the bytes are not valid UTF-8. - pub fn from_bytes(bytes: tinybytes::Bytes) -> Result { + pub fn from_bytes(bytes: Bytes) -> Result { std::str::from_utf8(&bytes)?; - Ok(NoAllocString { bytes }) + Ok(BytesString { bytes }) } - /// Creates a `NoAllocString` from a `tinybytes::Bytes` instance without validating the bytes. + /// Creates a `BytesString` from a `tinybytes::Bytes` instance without validating the bytes. /// /// This function does not perform any validation on the provided bytes, and assumes that the /// bytes are valid UTF-8. If the bytes are not valid UTF-8, the behavior is undefined. /// /// # Arguments /// - /// * `bytes` - A `tinybytes::Bytes` instance that will be converted into a `NoAllocString`. + /// * `bytes` - A `tinybytes::Bytes` instance that will be converted into a `BytesString`. /// /// # Safety /// /// This function is unsafe because it assumes the bytes are valid UTF-8. If the bytes are not /// valid UTF-8, the behavior is undefined. - pub fn from_bytes_unchecked(bytes: tinybytes::Bytes) -> NoAllocString { - NoAllocString { bytes } + pub fn from_bytes_unchecked(bytes: Bytes) -> BytesString { + BytesString { bytes } } - /// Returns the string slice representation of the `NoAllocString`. The slice is checked to be + /// Returns the string slice representation of the `BytesString`. The slice is checked to be /// valid UTF-8. If you use `from_bytes` or `from_slice` this check was already performed and /// you may want to use `as_str_unchecked` instead. /// @@ -155,8 +161,8 @@ impl NoAllocString { std::str::from_utf8(&self.bytes) } - /// Returns the string slice representation of the `NoAllocString` without validating the bytes. - /// Typically, you should use `from_slice` or `from_bytes` when creating a NoAllocString to + /// Returns the string slice representation of the `BytesString` without validating the bytes. + /// Typically, you should use `from_slice` or `from_bytes` when creating a BytesString to /// ensure the bytes are valid UTF-8 (if the bytes haven't already been validated by other /// means) so further validation may be unnecessary. /// @@ -170,18 +176,20 @@ impl NoAllocString { } } -impl Default for NoAllocString { +#[cfg(feature = "bytes_string")] +impl Default for BytesString { fn default() -> Self { - NoAllocString { - bytes: tinybytes::Bytes::empty(), + BytesString { + bytes: Bytes::empty(), } } } -impl Borrow for NoAllocString { +#[cfg(feature = "bytes_string")] +impl Borrow for BytesString { fn borrow(&self) -> &str { // This is safe because we have already validated that the bytes are valid UTF-8 when - // creating the NoAllocString. + // creating the BytesString. unsafe { self.as_str_unchecked() } } } @@ -194,61 +202,61 @@ mod tests { #[test] fn test_from_slice() { let slice = b"hello"; - let no_alloc_string = NoAllocString::from_slice(slice).unwrap(); - assert_eq!(no_alloc_string.as_str().unwrap(), "hello"); + let bytes_string = BytesString::from_slice(slice).unwrap(); + assert_eq!(bytes_string.as_str().unwrap(), "hello"); } #[test] fn test_from_slice_invalid_utf8() { let invalid_utf8_slice = &[0, 159, 146, 150]; - let result = NoAllocString::from_slice(invalid_utf8_slice); + let result = BytesString::from_slice(invalid_utf8_slice); assert!(result.is_err()); } #[test] fn test_from_bytes() { - let bytes = tinybytes::Bytes::copy_from_slice(b"world"); - let no_alloc_string = NoAllocString::from_bytes(bytes).unwrap(); - assert_eq!(no_alloc_string.as_str().unwrap(), "world"); + let bytes = Bytes::copy_from_slice(b"world"); + let bytes_string = BytesString::from_bytes(bytes).unwrap(); + assert_eq!(bytes_string.as_str().unwrap(), "world"); } #[test] fn test_from_bytes_invalid_utf8() { - let invalid_utf8_bytes = tinybytes::Bytes::copy_from_slice(&[0, 159, 146, 150]); - let result = NoAllocString::from_bytes(invalid_utf8_bytes); + let invalid_utf8_bytes = Bytes::copy_from_slice(&[0, 159, 146, 150]); + let result = BytesString::from_bytes(invalid_utf8_bytes); assert!(result.is_err()); } #[test] fn test_from_bytes_unchecked() { - let bytes = tinybytes::Bytes::copy_from_slice(b"unchecked"); - let no_alloc_string = NoAllocString::from_bytes_unchecked(bytes); - assert_eq!(no_alloc_string.as_str().unwrap(), "unchecked"); + let bytes = Bytes::copy_from_slice(b"unchecked"); + let bytes_string = BytesString::from_bytes_unchecked(bytes); + assert_eq!(bytes_string.as_str().unwrap(), "unchecked"); } #[test] fn test_as_str() { - let no_alloc_string = NoAllocString::from_slice(b"test").unwrap(); - assert_eq!(no_alloc_string.as_str().unwrap(), "test"); + let bytes_string = BytesString::from_slice(b"test").unwrap(); + assert_eq!(bytes_string.as_str().unwrap(), "test"); } #[test] fn test_serialize() { - let no_alloc_string = NoAllocString::from_slice(b"serialize"); - let serialized = serde_json::to_string(&no_alloc_string.unwrap()).unwrap(); + let bytes_string = BytesString::from_slice(b"serialize"); + let serialized = serde_json::to_string(&bytes_string.unwrap()).unwrap(); assert_eq!(serialized, "\"serialize\""); } #[test] fn test_default() { - let no_alloc_string: NoAllocString = Default::default(); - assert_eq!(no_alloc_string.as_str().unwrap(), ""); + let bytes_string: BytesString = Default::default(); + assert_eq!(bytes_string.as_str().unwrap(), ""); } #[test] fn test_borrow() { - let no_alloc_string = NoAllocString::from_slice(b"borrow").unwrap(); - let borrowed: &str = no_alloc_string.borrow(); + let bytes_string = BytesString::from_slice(b"borrow").unwrap(); + let borrowed: &str = bytes_string.borrow(); assert_eq!(borrowed, "borrow"); } } diff --git a/tinybytes/src/lib.rs b/tinybytes/src/lib.rs index 036c62788..a563efb22 100644 --- a/tinybytes/src/lib.rs +++ b/tinybytes/src/lib.rs @@ -264,5 +264,6 @@ impl fmt::Debug for Bytes { } } +pub mod bytes_string; #[cfg(test)] mod test; diff --git a/trace-utils/Cargo.toml b/trace-utils/Cargo.toml index 92de1e3ae..e1edc4cbf 100644 --- a/trace-utils/Cargo.toml +++ b/trace-utils/Cargo.toml @@ -39,7 +39,7 @@ testcontainers = { version = "0.17.0", optional = true } cargo_metadata = { version = "0.18.1", optional = true } # Dependency of cargo metadata, but 0.1.8 requires too new of a rust version. cargo-platform = { version = "=0.1.7", optional = true } -tinybytes = { path = "../tinybytes" } +tinybytes = { path = "../tinybytes", features = ["bytes_string", "serialization"] } [dev-dependencies] bolero = "0.10.1" diff --git a/trace-utils/benches/deserialization.rs b/trace-utils/benches/deserialization.rs index 88bb8acf0..b16afbca9 100644 --- a/trace-utils/benches/deserialization.rs +++ b/trace-utils/benches/deserialization.rs @@ -7,7 +7,6 @@ use datadog_trace_utils::tracer_payload::{ DefaultTraceChunkProcessor, TraceEncoding, TracerPayloadCollection, TracerPayloadParams, }; use serde_json::json; -use tinybytes; pub fn deserialize_msgpack_to_internal(c: &mut Criterion) { let span_data1 = json!([{ diff --git a/trace-utils/src/lib.rs b/trace-utils/src/lib.rs index c7cbeffec..d3090e777 100644 --- a/trace-utils/src/lib.rs +++ b/trace-utils/src/lib.rs @@ -11,5 +11,4 @@ pub mod trace_utils; pub mod tracer_header_tags; pub mod tracer_payload; -pub mod no_alloc_string; pub mod span_v04; diff --git a/trace-utils/src/msgpack_decoder/v04/decoder/mod.rs b/trace-utils/src/msgpack_decoder/v04/decoder/mod.rs index 09086c95a..18478f1ad 100644 --- a/trace-utils/src/msgpack_decoder/v04/decoder/mod.rs +++ b/trace-utils/src/msgpack_decoder/v04/decoder/mod.rs @@ -7,11 +7,11 @@ mod span_link; use self::span::decode_span; use super::error::DecodeError; use super::number::read_number; -use crate::no_alloc_string::{BufferWrapper, NoAllocString}; use crate::span_v04::Span; use rmp::decode::DecodeStringError; use rmp::{decode, decode::RmpRead, Marker}; use std::{collections::HashMap, f64}; +use tinybytes::bytes_string::{BufferWrapper, BytesString}; /// Decodes a slice of bytes into a vector of `TracerPayloadV04` objects. /// @@ -106,11 +106,11 @@ fn read_string_ref(buf: &[u8]) -> Result<(&str, &[u8]), DecodeError> { #[inline] // Safety: read_string_ref checks utf8 validity, so we don't do it again when creating the -// NoAllocStrings. -fn read_str_map_to_no_alloc_strings( +// BytesStrings. +fn read_str_map_to_bytes_strings( buf_wrapper: &BufferWrapper, buf: &mut &[u8], -) -> Result, DecodeError> { +) -> Result, DecodeError> { let len = decode::read_map_len(buf) .map_err(|_| DecodeError::InvalidFormat("Unable to get map len for str map".to_owned()))?; @@ -122,8 +122,8 @@ fn read_str_map_to_no_alloc_strings( let (val, next) = read_string_ref(buf)?; *buf = next; - let key = unsafe { buf_wrapper.create_no_alloc_string_unchecked(key.as_bytes()) }; - let value = unsafe { buf_wrapper.create_no_alloc_string_unchecked(val.as_bytes()) }; + let key = unsafe { buf_wrapper.create_bytes_string_unchecked(key.as_bytes()) }; + let value = unsafe { buf_wrapper.create_bytes_string_unchecked(val.as_bytes()) }; map.insert(key, value); } Ok(map) @@ -133,19 +133,19 @@ fn read_str_map_to_no_alloc_strings( fn read_metric_pair( buffer_wrapper: &BufferWrapper, buf: &mut &[u8], -) -> Result<(NoAllocString, f64), DecodeError> { +) -> Result<(BytesString, f64), DecodeError> { let (key, next) = read_string_ref(buf)?; *buf = next; let v = read_number(buf)?.try_into()?; - let key = unsafe { buffer_wrapper.create_no_alloc_string_unchecked(key.as_bytes()) }; + let key = unsafe { buffer_wrapper.create_bytes_string_unchecked(key.as_bytes()) }; Ok((key, v)) } fn read_metrics( buf_wrapper: &BufferWrapper, buf: &mut &[u8], -) -> Result, DecodeError> { +) -> Result, DecodeError> { let len = read_map_len(buf)?; read_map(len, buf_wrapper, buf, read_metric_pair) } @@ -153,11 +153,11 @@ fn read_metrics( fn read_meta_struct( buf_wrapper: &BufferWrapper, buf: &mut &[u8], -) -> Result>, DecodeError> { +) -> Result>, DecodeError> { fn read_meta_struct_pair( buf_wrapper: &BufferWrapper, buf: &mut &[u8], - ) -> Result<(NoAllocString, Vec), DecodeError> { + ) -> Result<(BytesString, Vec), DecodeError> { let (key, next) = read_string_ref(buf)?; *buf = next; let array_len = decode::read_array_len(buf).map_err(|_| { @@ -170,7 +170,7 @@ fn read_meta_struct( let value = read_number(buf)?.try_into()?; v.push(value); } - let key = unsafe { buf_wrapper.create_no_alloc_string_unchecked(key.as_bytes()) }; + let key = unsafe { buf_wrapper.create_bytes_string_unchecked(key.as_bytes()) }; Ok((key, v)) } @@ -247,17 +247,17 @@ fn read_map_len(buf: &mut &[u8]) -> Result { #[cfg(test)] mod tests { use super::*; - use crate::no_alloc_string::NoAllocString; use crate::span_v04::SpanLink; use bolero::check; use rmp_serde; use rmp_serde::to_vec_named; + use tinybytes::bytes_string::BytesString; #[test] fn decoder_read_string_success() { let expected_string = "test-service-name"; let span = Span { - name: NoAllocString::from_slice(expected_string.as_ref()).unwrap(), + name: BytesString::from_slice(expected_string.as_ref()).unwrap(), ..Default::default() }; let encoded_data = rmp_serde::to_vec_named(&vec![vec![span]]).unwrap(); @@ -274,11 +274,11 @@ mod tests { fn test_decoder_meta_struct_fixed_map_success() { let expected_meta_struct = HashMap::from([ ( - NoAllocString::from_slice("key1".as_ref()).unwrap(), + BytesString::from_slice("key1".as_ref()).unwrap(), vec![1, 2, 3], ), ( - NoAllocString::from_slice("key2".as_ref()).unwrap(), + BytesString::from_slice("key2".as_ref()).unwrap(), vec![4, 5, 6], ), ]); @@ -299,10 +299,10 @@ mod tests { #[test] fn test_decoder_meta_struct_map_16_success() { - let expected_meta_struct: HashMap> = (0..20) + let expected_meta_struct: HashMap> = (0..20) .map(|i| { ( - NoAllocString::from_slice(format!("key {}", i).as_ref()).unwrap(), + BytesString::from_slice(format!("key {}", i).as_ref()).unwrap(), vec![1 + i, 2 + i, 3 + i], ) }) @@ -327,12 +327,12 @@ mod tests { fn test_decoder_meta_fixed_map_success() { let expected_meta = HashMap::from([ ( - NoAllocString::from_slice("key1".as_ref()).unwrap(), - NoAllocString::from_slice("value1".as_ref()).unwrap(), + BytesString::from_slice("key1".as_ref()).unwrap(), + BytesString::from_slice("value1".as_ref()).unwrap(), ), ( - NoAllocString::from_slice("key2".as_ref()).unwrap(), - NoAllocString::from_slice("value2".as_ref()).unwrap(), + BytesString::from_slice("key2".as_ref()).unwrap(), + BytesString::from_slice("value2".as_ref()).unwrap(), ), ]); let span = Span { @@ -351,11 +351,11 @@ mod tests { #[test] fn test_decoder_meta_map_16_success() { - let expected_meta: HashMap = (0..20) + let expected_meta: HashMap = (0..20) .map(|i| { ( - NoAllocString::from_slice(format!("key {}", i).as_ref()).unwrap(), - NoAllocString::from_slice(format!("value {}", i).as_ref()).unwrap(), + BytesString::from_slice(format!("key {}", i).as_ref()).unwrap(), + BytesString::from_slice(format!("value {}", i).as_ref()).unwrap(), ) }) .collect(); @@ -379,8 +379,8 @@ mod tests { fn test_decoder_metrics_fixed_map_success() { let mut span = Span::default(); let expected_metrics = HashMap::from([ - (NoAllocString::from_slice("metric1".as_ref()).unwrap(), 1.23), - (NoAllocString::from_slice("metric2".as_ref()).unwrap(), 4.56), + (BytesString::from_slice("metric1".as_ref()).unwrap(), 1.23), + (BytesString::from_slice("metric2".as_ref()).unwrap(), 4.56), ]); span.metrics = expected_metrics.clone(); let encoded_data = rmp_serde::to_vec_named(&vec![vec![span]]).unwrap(); @@ -396,10 +396,10 @@ mod tests { #[test] fn test_decoder_metrics_map16_success() { let mut span = Span::default(); - let expected_metrics: HashMap = (0..20) + let expected_metrics: HashMap = (0..20) .map(|i| { ( - NoAllocString::from_slice(format!("metric{}", i).as_ref()).unwrap(), + BytesString::from_slice(format!("metric{}", i).as_ref()).unwrap(), i as f64, ) }) @@ -424,15 +424,15 @@ mod tests { span_id: 1, attributes: HashMap::from([ ( - NoAllocString::from_slice("attr1".as_ref()).unwrap(), - NoAllocString::from_slice("test_value".as_ref()).unwrap(), + BytesString::from_slice("attr1".as_ref()).unwrap(), + BytesString::from_slice("test_value".as_ref()).unwrap(), ), ( - NoAllocString::from_slice("attr2".as_ref()).unwrap(), - NoAllocString::from_slice("test_value2".as_ref()).unwrap(), + BytesString::from_slice("attr2".as_ref()).unwrap(), + BytesString::from_slice("test_value2".as_ref()).unwrap(), ), ]), - tracestate: NoAllocString::from_slice("state_test".as_ref()).unwrap(), + tracestate: BytesString::from_slice("state_test".as_ref()).unwrap(), flags: 0b101, }]; @@ -453,7 +453,7 @@ mod tests { #[test] fn test_decoder_read_string_wrong_format() { let span = Span { - service: NoAllocString::from_slice("my_service".as_ref()).unwrap(), + service: BytesString::from_slice("my_service".as_ref()).unwrap(), ..Default::default() }; let mut encoded_data = rmp_serde::to_vec_named(&vec![vec![span]]).unwrap(); @@ -475,7 +475,7 @@ mod tests { let invalid_str = unsafe { String::from_utf8_unchecked(invalid_seq) }; let invalid_str_as_bytes = tinybytes::Bytes::from(invalid_str); let span = Span { - name: NoAllocString::from_bytes_unchecked(invalid_str_as_bytes), + name: BytesString::from_bytes_unchecked(invalid_str_as_bytes), ..Default::default() }; let encoded_data = rmp_serde::to_vec_named(&vec![vec![span]]).unwrap(); @@ -574,16 +574,16 @@ mod tests { start, )| { let span = Span { - name: NoAllocString::from_slice(name.as_ref()).unwrap(), - service: NoAllocString::from_slice(service.as_ref()).unwrap(), - resource: NoAllocString::from_slice(resource.as_ref()).unwrap(), - r#type: NoAllocString::from_slice(span_type.as_ref()).unwrap(), + name: BytesString::from_slice(name.as_ref()).unwrap(), + service: BytesString::from_slice(service.as_ref()).unwrap(), + resource: BytesString::from_slice(resource.as_ref()).unwrap(), + r#type: BytesString::from_slice(span_type.as_ref()).unwrap(), meta: HashMap::from([( - NoAllocString::from_slice(meta_key.as_ref()).unwrap(), - NoAllocString::from_slice(meta_value.as_ref()).unwrap(), + BytesString::from_slice(meta_key.as_ref()).unwrap(), + BytesString::from_slice(meta_value.as_ref()).unwrap(), )]), metrics: HashMap::from([( - NoAllocString::from_slice(metric_key.as_ref()).unwrap(), + BytesString::from_slice(metric_key.as_ref()).unwrap(), metric_value.parse::().unwrap_or_default(), )]), trace_id, diff --git a/trace-utils/src/msgpack_decoder/v04/decoder/span.rs b/trace-utils/src/msgpack_decoder/v04/decoder/span.rs index 226e334cf..bbc476243 100644 --- a/trace-utils/src/msgpack_decoder/v04/decoder/span.rs +++ b/trace-utils/src/msgpack_decoder/v04/decoder/span.rs @@ -2,13 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 use super::{ - read_meta_struct, read_metrics, read_str_map_to_no_alloc_strings, read_string_ref, + read_meta_struct, read_metrics, read_str_map_to_bytes_strings, read_string_ref, span_link::read_span_links, }; use crate::msgpack_decoder::v04::error::DecodeError; use crate::msgpack_decoder::v04::number::read_number; -use crate::no_alloc_string::BufferWrapper; use crate::span_v04::{Span, SpanKey}; +use tinybytes::bytes_string::BufferWrapper; /// Decodes a slice of bytes into a `Span` object. /// @@ -45,7 +45,7 @@ pub fn decode_span<'a>( } // Safety: read_string_ref checks utf8 validity, so we don't do it again when creating the -// NoAllocStrings +// BytesStrings fn fill_span( span: &mut Span, buf_wrapper: &BufferWrapper, @@ -61,19 +61,17 @@ fn fill_span( match key { SpanKey::Service => { let (value, next) = read_string_ref(buf)?; - span.service = - unsafe { buf_wrapper.create_no_alloc_string_unchecked(value.as_bytes()) }; + span.service = unsafe { buf_wrapper.create_bytes_string_unchecked(value.as_bytes()) }; *buf = next; } SpanKey::Name => { let (value, next) = read_string_ref(buf)?; - span.name = unsafe { buf_wrapper.create_no_alloc_string_unchecked(value.as_bytes()) }; + span.name = unsafe { buf_wrapper.create_bytes_string_unchecked(value.as_bytes()) }; *buf = next; } SpanKey::Resource => { let (value, next) = read_string_ref(buf)?; - span.resource = - unsafe { buf_wrapper.create_no_alloc_string_unchecked(value.as_bytes()) }; + span.resource = unsafe { buf_wrapper.create_bytes_string_unchecked(value.as_bytes()) }; *buf = next; } SpanKey::TraceId => span.trace_id = read_number(buf)?.try_into()?, @@ -84,10 +82,10 @@ fn fill_span( SpanKey::Error => span.error = read_number(buf)?.try_into()?, SpanKey::Type => { let (value, next) = read_string_ref(buf)?; - span.r#type = unsafe { buf_wrapper.create_no_alloc_string_unchecked(value.as_bytes()) }; + span.r#type = unsafe { buf_wrapper.create_bytes_string_unchecked(value.as_bytes()) }; *buf = next; } - SpanKey::Meta => span.meta = read_str_map_to_no_alloc_strings(buf_wrapper, buf)?, + SpanKey::Meta => span.meta = read_str_map_to_bytes_strings(buf_wrapper, buf)?, SpanKey::Metrics => span.metrics = read_metrics(buf_wrapper, buf)?, SpanKey::MetaStruct => span.meta_struct = read_meta_struct(buf_wrapper, buf)?, SpanKey::SpanLinks => span.span_links = read_span_links(buf_wrapper, buf)?, diff --git a/trace-utils/src/msgpack_decoder/v04/decoder/span_link.rs b/trace-utils/src/msgpack_decoder/v04/decoder/span_link.rs index 9434d8f9d..33ab728bd 100644 --- a/trace-utils/src/msgpack_decoder/v04/decoder/span_link.rs +++ b/trace-utils/src/msgpack_decoder/v04/decoder/span_link.rs @@ -1,13 +1,13 @@ // Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/ // SPDX-License-Identifier: Apache-2.0 -use crate::msgpack_decoder::v04::decoder::{read_str_map_to_no_alloc_strings, read_string_ref}; +use crate::msgpack_decoder::v04::decoder::{read_str_map_to_bytes_strings, read_string_ref}; use crate::msgpack_decoder::v04::error::DecodeError; use crate::msgpack_decoder::v04::number::read_number; -use crate::no_alloc_string::BufferWrapper; use crate::span_v04::SpanLink; use rmp::Marker; use std::str::FromStr; +use tinybytes::bytes_string::BufferWrapper; /// Reads a slice of bytes and decodes it into a vector of `SpanLink` objects. /// @@ -73,8 +73,6 @@ impl FromStr for SpanLinkKey { } } -// Safety: read_string_ref checks utf8 validity, so we don't do it again when creating the -// NoAllocStrings fn decode_span_link(buf_wrapper: &BufferWrapper, buf: &mut &[u8]) -> Result { let mut span = SpanLink::default(); let span_size = rmp::decode::read_map_len(buf) @@ -90,12 +88,12 @@ fn decode_span_link(buf_wrapper: &BufferWrapper, buf: &mut &[u8]) -> Result span.trace_id_high = read_number(buf)?.try_into()?, SpanLinkKey::SpanId => span.span_id = read_number(buf)?.try_into()?, SpanLinkKey::Attributes => { - span.attributes = read_str_map_to_no_alloc_strings(buf_wrapper, buf)? + span.attributes = read_str_map_to_bytes_strings(buf_wrapper, buf)? } SpanLinkKey::Tracestate => { let (val, next) = read_string_ref(buf)?; span.tracestate = - unsafe { buf_wrapper.create_no_alloc_string_unchecked(val.as_bytes()) }; + unsafe { buf_wrapper.create_bytes_string_unchecked(val.as_bytes()) }; *buf = next; } SpanLinkKey::Flags => span.flags = read_number(buf)?.try_into()?, diff --git a/trace-utils/src/span_v04.rs b/trace-utils/src/span_v04.rs index 85d5a22e1..3dd058e7a 100644 --- a/trace-utils/src/span_v04.rs +++ b/trace-utils/src/span_v04.rs @@ -1,8 +1,11 @@ -use crate::no_alloc_string::NoAllocString; +// Copyright 2021-Present Datadog, Inc. https://www.datadoghq.com/ +// SPDX-License-Identifier: Apache-2.0 + use serde::Serialize; use std::collections::HashMap; use std::fmt; use std::str::FromStr; +use tinybytes::bytes_string::BytesString; #[derive(Debug, PartialEq)] pub enum SpanKey { @@ -48,10 +51,10 @@ impl FromStr for SpanKey { #[derive(Clone, Debug, Default, PartialEq, Serialize)] pub struct Span { - pub service: NoAllocString, - pub name: NoAllocString, - pub resource: NoAllocString, - pub r#type: NoAllocString, + pub service: BytesString, + pub name: BytesString, + pub resource: BytesString, + pub r#type: BytesString, pub trace_id: u64, pub span_id: u64, pub parent_id: u64, @@ -60,11 +63,11 @@ pub struct Span { #[serde(skip_serializing_if = "is_default")] pub error: i32, #[serde(skip_serializing_if = "HashMap::is_empty")] - pub meta: HashMap, + pub meta: HashMap, #[serde(skip_serializing_if = "HashMap::is_empty")] - pub metrics: HashMap, + pub metrics: HashMap, #[serde(skip_serializing_if = "HashMap::is_empty")] - pub meta_struct: HashMap>, + pub meta_struct: HashMap>, #[serde(skip_serializing_if = "Vec::is_empty")] pub span_links: Vec, } @@ -74,8 +77,8 @@ pub struct SpanLink { pub trace_id: u64, pub trace_id_high: u64, pub span_id: u64, - pub attributes: HashMap, - pub tracestate: NoAllocString, + pub attributes: HashMap, + pub tracestate: BytesString, pub flags: u64, } diff --git a/trace-utils/src/test_utils/mod.rs b/trace-utils/src/test_utils/mod.rs index 9797c25a9..0d5c5454f 100644 --- a/trace-utils/src/test_utils/mod.rs +++ b/trace-utils/src/test_utils/mod.rs @@ -6,7 +6,6 @@ pub mod datadog_test_agent; use std::collections::HashMap; use std::time::Duration; -use crate::no_alloc_string::NoAllocString; use crate::send_data::SendData; use crate::span_v04::Span; use crate::trace_utils::TracerHeaderTags; @@ -15,6 +14,7 @@ use datadog_trace_protobuf::pb; use ddcommon::Endpoint; use httpmock::Mock; use serde_json::json; +use tinybytes::bytes_string::BytesString; use tokio::time::sleep; pub fn create_test_no_alloc_span( @@ -27,50 +27,48 @@ pub fn create_test_no_alloc_span( let mut span = Span { trace_id, span_id, - service: NoAllocString::from_slice("test-service".as_ref()).unwrap(), - name: NoAllocString::from_slice("test_name".as_ref()).unwrap(), - resource: NoAllocString::from_slice("test-resource".as_ref()).unwrap(), + service: BytesString::from_slice("test-service".as_ref()).unwrap(), + name: BytesString::from_slice("test_name".as_ref()).unwrap(), + resource: BytesString::from_slice("test-resource".as_ref()).unwrap(), parent_id, start, duration: 5, error: 0, meta: HashMap::from([ ( - NoAllocString::from_slice("service".as_ref()).unwrap(), - NoAllocString::from_slice("test-service".as_ref()).unwrap(), + BytesString::from_slice("service".as_ref()).unwrap(), + BytesString::from_slice("test-service".as_ref()).unwrap(), ), ( - NoAllocString::from_slice("env".as_ref()).unwrap(), - NoAllocString::from_slice("test-env".as_ref()).unwrap(), + BytesString::from_slice("env".as_ref()).unwrap(), + BytesString::from_slice("test-env".as_ref()).unwrap(), ), ( - NoAllocString::from_slice("runtime-id".as_ref()).unwrap(), - NoAllocString::from_slice("test-runtime-id-value".as_ref()).unwrap(), + BytesString::from_slice("runtime-id".as_ref()).unwrap(), + BytesString::from_slice("test-runtime-id-value".as_ref()).unwrap(), ), ]), metrics: HashMap::new(), - r#type: NoAllocString::default(), + r#type: BytesString::default(), meta_struct: HashMap::new(), span_links: vec![], }; if is_top_level { - span.metrics.insert( - NoAllocString::from_slice("_top_level".as_ref()).unwrap(), - 1.0, - ); + span.metrics + .insert(BytesString::from_slice("_top_level".as_ref()).unwrap(), 1.0); span.meta.insert( - NoAllocString::from_slice("_dd.origin".as_ref()).unwrap(), - NoAllocString::from_slice("cloudfunction".as_ref()).unwrap(), + BytesString::from_slice("_dd.origin".as_ref()).unwrap(), + BytesString::from_slice("cloudfunction".as_ref()).unwrap(), ); span.meta.insert( - NoAllocString::from_slice("origin".as_ref()).unwrap(), - NoAllocString::from_slice("cloudfunction".as_ref()).unwrap(), + BytesString::from_slice("origin".as_ref()).unwrap(), + BytesString::from_slice("cloudfunction".as_ref()).unwrap(), ); span.meta.insert( - NoAllocString::from_slice("functionname".as_ref()).unwrap(), - NoAllocString::from_slice("dummy_function_name".as_ref()).unwrap(), + BytesString::from_slice("functionname".as_ref()).unwrap(), + BytesString::from_slice("dummy_function_name".as_ref()).unwrap(), ); - span.r#type = NoAllocString::from_slice("serverless".as_ref()).unwrap(); + span.r#type = BytesString::from_slice("serverless".as_ref()).unwrap(); } span } diff --git a/trace-utils/src/tracer_payload.rs b/trace-utils/src/tracer_payload.rs index 216452633..e16a7a365 100644 --- a/trace-utils/src/tracer_payload.rs +++ b/trace-utils/src/tracer_payload.rs @@ -280,11 +280,11 @@ impl<'a, T: TraceChunkProcessor + 'a> TryInto #[cfg(test)] mod tests { use super::*; - use crate::no_alloc_string::NoAllocString; use crate::test_utils::create_test_no_alloc_span; use datadog_trace_protobuf::pb; use serde_json::json; use std::collections::HashMap; + use tinybytes::bytes_string::BytesString; fn create_dummy_collection_v07() -> TracerPayloadCollection { TracerPayloadCollection::V07(vec![pb::TracerPayload { @@ -383,9 +383,9 @@ mod tests { }]); let expected_serialized_span_data1 = vec![Span { - service: NoAllocString::from_slice("test-service".as_ref()).unwrap(), - name: NoAllocString::from_slice("test-service-name".as_ref()).unwrap(), - resource: NoAllocString::from_slice("test-service-resource".as_ref()).unwrap(), + service: BytesString::from_slice("test-service".as_ref()).unwrap(), + name: BytesString::from_slice("test-service-name".as_ref()).unwrap(), + resource: BytesString::from_slice("test-service-resource".as_ref()).unwrap(), trace_id: 111, span_id: 222, parent_id: 100, @@ -395,7 +395,7 @@ mod tests { meta: HashMap::new(), metrics: HashMap::new(), meta_struct: HashMap::new(), - r#type: NoAllocString::from_slice("serverless".as_ref()).unwrap(), + r#type: BytesString::from_slice("serverless".as_ref()).unwrap(), span_links: vec![], }]; @@ -415,9 +415,9 @@ mod tests { }]); let expected_serialized_span_data2 = vec![Span { - service: NoAllocString::from_slice("test-service".as_ref()).unwrap(), - name: NoAllocString::from_slice("test-service-name".as_ref()).unwrap(), - resource: NoAllocString::from_slice("test-service-resource".as_ref()).unwrap(), + service: BytesString::from_slice("test-service".as_ref()).unwrap(), + name: BytesString::from_slice("test-service-name".as_ref()).unwrap(), + resource: BytesString::from_slice("test-service-resource".as_ref()).unwrap(), trace_id: 111, span_id: 333, parent_id: 100, @@ -427,7 +427,7 @@ mod tests { meta: HashMap::new(), metrics: HashMap::new(), meta_struct: HashMap::new(), - r#type: NoAllocString::default(), + r#type: BytesString::default(), span_links: vec![], }]; diff --git a/trace-utils/tests/test_send_data.rs b/trace-utils/tests/test_send_data.rs index 6d435b29b..fe87b2748 100644 --- a/trace-utils/tests/test_send_data.rs +++ b/trace-utils/tests/test_send_data.rs @@ -2,15 +2,14 @@ // SPDX-License-Identifier: Apache-2.0 #[cfg(test)] - mod tracing_integration_tests { - use datadog_trace_utils::no_alloc_string::NoAllocString; use datadog_trace_utils::send_data::SendData; use datadog_trace_utils::test_utils::create_test_no_alloc_span; use datadog_trace_utils::test_utils::datadog_test_agent::DatadogTestAgent; use datadog_trace_utils::trace_utils::TracerHeaderTags; use datadog_trace_utils::tracer_payload::TracerPayloadCollection; use ddcommon::Endpoint; + use tinybytes::bytes_string::BytesString; #[cfg_attr(miri, ignore)] #[tokio::test] @@ -37,18 +36,18 @@ mod tracing_integration_tests { let mut span_1 = create_test_no_alloc_span(1234, 12342, 12341, 1, false); span_1.metrics.insert( - NoAllocString::from_slice("_dd_metric1".as_ref()).unwrap(), + BytesString::from_slice("_dd_metric1".as_ref()).unwrap(), 1.0, ); span_1.metrics.insert( - NoAllocString::from_slice("_dd_metric2".as_ref()).unwrap(), + BytesString::from_slice("_dd_metric2".as_ref()).unwrap(), 2.0, ); let span_2 = create_test_no_alloc_span(1234, 12343, 12341, 1, false); let mut root_span = create_test_no_alloc_span(1234, 12341, 0, 0, true); - root_span.r#type = NoAllocString::from_slice("web".as_ref()).unwrap(); + root_span.r#type = BytesString::from_slice("web".as_ref()).unwrap(); let trace = vec![span_1, span_2, root_span];