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

Events using &OsStr don't seem to serialize properly #4

Open
jrmuizel opened this issue May 23, 2020 · 2 comments
Open

Events using &OsStr don't seem to serialize properly #4

jrmuizel opened this issue May 23, 2020 · 2 comments

Comments

@jrmuizel
Copy link

Running

use win_etw_macros::trace_logging_provider;
use std::ffi::OsStr;

#[trace_logging_provider(guid = "89d6f527-86d0-4da1-8b4b-b050159a1d96")]
pub trait MyAppEvents {
    #[event(opcode = 1)]
    fn database_connection_created(connection_id: u64, server: &OsStr);
    #[event(opcode = 2)]
    fn database_connection_closed(connection_id: u64);
    // ...
}

fn main() {
    let events = MyAppEvents::new();
    events.database_connection_created(None, 35, OsStr::new("foer"));
    events.database_connection_closed(None, 35);

shows up as

00000022    MyAppEvents 14796   14352   1   0   05\22\2020-20:41:31:607 {"connection_id":35,"server":"fo","meta":{"provider":"MyAppEvents","event":"database_connection_created","time":"2020-05-22T20:41:31.607","cpu":1,"pid":14796,"tid":14352,"channel":11,"level":4,"opcode":1}}

in TraceView. Notice that server comes out as "fo" instead of "foer".

@rylev
Copy link

rylev commented Jun 15, 2020

I tracked this down to being caused by passing the wrong length value for a wide os string here. The comment next to the code seems to indicate that passing the number of wide chars and not the number of bytes (minus the null char) is the right thing to do, but this leads to the error reported above. When doubling this value, the correct message is displayed in TraceView.

@sivadeilra
Copy link
Owner

Thanks, I'll get this fixed.

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

No branches or pull requests

3 participants