Skip to content
Merged
Show file tree
Hide file tree
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 Sep 12, 2025
0ea5243
Merge branch 'main' into disabling-log-spans
Angith Sep 12, 2025
e48f472
fix: parsing configuration file for disabling spans
Angith Sep 15, 2025
dda37e9
Merge branch 'disabling-log-spans' of https://github.com/instana/go-s…
Angith Sep 15, 2025
deb9dd8
fix: unit tests for parsing configuration file for disabling spans
Angith Sep 15, 2025
5ee06c4
chore: added an example for disabling log spans
Angith Sep 15, 2025
8e30ace
fix: accidental removal of unit tests
Angith Sep 15, 2025
5db5d1e
Merge branch 'main' into disabling-log-spans
Angith Sep 16, 2025
2552001
fix: unrecognized categories are always enabled
Angith Sep 16, 2025
7564d6b
Merge branch 'disabling-log-spans' of https://github.com/instana/go-s…
Angith Sep 16, 2025
184a14a
Merge branch 'main' into disabling-log-spans
Angith Sep 18, 2025
f926c49
refactor: disabling log implementation with review comments
Angith Sep 23, 2025
fb054c7
refactor: disabling log implementation with review comments
Angith Sep 24, 2025
3e4e1bc
Merge branch 'main' into disabling-log-spans
Angith Sep 24, 2025
4fac229
Update span.go
Angith Sep 24, 2025
e22f9c3
Merge branch 'main' into disabling-log-spans
Angith Sep 24, 2025
67d3d89
Update options.go
Angith Sep 24, 2025
358fe59
fix: Enhance security in config file handling
Angith Sep 24, 2025
309bf88
Update options.go
Angith Sep 26, 2025
59e2742
Update options.go
Angith Sep 26, 2025
df46f82
Update tracer_options.go
Angith Sep 26, 2025
66791b1
Update docs/disabling_spans.md
Angith Sep 26, 2025
42541d7
test: added unit test for validating config file
Angith Sep 27, 2025
8a050bc
doc: update disabling_spans.md with config file size info
Angith Sep 27, 2025
43b8c45
Merge branch 'main' into disabling-log-spans
Angith Sep 29, 2025
707ca11
doc: update disabling_spans.md with usecases
Angith Sep 29, 2025
5533fc1
doc: update disabling_spans.md
Angith Sep 29, 2025
bfbee64
fix: enforced maximum size for environment varaiable
Angith Sep 29, 2025
d85caba
fix: removed support for boolean value for env INSTANA_TRACING_DISABLE
Angith Sep 29, 2025
9e0c730
doc: update disabling_spans.md
Angith Sep 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ Another interesting feature is the usage of additional packages located under [i
1. [Tracing an application running on Azure Container Apps](docs/azure_container_apps.md)
1. [Tracing Other Go Packages](docs/other_packages.md)
1. [Instrumenting Code Manually](docs/manual_instrumentation.md)
1. [Disabling Spans by Category](docs/disabling_spans.md)
1. [Generic Serverless Agent](/docs/generic_serverless_agent.md)

<!-- Links section -->
Expand Down
3 changes: 2 additions & 1 deletion agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ type agentResponse struct {
} `json:"secrets"`
ExtraHTTPHeaders []string `json:"extraHeaders"`
Tracing struct {
ExtraHTTPHeaders []string `json:"extra-http-headers"`
ExtraHTTPHeaders []string `json:"extra-http-headers"`
Disable []map[string]bool `json:"disable"`
} `json:"tracing"`
}

Expand Down
3 changes: 2 additions & 1 deletion agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ func Test_agentApplyHostSettings(t *testing.T) {
Pid: 37892,
HostID: "myhost",
Tracing: struct {
ExtraHTTPHeaders []string `json:"extra-http-headers"`
ExtraHTTPHeaders []string `json:"extra-http-headers"`
Disable []map[string]bool `json:"disable"`
}{
ExtraHTTPHeaders: []string{"my-unwanted-custom-headers"},
},
Expand Down
86 changes: 86 additions & 0 deletions docs/disabling_spans.md
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
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:
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.
9 changes: 8 additions & 1 deletion docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ IncludeProfilerFrames is whether to include profiler calls into the profile or n

**Type:** [TracerOptions](https://pkg.go.dev/github.com/instana/go-sensor#TracerOptions)

Tracer contains tracer-specific configuration used by all tracers
Tracer contains tracer-specific configuration used by all tracers. Key options include:

- **Disable**: A map of span categories to disable. Currently, only the "logging" category is supported. See [Disabling Log Spans](disabling_spans.md) for details.
- **DropAllLogs**: Turns log events on all spans into no-ops when set to true.
- **MaxLogsPerSpan**: Maximum number of log records that can be attached to a span.
- **Secrets**: A secrets matcher used to filter out sensitive data from HTTP requests, database connection strings, etc.
- **CollectableHTTPHeaders**: A list of HTTP headers to be collected from requests.

#### AgentClient

Expand Down Expand Up @@ -97,3 +103,4 @@ Go Tracer only captures log spans with severity `warn` or higher.
[Tracing SQL Driver Databases](sql.md) |
[Tracing Other Go Packages](other_packages.md) |
[Instrumenting Code Manually](manual_instrumentation.md)

149 changes: 149 additions & 0 deletions example/disable-log-spans/README.md
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
3 changes: 3 additions & 0 deletions example/disable-log-spans/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tracing:
disable:
- logging: true
28 changes: 28 additions & 0 deletions example/disable-log-spans/go.mod
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
)
44 changes: 44 additions & 0 deletions example/disable-log-spans/go.sum
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=
Loading
Loading