Skip to content

Commit 2d66344

Browse files
committed
Associate a tracing subscriber with each OlmMachine
... and use it for all subsequent calls on that machine
1 parent cb3f5ec commit 2d66344

File tree

4 files changed

+132
-16
lines changed

4 files changed

+132
-16
lines changed

index.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ export declare function initAsync(url?: URL | string): Promise<void>;
5151
// The auto-generated typescript definitions are a good start, but could do with tightening up in a lot of areas.
5252
// The following is a manually-curated set of typescript definitions.
5353
declare module "./pkg/matrix_sdk_crypto_wasm.js" {
54+
interface JsLogger {
55+
debug(data: any): void;
56+
info(data: any): void;
57+
warn(data: any): void;
58+
error(data: any): void;
59+
}
60+
5461
/** The types returned by {@link OlmMachine.outgoingRequests}. */
5562
type OutgoingRequest =
5663
| KeysUploadRequest

src/future.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::future::Future;
22

33
use js_sys::Promise;
4+
use tracing::instrument::WithSubscriber;
45
use wasm_bindgen::{JsError, JsValue, UnwrapThrowExt};
56
use wasm_bindgen_futures::spawn_local;
67

@@ -9,6 +10,10 @@ use wasm_bindgen_futures::spawn_local;
910
* Javascript [`Promise`] which either resolves with an object of type `T`,
1011
* or rejects with an error of type [`Error`].
1112
*
13+
* Also applies [`WithSubscriber::with_current_subscriber`] to the future,
14+
* to ensure that the active tracing subscriber remains active while the
15+
* future is polled.
16+
*
1217
* [`Error`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error
1318
*/
1419
pub(crate) fn future_to_promise<F, T>(future: F) -> Promise
@@ -23,14 +28,18 @@ where
2328
* Convert a Rust [`Future`] which returns [`Result<T, E>`] into a
2429
* Javascript [`Promise`] which either resolves with an object of type `T`,
2530
* or rejects with an error of type `E`.
31+
*
32+
* Also applies [`WithSubscriber::with_current_subscriber`] to the future,
33+
* to ensure that the active tracing subscriber remains active while the
34+
* future is polled.
2635
*/
2736
pub(crate) fn future_to_promise_with_custom_error<F, T, E>(future: F) -> Promise
2837
where
2938
F: Future<Output = Result<T, E>> + 'static,
3039
T: Into<JsValue>,
3140
E: Into<JsValue>,
3241
{
33-
let mut future = Some(future);
42+
let mut future = Some(future.with_current_subscriber());
3443

3544
Promise::new(&mut |resolve, reject| {
3645
let future = future.take().unwrap_throw();

0 commit comments

Comments
 (0)