1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-08-10 22:31:50 +02:00

Clarify DefaultMaxQueueSize and DefaultScheduleDelay usage (#6974)

### Description

OpenTelemetry uses `DefaultScheduleDelay` and `DefaultExportTimeout`
values as milliseconds but Go time package will understand them as
nanoseconds.

I understand that this is a stable library and that those value will
probably never change, so can we at least clarify their usage?

Right above the defaults declaration it says `// Defaults for
BatchSpanProcessorOptions.` which is confusing.

We used `trace.DefaultScheduleDelay` as a fallback value for our tracing
setup.
This confusion led to high CPU usage due to the frequent batch exports.

### Confusing behavior

```go
processor := trace.NewBatchSpanProcessor(exporter,
    // set timeout to 5000 ns instead of the expected 5000 ms
    trace.WithBatchTimeout(trace.DefaultScheduleDelay),
    // set timeout to 30000 ns instead of the expected 30000 ms
    trace.WithExportTimeout(trace.DefaultExportTimeout),
)
```

### Correct way to use those values

```go
processor := trace.NewBatchSpanProcessor(exporter,
    trace.WithBatchTimeout(trace.DefaultScheduleDelay * time.Millisecond),
    trace.WithExportTimeout(trace.DefaultExportTimeout * time.Millisecond),
)
```

---------

Co-authored-by: Damien Mathieu <42@dmathieu.com>
Co-authored-by: Robert Pająk <pellared@hotmail.com>
This commit is contained in:
Corentin
2025-07-09 09:18:17 +00:00
committed by GitHub
parent afd476363f
commit 86640ceae0

View File

@@ -19,7 +19,9 @@ import (
// Defaults for BatchSpanProcessorOptions. // Defaults for BatchSpanProcessorOptions.
const ( const (
DefaultMaxQueueSize = 2048 DefaultMaxQueueSize = 2048
// DefaultScheduleDelay is the delay interval between two consecutive exports, in milliseconds.
DefaultScheduleDelay = 5000 DefaultScheduleDelay = 5000
// DefaultExportTimeout is the duration after which an export is cancelled, in milliseconds.
DefaultExportTimeout = 30000 DefaultExportTimeout = 30000
DefaultMaxExportBatchSize = 512 DefaultMaxExportBatchSize = 512
) )