| 1 | // Copyright The OpenTelemetry Authors |
| 2 | // SPDX-License-Identifier: Apache-2.0 |
| 3 | |
| 4 | package request // import "go.opentelemetry.io/collector/exporter/exporterhelper/internal/request" |
| 5 | |
| 6 | import ( |
| 7 | "context" |
| 8 | |
| 9 | "go.opentelemetry.io/collector/exporter/exporterhelper/internal/sender" |
| 10 | ) |
| 11 | |
| 12 | // Request represents a single request that can be sent to an external endpoint. |
| 13 | // Experimental: This API is at the early stage of development and may change without backward compatibility |
| 14 | // until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved. |
| 15 | type Request interface { |
| 16 | // ItemsCount returns a number of basic items in the request where item is the smallest piece of data that can be |
| 17 | // sent. For example, for OTLP exporter, this value represents the number of spans, |
| 18 | // metric data points or log records. |
| 19 | ItemsCount() int |
| 20 | // MergeSplit is a function that merge and/or splits this request with another one into multiple requests based on the |
| 21 | // configured limit provided in maxSize. |
| 22 | // MergeSplit does not split if maxSize is zero. |
| 23 | // All the returned requests MUST have a number of items that does not exceed the maximum number of items. |
| 24 | // Size of the last returned request MUST be less or equal than the size of any other returned request. |
| 25 | // The original request MUST not be mutated if error is returned after mutation or if the exporter is |
| 26 | // marked as not mutable. The length of the returned slice MUST not be 0. |
| 27 | // Experimental: This API is at the early stage of development and may change without backward compatibility |
| 28 | // until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved. |
| 29 | MergeSplit(ctx context.Context, maxSize int, sizerType SizerType, req Request) ([]Request, error) |
| 30 | // BytesSize returns the size of the request in bytes. |
| 31 | BytesSize() int |
| 32 | } |
| 33 | |
| 34 | // ErrorHandler is an optional interface that can be implemented by Request to provide a way handle partial |
| 35 | // temporary failures. For example, if some items failed to process and can be retried, this interface allows to |
| 36 | // return a new Request that contains the items left to be sent. Otherwise, the original Request should be returned. |
| 37 | // If not implemented, the original Request will be returned assuming the error is applied to the whole Request. |
| 38 | // Experimental: This API is at the early stage of development and may change without backward compatibility |
| 39 | // until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved. |
| 40 | type ErrorHandler interface { |
| 41 | Request |
| 42 | // OnError returns a new Request may contain the items left to be sent if some items failed to process and can be retried. |
| 43 | // Otherwise, it should return the original Request. |
| 44 | OnError(error) Request |
| 45 | } |
| 46 | |
| 47 | type RequestConverterFunc[T any] func(context.Context, T) (Request, error) |
| 48 | |
| 49 | // RequestConsumeFunc processes the request. After the function returns, the request is no longer accessible, |
| 50 | // and accessing it is considered undefined behavior. |
| 51 | type RequestConsumeFunc = sender.SendFunc[Request] |