refactor(sdk-logs, sdk-trace)!: refactor BatchSpanProcessor and BatchLogRecordProcessor constructor signature#6817
Conversation
…LogRecordProcessor constructor signature
Note: The `BatchSpanProcessor` from sdk-trace-base is *not* being changed.
A breaking change on sdk-trace is allowed because sdk-trace hasn't been
published yet.
This changes BatchSpanProcessor and BatchLogRecordProcessor to take a
single `options` argument, and changes the name of `BufferConfig` type
to `BatchLogRecordProcessorOptions`.
Before (effectively):
```ts
// in sdk-logs
class BatchLogRecordProcessor implements LogRecordProcessor {
constructor(exporter: LogRecordExporter, config: BufferConfig) { ... }
}
// in sdk-trace
class BatchSpanProcessor implements SpanProcessor {
constructor(exporter: SpanExporter, config: BufferConfig) { ... }
}
// usage example
const processor = new BatchLogRecordProcessor(exporter, { maxQueueSize: 1000 });
const processor = new BatchSpanProcessor(exporter, { maxQueueSize: 1000 });
```
After (effectively):
```ts
class BatchLogRecordProcessor implements LogRecordProcessor {
constructor(options: BatchLogRecordProcessorOptions) { ... }
}
class BatchSpanProcessor implements SpanProcessor {
constructor(options: BatchSpanProcessorOptions) { ... }
}
// usage example
const processor = new BatchLogRecordProcessor({ exporter, maxQueueSize: 1000 });
const processor = new BatchSpanProcessor({ exporter, maxQueueSize: 1000 });
```
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6817 +/- ##
=======================================
Coverage 94.95% 94.95%
=======================================
Files 382 383 +1
Lines 12912 12968 +56
Branches 2945 2961 +16
=======================================
+ Hits 12260 12314 +54
- Misses 652 654 +2
🚀 New features to boost your workflow:
|
exporter-logs-otlp-http has some examples that need updating as well 😄 |
pichlermarc
left a comment
There was a problem hiding this comment.
The interface change could also have been the following. I.e. just change the name of
BufferConfig.class BatchSpanProcessor implements SpanProcessor { constructor(exporter: SpanExporter, options?: BatchSpanProcessorOptions) { ... } }This would have been a smaller change. Also, user code would have have to change how arguments were passed. Thoughts? Preferences?
There aren't many examples of SDK classes that take required arguments and optional arguments to have a clear patterns on which constructor style should be preferred for consistency.
IMO your proposal is the way to go. I've had interactions with users that were confused why the PeriodicExportingMetricReader and the BatchSpanProcesssor have different ways of setting the exporter. Aligning them like this is a welcome change.
Change looks good % the things Jared and Jackson have already mentioned :)
Co-authored-by: Jared Freeze <overbalance@users.noreply.github.com>
Co-authored-by: Jared Freeze <overbalance@users.noreply.github.com>
Co-authored-by: Jared Freeze <overbalance@users.noreply.github.com>
Co-authored-by: Jared Freeze <overbalance@users.noreply.github.com>
…ll signature (from review feedback)
|
[Jared]
[Jackson]
Thanks. commit 31b2203 |
- bump the otel production deps 0.219 -> 0.220. BufferConfig type renamed to BatchLogRecordProcessorOptions. - @opentelemetry/sdk-logs 0.220.0 changed SimpleLogRecordProcessor and BatchLogRecordProcessor to a single options object (breaking change open-telemetry/opentelemetry-js#6817).
Note: The
BatchSpanProcessorfrom sdk-trace-base is not being changed.A breaking change on sdk-trace is allowed because sdk-trace hasn't been published yet.
This changes BatchSpanProcessor and BatchLogRecordProcessor to take a single
optionsargument, and changes the name ofBufferConfigtype toBatchLogRecordProcessorOptions.Before (effectively):
After (effectively):
A note on two BatchSpanProcessor classes
With this change the two
BatchSpanProcessorclasses (one in sdk-trace, one in sdk-trace-base) have slightly different call signatures. That will potentially be confusing to users for a while.The plan (as discussed in the description of #6775) is to:
sdk-trace-*packages in favour ofsdk-trace. I'll add a@deprecatedtoBatchSpanProcessorin sdk-trace-base at that point.Motivation
The change away from
interface BufferConfigwas motivated by confusion on this PR: #6504 (comment)That PR needed to add a
meterProvideroption to a BatchSpanProcessor -- on which self-observability SDK metrics can be added. AddingmeterProviderto a type calledBufferConfigfeels wrong, even though it belongs on the type that holds all the options for a BatchSpanProcessor.Two arguments or one to the constructor?
The interface change could also have been the following. I.e. just change the name of
BufferConfig.This would have been a smaller change. Also, user code would have have to change how arguments were passed.
Thoughts? Preferences?
There aren't many examples of SDK classes that take required arguments and optional arguments to have a clear patterns on which constructor style should be preferred for consistency.