Go Agent Exclusions
How to exclude Go packages (modules), files, or directories from the SeaLights scan and instrumentation
Use this guide to exclude packages and files from being scanned and reported as part of your Application.
When you run slgoagent scan, the agent scans your project structure and reports it to SeaLights, while also instrumenting the code in your project workspace. If you see vendor code, generated files, mocks, or other code in your scan results (on your coverage report in SeaLights) that cannot or should not be tested, you can use exclusions to prevent them from being included in the scan.
Quick Reference
The Sealights Go Agent supports two types of exclusions:
packages-excluded
Go module packages (entire packages/package trees)
• Config file: packagesExcludes field in slconfig.yaml
• CLI flag: --packages-excluded, --excludes, or --exclude
• Environment variable: SEALIGHTS_PACKAGES_EXCLUDED or SL_PACKAGES_EXCLUDED (set in build environment)
.slignore file
Specific files and directories (glob patterns)
• Create a .slignore file in your project root directory
When to Use Which
Use
packages-excludedfor: vendor dependencies, third-party modules, entire go.mod package subtreesUse
.slignorefor: specific files, generated code, mock files, test data directories, individual legacy files
Using packages-excluded (Exclude Go Packages)
packages-excluded (Exclude Go Packages)Use the packages-excluded parameter to exclude entire Go packages (Go modules) from being scanned and reported to SeaLights. This is the recommended approach for excluding vendor code, third-party modules, or entire package directories that appear in your scan results.
The typical workflow is:
Run
slgoagent configto configure the agent (to apply exclusions during the next step)Run
slgoagent scanto scan and instrument your code
Method 1: Command Line Flags
You can use any of these flag names (they all do the same thing):
--packages-excluded--excludes--exclude
Method 2: Configuration File (Recommended)
Add the packagesExcludes field to your slconfig.yaml:
Then run:
Method 3: Environment Variables
The environment variables SEALIGHTS_PACKAGES_EXCLUDED and SL_PACKAGES_EXCLUDED do the same thing. Set these in your build environment where the slgoagent commands run (e.g., in your CI pipeline configuration).
Note: When using environment variables, separate multiple packages with commas.
Using .slignore (Exclude Files or Directories)
Use a .slignore file to exclude specific files and directories from being scanned. This works like a .gitignore file and is useful when you need more granular control than package-level exclusions.
Creating a .slignore File
Create a .slignore file in your project root directory:
Pattern Syntax
The .slignore file follows the same syntax as .gitignore :
**matches any number of directories*matches any characters within a directoryLines starting with
#are commentsEmpty lines are ignored
Test File Behavior
The SeaLights Go Agent handles test files (*_test.go) like so:
Test files are NOT included in the build scan/build map by default (without adding these files to your exclusions)
Test files ARE instrumented during the
slgoagent scancommand
Unit Test coverage is automatically collected and reported to SeaLights as long as those unit test files were instrumented during the ./slgoagent scan command.
Tips
Use
./package/...syntax to exclude a package and all its sub-packages (withpackages-excludedonly)Start with minimal exclusions and add more as needed
Test your exclusions by running
slgoagent config --log-level debugandslgoagent scanto see what's being scannedUse
.slignorefor file-level or directory-level control whenpackages-excludedis too broadTo manage the
packages-excludedparameter with environment variables, these variables must be set in the build environment whereslgoagent configandslgoagent scanrun
For more information about configuration options, see the Go Agent Configuration Parameters documentation.
Last updated
Was this helpful?

