Vendor dependencies for 0.3.0 release

This commit is contained in:
2025-09-27 10:29:08 -05:00
parent 0c8d39d483
commit 82ab7f317b
26803 changed files with 16134934 additions and 0 deletions

View File

@@ -0,0 +1 @@
{"files":{"Cargo.toml":"db14df8d7d7abf9b32dccd76ef2f3bd59bccc646a47caad949a90f076a180ae0","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"c8a0ba6fae6e71dceb5712a31fa4ae4de31b996c638bb458e66e1d81713d699b","README.md":"fb41ca327584e592c600e002e5947b384478c01aa227c0a95280a1768501e64a","src/lib.rs":"4d71d428b624fc8987672eeb9f6e4894091493b7ae8b1d38f840b722670f11ff"},"package":"4575c663a174420fa2d78f4108ff68f65bf2fbb7dd89f33749b6e826b3626e07"}

46
vendor/tracing-wasm/Cargo.toml vendored Normal file
View File

@@ -0,0 +1,46 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies
#
# If you believe there's an error in this file please file an
# issue against the rust-lang/cargo repository. If you're
# editing this file be aware that the upstream Cargo.toml
# will likely look very different (and much more reasonable)
[package]
edition = "2018"
name = "tracing-wasm"
version = "0.2.1"
authors = ["Cole Lawrence <cole@colelawrence.com>", "Story.ai Team <team@story.ai>"]
exclude = ["*.png"]
description = "tracing subscriber for browser WASM"
readme = "README.md"
keywords = ["logging", "metrics", "wasm", "spans", "tracing"]
categories = ["development-tools::debugging", "development-tools::profiling", "no-std", "wasm"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/storyai/tracing-wasm"
[lib]
crate-type = ["cdylib", "rlib"]
[dependencies.rayon]
version = "1.5"
optional = true
[dependencies.tracing]
version = "0.1"
features = ["attributes"]
default-features = false
[dependencies.tracing-subscriber]
version = "0.3"
features = ["registry"]
default-features = false
[dependencies.wasm-bindgen]
version = "0.2"
[features]
mark-with-rayon-thread-index = ["rayon"]

201
vendor/tracing-wasm/LICENSE-APACHE vendored Normal file
View File

@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

25
vendor/tracing-wasm/LICENSE-MIT vendored Normal file
View File

@@ -0,0 +1,25 @@
Copyright (c) 2020 Story.ai
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

41
vendor/tracing-wasm/README.md vendored Normal file
View File

@@ -0,0 +1,41 @@
# `tracing-wasm`
Leverage performance profiling with your browser tools with the [tracing crate](https://crates.io/crates/tracing).
[![Crates.io][crates-badge]][crates-url]
[![Documentation][docs-badge]][docs-url]
[![MIT licensed][mit-badge]][mit-url]
[![APACHE licensed][apache-2-badge]][apache-2-url]
[crates-badge]: https://img.shields.io/crates/v/tracing-wasm.svg
[crates-url]: https://crates.io/crates/tracing-wasm
[docs-badge]: https://docs.rs/tracing-wasm/badge.svg
[docs-url]: https://docs.rs/tracing-wasm
[mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg
[mit-url]: LICENSE-MIT
[apache-2-badge]: https://img.shields.io/badge/license-APACHE%202.0-blue.svg
[apache-2-url]: LICENSE-APACHE
![Screenshot of performance reported using the `tracing-wasm` Subscriber](./2020-07-10-devtools-demo-screenshot.png)
Note: `tracing_wasm` uses the global JavaScript `console` and `performance` objects. It will not work in environments where one or both of these are not available, such as Node.js or Cloudflare Workers.
## Usage
For the simplest out of the box set-up, you can simply set `tracing_wasm` as your default tracing Subscriber in wasm_bindgen(start)
We have this declared in our `./src/lib.rs`
```rust
#[wasm_bindgen(start)]
pub fn start() -> Result<(), JsValue> {
// print pretty errors in wasm https://github.com/rustwasm/console_error_panic_hook
// This is not needed for tracing_wasm to work, but it is a common tool for getting proper error line numbers for panics.
console_error_panic_hook::set_once();
// Add this line:
tracing_wasm::set_as_global_default();
Ok(())
}
```

470
vendor/tracing-wasm/src/lib.rs vendored Normal file
View File

@@ -0,0 +1,470 @@
use core::fmt::{self, Write};
use core::sync::atomic::AtomicUsize;
use tracing::Subscriber;
use tracing::{
dispatcher::SetGlobalDefaultError,
field::{Field, Visit},
};
use tracing_subscriber::layer::*;
use tracing_subscriber::registry::*;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = performance)]
fn mark(a: &str);
#[wasm_bindgen(catch, js_namespace = performance)]
fn measure(name: String, startMark: String) -> Result<(), JsValue>;
#[wasm_bindgen(js_namespace = console, js_name = log)]
fn log1(message: String);
#[wasm_bindgen(js_namespace = console, js_name = log)]
fn log2(message1: &str, message2: &str);
#[wasm_bindgen(js_namespace = console, js_name = log)]
fn log3(message1: &str, message2: &str, message3: &str);
#[wasm_bindgen(js_namespace = console, js_name = log)]
fn log4(message1: String, message2: &str, message3: &str, message4: &str);
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_default_built_config() {
let builder = WASMLayerConfigBuilder::new();
let config = builder.build();
assert_eq!(
config,
WASMLayerConfig {
report_logs_in_timings: true,
report_logs_in_console: true,
use_console_color: true,
max_level: tracing::Level::TRACE,
}
)
}
#[test]
fn test_set_report_logs_in_timings() {
let mut builder = WASMLayerConfigBuilder::new();
builder.set_report_logs_in_timings(false);
let config = builder.build();
assert_eq!(config.report_logs_in_timings, false);
}
#[test]
fn test_set_console_config_no_reporting() {
let mut builder = WASMLayerConfigBuilder::new();
builder.set_console_config(ConsoleConfig::NoReporting);
let config = builder.build();
assert_eq!(config.report_logs_in_console, false);
assert_eq!(config.use_console_color, false);
}
#[test]
fn test_set_console_config_without_color() {
let mut builder = WASMLayerConfigBuilder::new();
builder.set_console_config(ConsoleConfig::ReportWithoutConsoleColor);
let config = builder.build();
assert_eq!(config.report_logs_in_console, true);
assert_eq!(config.use_console_color, false);
}
#[test]
fn test_set_console_config_with_color() {
let mut builder = WASMLayerConfigBuilder::new();
builder.set_console_config(ConsoleConfig::ReportWithConsoleColor);
let config = builder.build();
assert_eq!(config.report_logs_in_console, true);
assert_eq!(config.use_console_color, true);
}
#[test]
fn test_default_config_log_level() {
let builder = WASMLayerConfigBuilder::new();
let config = builder.build();
assert_eq!(config.max_level, tracing::Level::TRACE);
}
#[test]
fn test_set_config_log_level_warn() {
let mut builder = WASMLayerConfigBuilder::new();
builder.set_max_level(tracing::Level::WARN);
let config = builder.build();
assert_eq!(config.max_level, tracing::Level::WARN);
}
}
pub enum ConsoleConfig {
NoReporting,
ReportWithoutConsoleColor,
ReportWithConsoleColor,
}
pub struct WASMLayerConfigBuilder {
/// Log events will be marked and measured so they appear in performance Timings
report_logs_in_timings: bool,
/// Log events will be logged to the browser console
report_logs_in_console: bool,
/// Only relevant if report_logs_in_console is true, this will use color style strings in the console.
use_console_color: bool,
/// Log events will be reported from this level -- Default is ALL (TRACE)
max_level: tracing::Level,
}
impl WASMLayerConfigBuilder {
pub fn new() -> WASMLayerConfigBuilder {
WASMLayerConfigBuilder::default()
}
/// Set whether events should appear in performance Timings
pub fn set_report_logs_in_timings(
&mut self,
report_logs_in_timings: bool,
) -> &mut WASMLayerConfigBuilder {
self.report_logs_in_timings = report_logs_in_timings;
self
}
/// Set the maximal level on which events should be displayed
pub fn set_max_level(&mut self, max_level: tracing::Level) -> &mut WASMLayerConfigBuilder {
self.max_level = max_level;
self
}
/// Set if and how events should be displayed in the browser console
pub fn set_console_config(
&mut self,
console_config: ConsoleConfig,
) -> &mut WASMLayerConfigBuilder {
match console_config {
ConsoleConfig::NoReporting => {
self.report_logs_in_console = false;
self.use_console_color = false;
}
ConsoleConfig::ReportWithoutConsoleColor => {
self.report_logs_in_console = true;
self.use_console_color = false;
}
ConsoleConfig::ReportWithConsoleColor => {
self.report_logs_in_console = true;
self.use_console_color = true;
}
}
self
}
/// Build the WASMLayerConfig
pub fn build(&self) -> WASMLayerConfig {
WASMLayerConfig {
report_logs_in_timings: self.report_logs_in_timings,
report_logs_in_console: self.report_logs_in_console,
use_console_color: self.use_console_color,
max_level: self.max_level,
}
}
}
impl Default for WASMLayerConfigBuilder {
fn default() -> WASMLayerConfigBuilder {
WASMLayerConfigBuilder {
report_logs_in_timings: true,
report_logs_in_console: true,
use_console_color: true,
max_level: tracing::Level::TRACE,
}
}
}
#[derive(Debug, PartialEq)]
pub struct WASMLayerConfig {
report_logs_in_timings: bool,
report_logs_in_console: bool,
use_console_color: bool,
max_level: tracing::Level,
}
impl core::default::Default for WASMLayerConfig {
fn default() -> Self {
WASMLayerConfig {
report_logs_in_timings: true,
report_logs_in_console: true,
use_console_color: true,
max_level: tracing::Level::TRACE,
}
}
}
/// Implements [tracing_subscriber::layer::Layer] which uses [wasm_bindgen] for marking and measuring with `window.performance`
pub struct WASMLayer {
last_event_id: AtomicUsize,
config: WASMLayerConfig,
}
impl WASMLayer {
pub fn new(config: WASMLayerConfig) -> Self {
WASMLayer {
last_event_id: AtomicUsize::new(0),
config,
}
}
}
impl core::default::Default for WASMLayer {
fn default() -> Self {
WASMLayer::new(WASMLayerConfig::default())
}
}
#[cfg(not(feature = "mark-with-rayon-thread-index"))]
#[inline]
fn thread_display_suffix() -> &'static str {
""
}
#[cfg(feature = "mark-with-rayon-thread-index")]
fn thread_display_suffix() -> String {
let mut message = " #".to_string();
match rayon::current_thread_index() {
Some(idx) => message.push_str(&format!("{}", idx)),
None => message.push_str("main"),
}
message
}
#[cfg(not(feature = "mark-with-rayon-thread-index"))]
fn mark_name(id: &tracing::Id) -> String {
format!("t{:x}", id.into_u64())
}
#[cfg(feature = "mark-with-rayon-thread-index")]
fn mark_name(id: &tracing::Id) -> String {
format!(
"t{:x}-{}",
id.into_u64(),
rayon::current_thread_index().unwrap_or(999)
)
}
impl<S: Subscriber + for<'a> LookupSpan<'a>> Layer<S> for WASMLayer {
fn enabled(&self, metadata: &tracing::Metadata<'_>, _: Context<'_, S>) -> bool {
let level = metadata.level();
level <= &self.config.max_level
}
fn on_new_span(
&self,
attrs: &tracing::span::Attributes<'_>,
id: &tracing::Id,
ctx: Context<'_, S>,
) {
let mut new_debug_record = StringRecorder::new();
attrs.record(&mut new_debug_record);
if let Some(span_ref) = ctx.span(id) {
span_ref
.extensions_mut()
.insert::<StringRecorder>(new_debug_record);
}
}
/// doc: Notifies this layer that a span with the given Id recorded the given values.
fn on_record(&self, id: &tracing::Id, values: &tracing::span::Record<'_>, ctx: Context<'_, S>) {
if let Some(span_ref) = ctx.span(id) {
if let Some(debug_record) = span_ref.extensions_mut().get_mut::<StringRecorder>() {
values.record(debug_record);
}
}
}
// /// doc: Notifies this layer that a span with the ID span recorded that it follows from the span with the ID follows.
// fn on_follows_from(&self, _span: &tracing::Id, _follows: &tracing::Id, ctx: Context<'_, S>) {}
/// doc: Notifies this layer that an event has occurred.
fn on_event(&self, event: &tracing::Event<'_>, _ctx: Context<'_, S>) {
if self.config.report_logs_in_timings || self.config.report_logs_in_console {
let mut recorder = StringRecorder::new();
event.record(&mut recorder);
let meta = event.metadata();
let level = meta.level();
if self.config.report_logs_in_console {
let origin = meta
.file()
.and_then(|file| meta.line().map(|ln| format!("{}:{}", file, ln)))
.unwrap_or_default();
if self.config.use_console_color {
log4(
format!(
"%c{}%c {}{}%c{}",
level,
origin,
thread_display_suffix(),
recorder,
),
match *level {
tracing::Level::TRACE => "color: dodgerblue; background: #444",
tracing::Level::DEBUG => "color: lawngreen; background: #444",
tracing::Level::INFO => "color: whitesmoke; background: #444",
tracing::Level::WARN => "color: orange; background: #444",
tracing::Level::ERROR => "color: red; background: #444",
},
"color: gray; font-style: italic",
"color: inherit",
);
} else {
log1(format!(
"{} {}{} {}",
level,
origin,
thread_display_suffix(),
recorder,
));
}
}
if self.config.report_logs_in_timings {
let mark_name = format!(
"c{:x}",
self.last_event_id
.fetch_add(1, core::sync::atomic::Ordering::Relaxed)
);
// mark and measure so you can see a little blip in the profile
mark(&mark_name);
let _ = measure(
format!(
"{} {}{} {}",
level,
meta.module_path().unwrap_or("..."),
thread_display_suffix(),
recorder,
),
mark_name,
);
}
}
}
/// doc: Notifies this layer that a span with the given ID was entered.
fn on_enter(&self, id: &tracing::Id, _ctx: Context<'_, S>) {
mark(&mark_name(id));
}
/// doc: Notifies this layer that the span with the given ID was exited.
fn on_exit(&self, id: &tracing::Id, ctx: Context<'_, S>) {
if let Some(span_ref) = ctx.span(id) {
let meta = span_ref.metadata();
if let Some(debug_record) = span_ref.extensions().get::<StringRecorder>() {
let _ = measure(
format!(
"\"{}\"{} {} {}",
meta.name(),
thread_display_suffix(),
meta.module_path().unwrap_or("..."),
debug_record,
),
mark_name(id),
);
} else {
let _ = measure(
format!(
"\"{}\"{} {}",
meta.name(),
thread_display_suffix(),
meta.module_path().unwrap_or("..."),
),
mark_name(id),
);
}
}
}
// /// doc: Notifies this layer that the span with the given ID has been closed.
// /// We can dispose of any data for the span we might have here...
// fn on_close(&self, _id: tracing::Id, ctx: Context<'_, S>) {}
// /// doc: Notifies this layer that a span ID has been cloned, and that the subscriber returned a different ID.
// /// I'm not sure if I need to do something here...
// fn on_id_change(&self, _old: &tracing::Id, _new: &tracing::Id, ctx: Context<'_, S>) {}
}
/// Set the global default with [tracing::subscriber::set_global_default]
pub fn set_as_global_default() {
tracing::subscriber::set_global_default(
Registry::default().with(WASMLayer::new(WASMLayerConfig::default())),
)
.expect("default global");
}
/// Set the global default with [tracing::subscriber::set_global_default]
pub fn try_set_as_global_default() -> Result<(), SetGlobalDefaultError> {
tracing::subscriber::set_global_default(
Registry::default().with(WASMLayer::new(WASMLayerConfig::default())),
)
}
/// Set the global default with [tracing::subscriber::set_global_default]
pub fn set_as_global_default_with_config(config: WASMLayerConfig) {
tracing::subscriber::set_global_default(Registry::default().with(WASMLayer::new(config)))
.expect("default global");
}
struct StringRecorder {
display: String,
is_following_args: bool,
}
impl StringRecorder {
fn new() -> Self {
StringRecorder {
display: String::new(),
is_following_args: false,
}
}
}
impl Visit for StringRecorder {
fn record_debug(&mut self, field: &Field, value: &dyn fmt::Debug) {
if field.name() == "message" {
if !self.display.is_empty() {
self.display = format!("{:?}\n{}", value, self.display)
} else {
self.display = format!("{:?}", value)
}
} else {
if self.is_following_args {
// following args
writeln!(self.display).unwrap();
} else {
// first arg
write!(self.display, " ").unwrap();
self.is_following_args = true;
}
write!(self.display, "{} = {:?};", field.name(), value).unwrap();
}
}
}
impl core::fmt::Display for StringRecorder {
fn fmt(&self, mut f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
if !self.display.is_empty() {
write!(&mut f, " {}", self.display)
} else {
Ok(())
}
}
}
impl core::default::Default for StringRecorder {
fn default() -> Self {
StringRecorder::new()
}
}