Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ffi): move tracing setup from the final client to the ffi layer #4492

Merged
merged 5 commits into from
Jan 9, 2025

Conversation

stefanceriu
Copy link
Member

Having the final clients define the tracing filters / log levels proved to be tricky to keep in check resulting missing logs (e.g. recently introduced modules like the event cache) or unexpected behaviors (e.g. missing panics because we don't set a global filter). As such we decided to move the tracing setup and default definitions over to the rust side and let rust developers have full control over them.

We will now take a general log level and the final client's target name and apply them on top of the rust side defined default. Targets that log more than the requested by default will remain unchanged while the others will increase their log levels to match. Certain targets like hyper will be ignored in this step as they're too verbose.

@stefanceriu stefanceriu requested a review from a team as a code owner January 9, 2025 11:19
@stefanceriu stefanceriu requested review from Hywan and removed request for a team January 9, 2025 11:19
@@ -245,12 +231,65 @@ pub struct TracingFileConfiguration {
max_files: Option<u64>,
}

#[derive(PartialEq, PartialOrd)]
enum LogTarget {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think EXA has more target than that https://github.com/element-hq/element-x-android/blob/65ce91a8fbe287564bbdaa969ce9b925edacdb6c/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/tracing/TracingFilterConfiguration.kt#L48-L66

Would be nice to have a CustomTarget(rawString)? that would allow to add a new target wihtout having to compile a custom sdk when developping?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think EXA has more target than that

Seems so. The missing ones are matrix_sdk_ffi::uniffi_api , matrix_sdk and matrix_sdk::send_queue. Not sure if we should include them or not to be honest ¯_(ツ)_/¯ Perhaps keep matrix_sdk on info and not add the rest?

Would be nice to have a CustomTarget(rawString)?

Thought about exposing an optional filter parameter that will just override everything but I figured it's best we keep the api simple as a first step. I'm not sure how often you'll want to debug something with custom tracing on the app side without having a custom sdk version as well, moment in which tweaking the logs becomes easy.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought about exposing an optional filter parameter that will just override everything but I figured it's best we keep the api simple as a first step. I'm not sure how often you'll want to debug something with custom tracing on the app side without having a custom sdk version as well, moment in which tweaking the logs becomes easy.

Could the TracingConfiguration include an extra_logs: Vec<(String, LogLevel)>, that would be applied as such without any checks? Having some dynamic way to set some logs is definitely a recurring need, and will pay off super quick.

Then we wouldn't need the mandatory app_target field in there, as it could be part of the extra logs. (And that gives you the possibility to use different spans if you'd like!)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, nice idea, let's do it! 💪

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so I had a play and ended up with passing in only an array of targets as opposed to (target, level) as doing the latter would force the final client to duplicate the level adjustment logic done here.

If we pass in only the targets we can keep using the same logic while offering just enough flexibility imho.

Copy link

codecov bot commented Jan 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.36%. Comparing base (df4b696) to head (36500c6).
Report is 16 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4492      +/-   ##
==========================================
- Coverage   85.38%   85.36%   -0.02%     
==========================================
  Files         284      284              
  Lines       31885    31885              
==========================================
- Hits        27225    27220       -5     
- Misses       4660     4665       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Having the final clients define the tracing filters / log levels proved to be tricky to keep in check resulting missing logs (e.g. recently introduced modules like the event cache) or unexpected behaviors (e.g. missing panics because we don't set a global filter). As such we decided to move the tracing setup and default definitions over to the rust side and let rust developers have full control over them.

We will now take a general log level and the final client's target name and apply them on top of the rust side defined default. Targets that log more than the requested by default will remain unchanged while the others will increase their log levels to match. Certain targets like `hyper` will be ignored in this step as they're too verbose.
@stefanceriu stefanceriu force-pushed the stefan/ffiTracingConfiguration branch from dcfc9d0 to 33e277f Compare January 9, 2025 11:38
stefanceriu added a commit to matrix-org/complement-crypto that referenced this pull request Jan 9, 2025
Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a bunch for doing this, you rock! My only blocking comment is about extra_logs, the rest are mostly nits.

bindings/matrix-sdk-ffi/src/platform.rs Outdated Show resolved Hide resolved
@@ -245,12 +231,65 @@ pub struct TracingFileConfiguration {
max_files: Option<u64>,
}

#[derive(PartialEq, PartialOrd)]
enum LogTarget {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought about exposing an optional filter parameter that will just override everything but I figured it's best we keep the api simple as a first step. I'm not sure how often you'll want to debug something with custom tracing on the app side without having a custom sdk version as well, moment in which tweaking the logs becomes easy.

Could the TracingConfiguration include an extra_logs: Vec<(String, LogLevel)>, that would be applied as such without any checks? Having some dynamic way to set some logs is definitely a recurring need, and will pay off super quick.

Then we wouldn't need the mandatory app_target field in there, as it could be part of the extra logs. (And that gives you the possibility to use different spans if you'd like!)

bindings/matrix-sdk-ffi/src/platform.rs Outdated Show resolved Hide resolved
LogTarget::MatrixSDKBaseSlidingSync => "matrix_sdk_base::sliding_sync",
LogTarget::MatrixSDKUITimeline => "matrix_sdk_ui::timeline",
LogTarget::MatrixSDKEventCache => "matrix_sdk::event_cache",
LogTarget::MatrixSDKEventCacheStore => "matrix_sdk_sqlite::event_cache_store",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the event cache pack, we'd need also LogTarget::MatrixSdkBaseEventCache. But I can do that as a follow-up, if you'd like :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've addedMatrixSdkBaseEventCache that defaults to Info like the others and I've also added an matrix_sdk wide one that also defaults to info but won't drop lower than that.

bindings/matrix-sdk-ffi/src/platform.rs Outdated Show resolved Hide resolved
bindings/matrix-sdk-ffi/src/platform.rs Outdated Show resolved Hide resolved
bindings/matrix-sdk-ffi/src/platform.rs Outdated Show resolved Hide resolved
stefanceriu added a commit to matrix-org/complement-crypto that referenced this pull request Jan 9, 2025
@stefanceriu stefanceriu requested a review from bnjbvr January 9, 2025 15:12
Copy link
Member

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥳

@stefanceriu stefanceriu merged commit c4bfbd0 into main Jan 9, 2025
40 checks passed
@stefanceriu stefanceriu deleted the stefan/ffiTracingConfiguration branch January 9, 2025 16:08
@poljar
Copy link
Contributor

poljar commented Jan 9, 2025

I think that this should have been merged at the same time matrix-org/complement-crypto#159 got merged, now our CI is busted 😢.

@stefanceriu
Copy link
Member Author

Bah, didn't even cross my mind 😬
Perhaps we should be more leninent on complement crypto as it's an external project.

poljar pushed a commit to matrix-org/complement-crypto that referenced this pull request Jan 10, 2025
@poljar
Copy link
Contributor

poljar commented Jan 10, 2025

Well complement-crypto was designed with this in mind and it did work out nicely in the past, I don't think we need to change this.

@stefanceriu
Copy link
Member Author

Okay then perhaps we should not try to match the branches and instead always run complement crypto on main so it blocks PRs?

@poljar
Copy link
Contributor

poljar commented Jan 10, 2025

The matching branches are here so you can develop the complement changes and double check that your changes in the SDK and in complement crypto pass the CI.

It's a chicken and egg problem, if we run always against main of complement crypto then we're never able to get the CI green in the PR. Do note, if we merge the complement crypto PR and forget to merge the SDK PR, then we also get a CI failure.

Sadly, I don't see any better way of doing this.

@stefanceriu
Copy link
Member Author

Do note, if we merge the complement crypto PR and forget to merge the SDK PR, then we also get a CI failure.

Ah right, didn't think about that. Well I guess we'll just have to do to the best with what we have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants