33 Commits
Author SHA1 Message Date
Amit fd34511314 Switch to Go 1.23 and fix CI failures
Some new upcoming changes require us to use Go 1.23. However, if we switch to Go 1.23 some
new linter errors are showing up. This commit fixes most of the errors and adds an
exclusion for integer overflow errors.

Signed-off-by: Amit <ambarve@microsoft.com>
2025-10-27 09:08:22 -07:00
Hamza El-Saawy e268c11e27 Add lint and go generate steps to CI (#254)
* Add lint and go generate stages to CI

Add CI step to verify `go generate` was run on repo.
Add linter stage to CI along with linter config file,
`.golangci.yml`.
Will likely prefer revive over static-check.

Updated README Contributing section on linting requirements.

Added sequence ordering to make sure lint and go generate stages run
before tests and build.
This way, build and tests are not run on code that could potentially:

    1. not build due to `gofmt` issues;
    2. contain bugs;
    3. have to be re-submitted after issues are fixed; or
    4. contain outdated Win32 syscall or other auto-generated files.

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>

* Fixed linter issues

Code changes to satisfy linters:

 - Ran `gofmt -s -w` on repo.
 - Broke up long lines.
 - When possible, changed names with incorrect initialism formatting
   - Added exceptions for exported variables.
 - Added exceptions for ALL_CAPS_WITH_UNDERSCORES code.
   - Switched to using `windows` or `syscall` definitions if possible;
     especially if some constants were unused.
 - Added `_ =` to satisfy error linter, and acknowledge that errors are
   being ignored.
 - Switched to using `errors.Is` and `As` in places, elsewhere added
   exceptions if error value was known to be `syscall.Errno`.
 - Removed bare returns.
 - Prevented variables from being overshadowed in certain places
   (ignoring cases of overshadowing `err`).
 - Renamed variables and functions (eg, `len`, `eventMetadata.bytes`) to
   prevent shadowing pre-built functions and imported pacakges.
 - Removed unused method receivers.
 - Added exceptions to certain unused (unexported) constants and
   functions.
   - Deleted unused `once` from `pkg/etw.providerMap`.
 - Renamed `noop.go` files to `main_other.go` or `doc.go`, to better fit
   style recommendations.
 - Added exceptions for non-secure use of SHA1 and weak crypto
   libraries.
 - Replaced `ioutil` with `io` and `os` (and `t.TempDir` in tests).
 - Added fully exhaustive checks for `switch` statements in `pkg/etw`.
 - Defined constant strings for `tools/mkwinsyscall`.
 - Removed unnecessary conversions.
 - Made sure `context.Cancel` was called.

Additionally, added `//go:build windows" constraints on files with
unexported code, since linter will complain about unused code on
non-Windows platforms.

Added a stub `main() {}` for `mkwinsyscall` for non-Windows builds, just in
case `//go:generate` directives are added to OS-agnostic files.

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>

* PR: spelling, constants, fuzzing

Moved HVSocket fuzzing tests to separate file with go 1.18 build
constraint.

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
2022-08-23 15:05:05 -04:00
Hamza El-Saawy 87532d1cfe Set ETW event name and options for logrus hook (#245)
* ETW name and options functionality

Added functionality to set the event (task) name and options (such as
event or associated event ID) for ETW events created by the hook based
on the logrus.Entry fields.

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>

* PR: export and comment

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
2022-04-27 15:00:13 -04:00
Thomas d4c02ad896 Add missing build constraints 2021-02-10 23:54:19 +00:00
Thomas Way 9d8277341f Add build guards for all Windows imports 2021-01-21 23:24:01 +00:00
Justin d2ef9cfdac Merge pull request #149 from microsoft/etw-logrus-time
etwlogrus: Pass through entry time as ETW field
2019-06-25 10:40:15 -07:00
Kevin Parsons 09baa54393 etwlogrus: Pass through entry time as ETW field
Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
2019-06-25 10:36:45 -07:00
Kevin Parsons 2ae559ad19 Replace ETW Logrus hook levels with AllLevels
Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
2019-06-25 10:32:12 -07:00
John Starks 2be8053e58 Merge pull request #138 from microsoft/etw-write-error
etwlogrus: Ignore error from ETW WriteEvent
2019-05-08 08:21:23 -07:00
John Starks 1bcf844dd4 Merge pull request #140 from microsoft/etwlogrus-tests
etwlogrus: Improve tests to actually go through logrus hook
2019-05-08 08:20:37 -07:00
Kevin Parsons afa8dc2e8d etwlogrus: Improve tests to actually go through logrus hook
Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
2019-05-08 00:01:40 -07:00
Kevin Parsons ed00d9afc1 etwlogrus: Fix event logging not including fields
Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
2019-05-07 23:51:39 -07:00
Kevin Parsons 2093f10e12 etwlogrus: Ignore error from ETW WriteEvent
Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
2019-05-07 23:41:01 -07:00
John Starks 664840fcdb pkg/etwlogrus: Ensure stable event field order
This change updates the logrus hook to sort the incoming logrus data
before passing it to the tracelogging code. This is useful because it
ensures that two instances of the same event have the fields in the same
order, which is necessary to get WPA to line the fields up.
2019-05-07 19:27:13 +00:00
Kevin Parsons 88da7d1491 Add guid package 2019-04-01 16:07:14 -07:00
Kevin Parsons a132ab2270 Move smart ETW field logging to base etw library 2019-03-22 14:16:54 -07:00
Justin 584c8d8bd8 Merge pull request #115 from kevpar/etw-logrus-pass-provider
Etw logrus pass provider
2019-03-19 11:13:27 -07:00
Justin 19a2e5edd7 Merge pull request #113 from kevpar/public-etw
Export etw package
2019-03-19 11:12:31 -07:00
Kevin Parsons 811b34668c Provide a hook constructor which accepts an ETW provider
Previously, the only constructor for the etwlogrus hook accepted a name, and
created a new ETW provider with that name. With this change, there is another
constructor which takes an already created ETW provider. This is to allow the
use of the ETW provider for other things, such as if the application wants to
support ETW capture state.
2019-03-19 00:09:35 -07:00
Kevin Parsons b246ce4803 Map Logrus level to standard ETW level
ETW and Logrus have similar, but different definitiosn of log level.
Originally, the plan was to just convert the integer value of the Logrus level
to an ETW level, and leave it at that. However, it turns out there are tools
that assume you are logging with the standard set of ETW log level. So now we
will map the Logrus level to an ETW level, so that these tools better.
2019-03-19 00:01:56 -07:00
Kevin Parsons ce5a3739bc Export etw package 2019-03-18 23:57:19 -07:00
John Howard c16103c642 Convert to UNix line endings
Signed-off-by: John Howard <jhoward@microsoft.com>
2019-02-21 09:33:18 -08:00
Kevin Parsons 6e71d2839c Add test cases for logging empty slices
Signed-off-by: Kevin Parsons <kevpar@ntdev.microsoft.com>
2019-01-11 12:22:02 -08:00
Kevin Parsons 515e920a0a Support logging more Go types to ETW
Signed-off-by: Kevin Parsons <kevpar@ntdev.microsoft.com>
2019-01-10 11:08:01 -08:00
Kevin Parsons 82fc62aed2 Return error from WriteEvent in Logrus hook 2019-01-03 16:08:24 -08:00
Kevin Parsons b87cea3696 Clean up and PR feedback 2019-01-03 13:08:23 -08:00
Kevin Parsons fac5ca0c3a Separate ETW into low-level and high-level API 2018-12-21 16:18:22 -08:00
Kevin Parsons 50cf0baa2f Support auto-generation of ETW provider ID 2018-12-20 14:05:36 -08:00
Kevin Parsons 82ad381699 Add ETW support for out type and tags 2018-12-20 01:28:55 -08:00
Kevin Parsons 824a366a22 Make etw package internal 2018-12-19 01:52:15 -08:00
Kevin Parsons dcfdf4a9f6 Improve ETW callback support and track provider enable state 2018-12-19 01:42:44 -08:00
Kevin Parsons cd4b2fefe9 Change from reflection to type switch in Logrus hook 2018-12-13 17:23:55 -08:00
Kevin Parsons 62f7a6b7b9 Rearrange etw packages 2018-12-13 14:26:45 -08:00