pub struct Provider { /* private fields */ }
Expand description

A connection to ETW for writing TraceLogging (manifest-free) events.

Overview

  1. Use define_provider! to create a static provider variable.
  2. Call Provider::register() during component initialization to open the connection to ETW.
  3. Use write_event! as needed to write events.
  4. Call Provider::unregister() during component cleanup to close the connection to ETW.

Implementations

Returns the current thread’s thread-local activity id. (Calls EventActivityIdControl with control code EVENT_ACTIVITY_CTRL_GET_ID.)

The thread-local activity id will be used if write_event! is called with no activity_id option.

Sets the current thread’s thread-local activity id. Returns the previous value. (Calls EventActivityIdControl with control code EVENT_ACTIVITY_CTRL_GET_SET_ID.)

The thread-local activity id will be used if write_event! is called with no activity_id option.

Important: thread-local activity id should follow scoping rules. If you set the thread-local activity id in a scope, you should restore the previous value before exiting the scope.

Generates and returns a new 128-bit value suitable for use as an activity id. (Calls EventActivityIdControl with control code EVENT_ACTIVITY_CREATE_ID.)

The returned value is not a true GUID/UUID since it is not globally-unique. The returned value is locally-unique: it is guaranteed to be different from all other values generated by create_activity_id() on the current machine in the current boot session.

Activity ids need to be unique within the trace but do not need to be globally-unique, so your activity ids can use either a real GUID/UUID or a locally-unique id generated by create_activity_id(). Use create_activity_id() for locally-unique activity ids or use [Guid::new] for globally-unique activity ids.

Returns a GUID generated from a case-insensitive hash of the specified trace provider name. The hash uses the same algorithm as many other ETW tools and APIs. Given the same name, it will always generate the same GUID. (Same as Guid::from_name.)

The result can (and usually should) be used as the provider id.

Note: Do not use guid_from_name to generate activity ids.

use tracelogging as tlg;
assert_eq!(
   tlg::Provider::guid_from_name("MyProvider"),
   tlg::Guid::from_u128(&0xb3864c38_4273_58c5_545b_8b3608343471));

Advanced: Returns this provider’s encoded metadata bytes.

Returns this provider’s name.

Returns this provider’s id (GUID).

Returns true if any ETW logging session is listening to this provider for events with the specified level and keyword.

Note: write_event! already checks enabled(). You only need to make your own call to enabled() if you want to skip something other than write_event!.

If this provider is not registered, does nothing and returns 0. Otherwise, unregisters the provider.

Returns 0 for success or a Win32 error from EventUnregister for failure. The return value is for diagnostic purposes only and should generally be ignored in retail builds.

Preconditions
  • For a given provider object, a call on one thread to the provider’s register or unregister method must not occur at the same time as a call to the provider’s register or unregister method on any other thread. Verified at runtime, failure = panic.

Register the provider.

Preconditions
  • Provider must not already be registered. Verified at runtime, failure = panic.
  • For a given provider object, a call on one thread to the provider’s register or unregister method must not occur at the same time as a call to the provider’s register or unregister method on any other thread. Verified at runtime, failure = panic.
Safety
  • If creating a DLL or creating a provider that might run as part of a DLL, all registered providers must be unregistered before the DLL unloads.

    If a provider variable is registered by a DLL and the DLL unloads while the provider is still registered, the process may subsequently crash. This occurs because register enables an ETW callback into the calling DLL and unregister ensures that the callback is disabled. If the module unloads without disabling the callback, the process will crash the next time that ETW tries to invoke the callback.

    The provider cannot unregister itself because the provider is static and Rust does not drop static objects.

    You’ll typically register the provider during DLL_PROCESS_ATTACH and unregister during DLL_PROCESS_DETACH.

Register the provider with a custom provider enable callback.

Preconditions
  • Provider must not already be registered. Verified at runtime, failure = panic.
  • For a given provider object, a call on one thread to the provider’s register or unregister method must not occur at the same time as a call to the provider’s register or unregister method on any other thread. Verified at runtime, failure = panic.
Safety
  • If creating a DLL or creating a provider that might run as part of a DLL, all registered providers must be unregistered before the DLL unloads.

    If a provider variable is registered by a DLL and the DLL unloads while the provider is still registered, the process may subsequently crash. This occurs because register enables an ETW callback into the calling DLL and unregister ensures that the callback is disabled. If the module unloads without disabling the callback, the process will crash the next time that ETW tries to invoke the callback.

    The provider cannot unregister itself because the provider is static and Rust does not drop static objects.

    You’ll typically register the provider during DLL_PROCESS_ATTACH and unregister during DLL_PROCESS_DETACH.

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.