Skip to content

OpenTelemetryトレーシングの送出間隔

OpenTelemetry SDKの組み込みSpanProcessorは2つある。

ひとつのトレースが完了したとき、即時にTraceExporterへ送出する。即時なので特に設定はない。

ある程度のSpanをまとめてTraceExporterへ送出する。送出間隔の調整は以下のパラメータで行える。

  • maxExportBatchSize: Spanの数がこれに到達したとき、まとめてExporterへ送る
  • scheduledDelayMillis: 送出間隔をミリ秒で設定する; batch sizeに満たなくても送る

デフォルトではどちらが使われるのか

Section titled “デフォルトではどちらが使われるのか”

CollectorのディストリまたはSDKによって異なるのかもしれないが、corecolの場合はcmd/otelcorecol/components.goでファクトリにより設定している。ここではMetric/Log/Traceを区別していない。

factories.ProcessorModules[batchprocessor.NewFactory().Type()] = "go.opentelemetry.io/collector/processor/batchprocessor v0.110.0"

名前からもうすでに分かるけど、ではトレースの場合に何が設定されるかというとprocessor/batchprocessor/factory.goに書かれている。

func NewFactory() processor.Factory {
return processor.NewFactory(
metadata.Type,
createDefaultConfig,
processor.WithTraces(createTraces, metadata.TracesStability),
processor.WithMetrics(createMetrics, metadata.MetricsStability),
processor.WithLogs(createLogs, metadata.LogsStability))
}
func createTraces(
_ context.Context,
set processor.Settings,
cfg component.Config,
nextConsumer consumer.Traces,
) (processor.Traces, error) {
return newBatchTracesProcessor(set, nextConsumer, cfg.(*Config))
}

最終的にprocessor/batchprocessor/batch_processor.goによってBatchProcessorが設定される。

func newBatchLogsProcessor(set processor.Settings, next consumer.Logs, cfg *Config) (*batchProcessor, error) {
return newBatchProcessor(set, cfg, func() batch { return newBatchLogs(next) })
}
// batch_processor is a component that accepts spans and metrics, places them
// into batches and sends downstream.
//
// batch_processor implements consumer.Traces and consumer.Metrics
//
// Batches are sent out with any of the following conditions:
// - batch size reaches cfg.SendBatchSize
// - cfg.Timeout is elapsed since the timestamp when the previous batch was sent out.
type batchProcessor struct {...}
// 長いので省略
func newBatchProcessor(set processor.Settings, cfg *Config, batchFunc func() batch) (*batchProcessor, error)