-
Notifications
You must be signed in to change notification settings - Fork 36
feat: Ability to disable log collection at the tracer level #1254
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
Merged
Merged
Changes from 18 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
a266a71
feat: added option to disable logging spans via configuration
Angith 0ea5243
Merge branch 'main' into disabling-log-spans
Angith e48f472
fix: parsing configuration file for disabling spans
Angith dda37e9
Merge branch 'disabling-log-spans' of https://github.com/instana/go-s…
Angith deb9dd8
fix: unit tests for parsing configuration file for disabling spans
Angith 5ee06c4
chore: added an example for disabling log spans
Angith 8e30ace
fix: accidental removal of unit tests
Angith 5db5d1e
Merge branch 'main' into disabling-log-spans
Angith 2552001
fix: unrecognized categories are always enabled
Angith 7564d6b
Merge branch 'disabling-log-spans' of https://github.com/instana/go-s…
Angith 184a14a
Merge branch 'main' into disabling-log-spans
Angith f926c49
refactor: disabling log implementation with review comments
Angith fb054c7
refactor: disabling log implementation with review comments
Angith 3e4e1bc
Merge branch 'main' into disabling-log-spans
Angith 4fac229
Update span.go
Angith e22f9c3
Merge branch 'main' into disabling-log-spans
Angith 67d3d89
Update options.go
Angith 358fe59
fix: Enhance security in config file handling
Angith 309bf88
Update options.go
Angith 59e2742
Update options.go
Angith df46f82
Update tracer_options.go
Angith 66791b1
Update docs/disabling_spans.md
Angith 42541d7
test: added unit test for validating config file
Angith 8a050bc
doc: update disabling_spans.md with config file size info
Angith 43b8c45
Merge branch 'main' into disabling-log-spans
Angith 707ca11
doc: update disabling_spans.md with usecases
Angith 5533fc1
doc: update disabling_spans.md
Angith bfbee64
fix: enforced maximum size for environment varaiable
Angith d85caba
fix: removed support for boolean value for env INSTANA_TRACING_DISABLE
Angith 9e0c730
doc: update disabling_spans.md
Angith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Disabling Log Spans | ||
|
||
The Instana Go Tracer allows you to disable log spans to reduce the amount of data being collected and processed. This can be useful in high-volume environments or when you want to focus on specific types of traces. | ||
|
||
## Supported Span Categories | ||
|
||
Currently, only the following span category can be disabled: | ||
|
||
| Category | Description | Affected Instrumentations | | ||
| --------- | ----------- | ------------------------- | | ||
| `logging` | Log spans | `logrus` | | ||
|
||
## Configuration Methods | ||
|
||
There are four ways to disable log spans: | ||
|
||
### 1. Using Code | ||
|
||
You can disable log spans when initializing the tracer: | ||
|
||
```go | ||
col := instana.InitCollector(&instana.Options{ | ||
Service: "My Service", | ||
Tracer: instana.TracerOptions{ | ||
DisableSpans: map[string]bool{ | ||
"logging": true, // Disable log spans | ||
}, | ||
}, | ||
}) | ||
``` | ||
|
||
### 2. Using Environment Variables | ||
|
||
You can disable log spans using the `INSTANA_TRACING_DISABLE` environment variable: | ||
|
||
```bash | ||
# Disable log spans | ||
export INSTANA_TRACING_DISABLE="logging" | ||
|
||
# Disable all tracing | ||
Angith marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
export INSTANA_TRACING_DISABLE=true | ||
``` | ||
|
||
### 3. Using Configuration File | ||
|
||
You can create a YAML configuration file and specify its path using the `INSTANA_CONFIG_PATH` environment variable: | ||
|
||
```yaml | ||
# config.yaml | ||
tracing: | ||
disable: | ||
- logging | ||
``` | ||
```bash | ||
export INSTANA_CONFIG_PATH=/path/to/config.yaml | ||
``` | ||
|
||
### 4. Using Instana Agent Configuration | ||
|
||
You can configure the Instana agent to disable log spans for all applications monitored by this agent: | ||
|
||
1. Locate your Instana agent configuration file. | ||
2. Add the following configuration to the agent's configuration file: | ||
```yaml | ||
com.instana.tracing: | ||
disable: | ||
- logging | ||
``` | ||
3. Restart the Instana agent: | ||
## Priority Order | ||
When multiple configuration methods are used, they are applied in the following order of precedence: | ||
Angith marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
1. Configuration file (`INSTANA_CONFIG_PATH`) | ||
2. Environment variable (`INSTANA_TRACING_DISABLE`) | ||
3. Code-level configuration | ||
4. Agent configuration | ||
|
||
## Use Cases | ||
|
||
- **Performance Optimization**: In high-throughput applications, disabling log spans can reduce the overhead of tracing. | ||
- **Cost Management**: Reduce the volume of trace data sent to Instana to manage costs. | ||
- **Focus on Specific Areas**: Disable log spans to focus on the parts of your application that need attention. | ||
- **Testing**: Temporarily disable log spans during testing or development. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
# Disabling Log Spans Example | ||
|
||
This example demonstrates how to disable log spans in an Instana-instrumented Go application using four different methods: | ||
1. Using Code | ||
2. Using Environment Variables | ||
3. Using Configuration File | ||
4. Using Instana Agent Configuration | ||
|
||
The application uses logrus for logging and GORM with SQLite for database operations. It creates a simple HTTP server with two endpoints: | ||
- `/start` - Creates a database table and inserts a record | ||
- `/error` - Deliberately causes a database error | ||
|
||
Both endpoints generate log entries that would normally create log spans in Instana. | ||
|
||
## Prerequisites | ||
|
||
- Go 1.23 or later | ||
- The Instana Agent should either be running locally or accessible via the network. If no agent is available, a serverless endpoint must be configured. | ||
|
||
## Setup | ||
|
||
1. Clone the repository: | ||
```bash | ||
git clone https://github.com/instana/go-sensor.git | ||
cd go-sensor/example/disable-log-spans | ||
``` | ||
|
||
2. Install dependencies: | ||
```bash | ||
go mod tidy | ||
``` | ||
|
||
## Running the Example | ||
|
||
### Scenario 1: Disable Log Spans Using Code | ||
|
||
In this scenario, we'll disable log spans directly in the code by modifying the Instana tracer options. | ||
|
||
1. Edit `main.go` and update the `init()` function to include the `Disable` option: | ||
|
||
```go | ||
func init() { | ||
c = instana.InitCollector(&instana.Options{ | ||
Service: "logrus-example", | ||
Tracer: instana.TracerOptions{ | ||
DisableSpans: map[string]bool{ | ||
"logging": true, | ||
}, | ||
}, | ||
}) | ||
connectDB() | ||
} | ||
``` | ||
|
||
2. Run the application: | ||
```bash | ||
go run main.go | ||
``` | ||
|
||
3. Expected output: | ||
- The application will start and make requests to both endpoints | ||
- You'll see log messages in the console | ||
- In the Instana UI, you'll see HTTP and database spans, but no log spans | ||
|
||
### Scenario 2: Disable Log Spans Using Environment Variables | ||
|
||
In this scenario, we'll disable log spans using the `INSTANA_TRACING_DISABLE` environment variable. | ||
|
||
1. Revert any changes made to `main.go` for Scenario 1. | ||
|
||
2. Run the application with the environment variable: | ||
```bash | ||
INSTANA_TRACING_DISABLE=logging go run main.go | ||
``` | ||
|
||
3. Expected output: | ||
- The application will start and make requests to both endpoints | ||
- You'll see log messages in the console | ||
- In the Instana UI, you'll see HTTP and database spans, but no log spans | ||
|
||
### Scenario 3: Disable Log Spans Using Configuration File | ||
|
||
In this scenario, we'll disable log spans using a YAML configuration file. | ||
|
||
1. Ensure the `config.yaml` file contains: | ||
```yaml | ||
tracing: | ||
disable: | ||
- logging: true | ||
``` | ||
|
||
2. Run the application with the configuration file path: | ||
```bash | ||
INSTANA_CONFIG_PATH=./config.yaml go run main.go | ||
``` | ||
|
||
3. Expected output: | ||
- The application will start and make requests to both endpoints | ||
- You'll see log messages in the console | ||
- In the Instana UI, you'll see HTTP and database spans, but no log spans | ||
|
||
### Scenario 4: Disable Log Spans Using Instana Agent Configuration | ||
|
||
In this scenario, we'll configure the Instana agent to disable log spans for all applications monitored by this agent. | ||
|
||
1. Locate your Instana agent configuration file: | ||
|
||
2. Add the following configuration to the agent's configuration file: | ||
```yaml | ||
com.instana.tracing: | ||
disable: | ||
- logging: true | ||
``` | ||
3. Restart the Instana agent. | ||
|
||
4. Run the application without any special configuration: | ||
```bash | ||
go run main.go | ||
``` | ||
|
||
1. Expected output: | ||
- The application will start and make requests to both endpoints | ||
- You'll see log messages in the console | ||
- In the Instana UI, you'll see HTTP and database spans, but no log spans | ||
- All applications monitored by this agent will have log spans disabled | ||
|
||
## Verifying Results | ||
|
||
To verify that log spans are being disabled: | ||
|
||
1. Run the application without disabling log spans: | ||
```bash | ||
go run main.go | ||
``` | ||
|
||
2. Check the Instana UI - you should see log spans along with HTTP and database spans. | ||
|
||
3. Run the application using one of the four methods to disable log spans. | ||
|
||
4. Recheck the Instana UI - you should see HTTP and database spans, but no log spans. | ||
|
||
## Priority Order | ||
|
||
When multiple configuration methods are used, they are applied in the following order of precedence: | ||
|
||
1. Configuration file (`INSTANA_CONFIG_PATH`) | ||
2. Environment variable (`INSTANA_TRACING_DISABLE`) | ||
3. Code-level configuration | ||
4. Agent configuration |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
tracing: | ||
disable: | ||
- logging: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module github.com/instana/go-sensor/example/disable_log_spans | ||
|
||
go 1.23.0 | ||
|
||
replace github.com/instana/go-sensor => ../../../go-sensor | ||
|
||
require ( | ||
github.com/instana/go-sensor v1.70.0 | ||
github.com/instana/go-sensor/instrumentation/instagorm v1.32.0 | ||
github.com/instana/go-sensor/instrumentation/instalogrus v1.34.0 | ||
github.com/sirupsen/logrus v1.9.3 | ||
gorm.io/driver/sqlite v1.6.0 | ||
gorm.io/gorm v1.31.0 | ||
) | ||
|
||
require ( | ||
github.com/google/pprof v0.0.0-20250630185457-6e76a2b096b5 // indirect | ||
github.com/google/uuid v1.6.0 // indirect | ||
github.com/jinzhu/inflection v1.0.0 // indirect | ||
github.com/jinzhu/now v1.1.5 // indirect | ||
github.com/looplab/fsm v1.0.3 // indirect | ||
github.com/mattn/go-sqlite3 v1.14.28 // indirect | ||
github.com/opentracing/opentracing-go v1.2.0 // indirect | ||
github.com/stretchr/testify v1.10.0 // indirect | ||
golang.org/x/sys v0.34.0 // indirect | ||
golang.org/x/text v0.27.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/google/pprof v0.0.0-20250630185457-6e76a2b096b5 h1:xhMrHhTJ6zxu3gA4enFM9MLn9AY7613teCdFnlUVbSQ= | ||
github.com/google/pprof v0.0.0-20250630185457-6e76a2b096b5/go.mod h1:5hDyRhoBCxViHszMt12TnOpEI4VVi+U8Gm9iphldiMA= | ||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= | ||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||
github.com/instana/go-sensor/instrumentation/instagorm v1.32.0 h1:fjkWMVv7gAZQfQ5bq5jUNvOEGQmVw8EIExS+fYn0u0c= | ||
github.com/instana/go-sensor/instrumentation/instagorm v1.32.0/go.mod h1:b5wq180zXUeoybZx0jm8MQEvpdIuVTng3tUfQXvAAHk= | ||
github.com/instana/go-sensor/instrumentation/instalogrus v1.34.0 h1:0Q51nXZWeILrNKVcoUSP4IykuSW+DAQmsbRs2T/ad/M= | ||
github.com/instana/go-sensor/instrumentation/instalogrus v1.34.0/go.mod h1:inMNLws8h6E+kHQzelvNmPr6AClopwi9mTqXJs1TOA8= | ||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= | ||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= | ||
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= | ||
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= | ||
github.com/looplab/fsm v1.0.3 h1:qtxBsa2onOs0qFOtkqwf5zE0uP0+Te+wlIvXctPKpcw= | ||
github.com/looplab/fsm v1.0.3/go.mod h1:PmD3fFvQEIsjMEfvZdrCDZ6y8VwKTwWNjlpEr6IKPO4= | ||
github.com/mattn/go-sqlite3 v1.14.28 h1:ThEiQrnbtumT+QMknw63Befp/ce/nUPgBPMlRFEum7A= | ||
github.com/mattn/go-sqlite3 v1.14.28/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= | ||
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= | ||
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= | ||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= | ||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= | ||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= | ||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA= | ||
golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= | ||
golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4= | ||
golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||
gorm.io/driver/sqlite v1.6.0 h1:WHRRrIiulaPiPFmDcod6prc4l2VGVWHz80KspNsxSfQ= | ||
gorm.io/driver/sqlite v1.6.0/go.mod h1:AO9V1qIQddBESngQUKWL9yoH93HIeA1X6V633rBwyT8= | ||
gorm.io/gorm v1.31.0 h1:0VlycGreVhK7RF/Bwt51Fk8v0xLiiiFdbGDPIZQ7mJY= | ||
gorm.io/gorm v1.31.0/go.mod h1:XyQVbO2k6YkOis7C2437jSit3SsDK72s7n7rsSHd+Gs= |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.