-
Notifications
You must be signed in to change notification settings - Fork 1.4k
sdk/log: self observability: batch log processor metrics #7124
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
base: main
Are you sure you want to change the base?
Changes from 32 commits
93e2fec
9de991b
8d1edbf
ec0b55e
385fd9f
5c405d7
1366caa
b2dd092
4f24dff
c4bf81a
4cbaff1
9d42e5c
3a35f8e
96de62a
001ddb6
9371ede
f3a214a
a931308
df7b8f0
7c2fd2b
7238dd4
3f2c046
a3d80da
bff6fee
5d57d29
a12f99f
d7fcefa
055f5ec
eebda4b
84e81c4
68025cc
c82c8db
81872b0
52a7300
170e336
b41cc36
b9034e2
8394a13
5aa07b5
5916770
f3d3c1f
43fc59e
d16b9c7
590b9f9
b3019d5
c7e2ffb
a917056
571c270
f3ed952
96bfdcb
75df171
d197e14
27c8cd5
d3df34a
c50a25b
0906ae3
75f09bc
2c4c652
a6ec144
53e164d
2d1f19b
7b738ba
79027a8
2f662ce
feafe4d
d9d3c8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,10 @@ import ( | |
| "sync/atomic" | ||
| "time" | ||
|
|
||
| "go.opentelemetry.io/otel" | ||
| "go.opentelemetry.io/otel/internal/global" | ||
| "go.opentelemetry.io/otel/sdk/log/internal/counter" | ||
| "go.opentelemetry.io/otel/sdk/log/internal/observ" | ||
| ) | ||
|
|
||
| const ( | ||
|
|
@@ -98,6 +101,9 @@ type BatchProcessor struct { | |
| // stopped holds the stopped state of the BatchProcessor. | ||
| stopped atomic.Bool | ||
|
|
||
| // inst is the instrumentation for observability (nil when disabled). | ||
| inst *observ.BLP | ||
|
|
||
| noCmp [0]func() //nolint: unused // This is indeed used. | ||
| } | ||
|
|
||
|
|
@@ -111,6 +117,31 @@ func NewBatchProcessor(exporter Exporter, opts ...BatchProcessorOption) *BatchPr | |
| // Do not panic on nil export. | ||
| exporter = defaultNoopExporter | ||
| } | ||
|
|
||
| b := &BatchProcessor{ | ||
| q: newQueue(cfg.maxQSize.Value), | ||
| batchSize: cfg.expMaxBatchSize.Value, | ||
| pollTrigger: make(chan struct{}, 1), | ||
| pollKill: make(chan struct{}), | ||
| } | ||
|
|
||
| var err error | ||
| b.inst, err = observ.NewBLP( | ||
| counter.NextExporterID(), | ||
| func() int64 { return int64(b.q.Len()) }, | ||
| int64(cfg.maxQSize.Value), | ||
| ) | ||
|
MrAlias marked this conversation as resolved.
|
||
| if err != nil { | ||
| otel.Handle(err) | ||
| } | ||
|
|
||
| // Wrap exporter with metrics recording if observability is enabled. | ||
| // This must be the innermost wrapper (closest to user exporter) to record | ||
| // metrics just before calling the actual exporter. | ||
| if b.inst != nil { | ||
| exporter = newMetricsExporter(exporter, b.inst) | ||
| } | ||
|
MrAlias marked this conversation as resolved.
|
||
|
|
||
| // Order is important here. Wrap the timeoutExporter with the chunkExporter | ||
| // to ensure each export completes in timeout (instead of all chunked | ||
| // exports). | ||
|
|
@@ -119,15 +150,9 @@ func NewBatchProcessor(exporter Exporter, opts ...BatchProcessorOption) *BatchPr | |
| // appropriately on export. | ||
| exporter = newChunkExporter(exporter, cfg.expMaxBatchSize.Value) | ||
|
|
||
| b := &BatchProcessor{ | ||
| exporter: newBufferExporter(exporter, cfg.expBufferSize.Value), | ||
|
|
||
| q: newQueue(cfg.maxQSize.Value), | ||
| batchSize: cfg.expMaxBatchSize.Value, | ||
| pollTrigger: make(chan struct{}, 1), | ||
| pollKill: make(chan struct{}), | ||
| } | ||
| b.exporter = newBufferExporter(exporter, cfg.expBufferSize.Value) | ||
| b.pollDone = b.poll(cfg.expInterval.Value) | ||
|
|
||
| return b | ||
| } | ||
|
|
||
|
|
@@ -143,6 +168,8 @@ func (b *BatchProcessor) poll(interval time.Duration) (done chan struct{}) { | |
| defer close(done) | ||
| defer ticker.Stop() | ||
|
|
||
| ctx := context.Background() | ||
|
|
||
| for { | ||
| select { | ||
| case <-ticker.C: | ||
|
|
@@ -153,6 +180,9 @@ func (b *BatchProcessor) poll(interval time.Duration) (done chan struct{}) { | |
| } | ||
|
|
||
| if d := b.q.Dropped(); d > 0 { | ||
| if b.inst != nil { | ||
| b.inst.ProcessedQueueFull(ctx, int64(d)) //nolint: gosec | ||
| } | ||
|
pellared marked this conversation as resolved.
|
||
| global.Warn("dropped log records", "dropped", d) | ||
| } | ||
|
Comment on lines
183
to
188
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clamped to math.MaxInt64 I still had to keep |
||
|
|
||
|
|
@@ -225,6 +255,9 @@ func (b *BatchProcessor) Shutdown(ctx context.Context) error { | |
|
|
||
| // Flush remaining queued before exporter shutdown. | ||
| err := b.exporter.Export(ctx, b.q.Flush()) | ||
| if b.inst != nil { | ||
| err = errors.Join(err, b.inst.Shutdown()) | ||
|
MrAlias marked this conversation as resolved.
|
||
| } | ||
| return errors.Join(err, b.exporter.Shutdown(ctx)) | ||
|
Comment on lines
262
to
266
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. b.inst.Shutdown() added for ctx.Done() early return path |
||
| } | ||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.