Skip to main content

traceloggingdynamic

The traceloggingdynamic module provides support for generating TraceLogging-encoded ETW (Event Tracing for Windows) events directly from Python (no C/C++ code). The events can be generated and collected on Windows Vista or later. The events can be decoded on Windows 10 or later.

This is a middle-layer API:

  • Directly exposes ETW concepts rather than wrapping them in Python idioms.
  • Makes it possible for the caller to be efficient even when that means the caller might need to do more work (e.g. take names as bytes so that the caller has the option of avoiding the string encoding for each event).
  • Could be used directly by a consumer or could be wrapped in a higher-level module to create a more Python-friendly API.

Public

  • Provider class: represents an ETW data source with a name and id. Core methods: provider.is_enabled(event_level, event_keyword), provider.write(event_builder).
  • EventBuilder class: Used to put together the data for an event. Core methods: eb.reset(event_name, event_level, event_keyword, [more...]), eb.add_FIELDTYPE(field_name, field_value, [out_type, tag]). When the event is ready, send it to ETW with provider.write(eb).
  • OutType enum: Formatting hints that can be added to a field.
  • providerid_from_name function: Hashes a provider name string to generate a provider id UUID. Hash is generated using the same algorithm as other ETW APIs and tools such as .NET EventSource and WinRT LoggingChannel.

Example

# At start of program:
provider = Provider(b'MyCompany.MyGroup.MyComponent')

# When you want to generate an event:
my_field_value = True
my_event_level = 5      # 5 = Verbose
my_event_keyword = 0x21 # User-defined bits indicating categories.
if provider.is_enabled(my_event_level, my_event_keyword): # Anybody listening?
    eb = EventBuilder()
    eb.reset(b'MyEventName', my_event_level, my_event_keyword)
    eb.add_bool32(b'MyFieldName', my_field_value) # as needed to add fields.
    provider.write(eb)

Notes

Collect the events using Windows SDK tools like traceview or tracelog. Decode the events using Windows SDK tools like traceview or tracefmt. For example, for Provider(b'MyCompany.MyComponent'):

tracelog -start MyTrace -f MyTraceFile.etl -guid *MyCompany.MyComponent -level 5 -matchanykw 0xf
<run your Python program>
tracelog -stop MyTrace
tracefmt -o MyTraceData.txt MyTraceFile.etl

ETW events are limited in size (event size = headers + metadata + data). Windows will drop any event that is larger than 64KB and will drop any event that is larger than the buffer size of the recording session. To help prevent unexpected event loss, this module will raise an exception if the metadata exceeds 32KB or if the data exceeds 64KB. To help track down event loss, this module will assert if it detects that ETW dropped an event due to size.

Most ETW decoding tools are unable to decode an event with more than 128 fields. This module will raise an exception if you add more than 128 fields to an event. Note that sequence fields and binary fields each count as 2 fields.

Metadata

Release files for traceloggingdynamic 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for traceloggingdynamic 1.0.1
File Size Uploaded
traceloggingdynamic-1.0.1.tar.gz 19.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for traceloggingdynamic 1.0.1
File Interpreter ABI Platform
traceloggingdynamic-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 38.8 kB

Release files / traceloggingdynamic-1.0.1.tar.gz

Download URL traceloggingdynamic-1.0.1.tar.gz
Size 19.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d9dd4b291dd04c15e34181eed06f73fdf4ffa7b1f895b78217163def48ab1a52
BLAKE2b-256 checksum
How to use checksums
ea1f945c3e9a033b454bc845ca0cbd091b0e4d7e9860e0a943274deba16481e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.1

Release files / traceloggingdynamic-1.0.1-py3-none-any.whl

Download URL traceloggingdynamic-1.0.1-py3-none-any.whl
Size 19.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0e19da491a8960725b3622366487ae35f49d8f595bb2e4e5ce1795eb5928db7c
BLAKE2b-256 checksum
How to use checksums
c7472cdb5806cf8c97da20437f0b1c8b3cbd779b35a354a8c4da18f406c3ecd8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.1

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page