| 1 |
# General Information |
| 2 |
|
| 3 |
Processors are used at various stages of a pipeline. Generally, a processor |
| 4 |
pre-processes data before it is exported (e.g. modify attributes or sample). |
| 5 |
|
| 6 |
Some important aspects of pipelines and processors to be aware of: |
| 7 |
- [Recommended Processors](#recommended-processors) |
| 8 |
- [Data Ownership](#data-ownership) |
| 9 |
- [Exclusive Ownership](#exclusive-ownership) |
| 10 |
- [Shared Ownership](#shared-ownership) |
| 11 |
- [Ordering Processors](#ordering-processors) |
| 12 |
- [Creating Custom Processor](#creating-custom-processors) |
| 13 |
|
| 14 |
Supported processors (sorted alphabetically): |
| 15 |
- [Batch Processor](batchprocessor/README.md) |
| 16 |
- [Memory Limiter Processor](memorylimiterprocessor/README.md) |
| 17 |
|
| 18 |
The [contrib repository](https://github.com/open-telemetry/opentelemetry-collector-contrib) |
| 19 |
has more processors that can be added to a custom build of the Collector. |
| 20 |
|
| 21 |
## Recommended Processors |
| 22 |
|
| 23 |
By default, no processors are enabled. Depending on the data source, it may be |
| 24 |
recommended that multiple processors be enabled. Processors must be enabled |
| 25 |
for every data source and not all processors support all data sources. |
| 26 |
In addition, it is important to note that the order of processors matters. The |
| 27 |
order in each section below is the best practice. Refer to the individual |
| 28 |
processor documentation for more information. |
| 29 |
|
| 30 |
1. [memory_limiter](memorylimiterprocessor/README.md) |
| 31 |
2. Any sampling or initial filtering processors |
| 32 |
3. Any processor relying on sending source from `Context` (e.g. `k8sattributes`) |
| 33 |
3. [batch](batchprocessor/README.md), although prefer using the exporter's batching capabilities |
| 34 |
4. Any other processors |
| 35 |
|
| 36 |
## Data Ownership |
| 37 |
|
| 38 |
The ownership of the `pdata.Traces`, `pdata.Metrics` and `pdata.Logs` data in a pipeline |
| 39 |
is passed as the data travels through the pipeline. The data is created by the receiver |
| 40 |
and then the ownership is passed to the first processor when `ConsumeTraces`/`ConsumeMetrics`/`ConsumeLogs` |
| 41 |
function is called. |
| 42 |
|
| 43 |
Note: the receiver may be attached to multiple pipelines, in which case the same data |
| 44 |
will be passed to all attached pipelines via a data fan-out connector. |
| 45 |
|
| 46 |
From data ownership perspective pipelines can work in 2 modes: |
| 47 |
* Exclusive data ownership |
| 48 |
* Shared data ownership |
| 49 |
|
| 50 |
The mode is defined during startup based on data modification intent reported by the |
| 51 |
processors. The intent is reported by each processor via `MutatesData` field of |
| 52 |
the struct returned by `Capabilities` function. If any processor in the pipeline |
| 53 |
declares an intent to modify the data then that pipeline will work in exclusive ownership |
| 54 |
mode. In addition, any other pipeline that receives data from a receiver that is attached |
| 55 |
to a pipeline with exclusive ownership mode will be also operating in exclusive ownership |
| 56 |
mode. |
| 57 |
|
| 58 |
### Exclusive Ownership |
| 59 |
|
| 60 |
In exclusive ownership mode the data is owned exclusively by a particular processor at a |
| 61 |
given moment of time, and the processor is free to modify the data it owns. |
| 62 |
|
| 63 |
Exclusive ownership mode is only applicable for pipelines that receive data from the |
| 64 |
same receiver. If a pipeline is marked to be in exclusive ownership mode then any data |
| 65 |
received from a shared receiver will be cloned at the fan-out connector before passing |
| 66 |
further to each pipeline. This ensures that each pipeline has its own exclusive copy of |
| 67 |
data, and the data can be safely modified in the pipeline. |
| 68 |
|
| 69 |
The exclusive ownership of data allows processors to freely modify the data while |
| 70 |
they own it (e.g. see `attributesprocessor`). The duration of ownership of the data |
| 71 |
by processor is from the beginning of `ConsumeTraces`/`ConsumeMetrics`/`ConsumeLogs` |
| 72 |
call until the processor calls the next processor's `ConsumeTraces`/`ConsumeMetrics`/`ConsumeLogs` |
| 73 |
function, which passes the ownership to the next processor. After that the processor |
| 74 |
must no longer read or write the data since it may be concurrently modified by the |
| 75 |
new owner. |
| 76 |
|
| 77 |
Exclusive Ownership mode allows to easily implement processors that need to modify |
| 78 |
the data by simply declaring such intent. |
| 79 |
|
| 80 |
### Shared Ownership |
| 81 |
|
| 82 |
In shared ownership mode no particular processor owns the data and no processor is |
| 83 |
allowed the modify the shared data. |
| 84 |
|
| 85 |
In this mode no cloning is performed at the fan-out connector of receivers that |
| 86 |
are attached to multiple pipelines. In this case all such pipelines will see |
| 87 |
the same single shared copy of the data. Processors in pipelines operating in shared |
| 88 |
ownership mode are prohibited from modifying the original data that they receive |
| 89 |
via `ConsumeTraces`/`ConsumeMetrics`/`ConsumeLogs` call. Processors may only read |
| 90 |
the data but must not modify the data. |
| 91 |
|
| 92 |
If the processor needs to modify the data while performing the processing but |
| 93 |
does not want to incur the cost of data cloning that Exclusive mode brings then |
| 94 |
the processor can declare that it does not modify the data and use any |
| 95 |
different technique that ensures original data is not modified. For example, |
| 96 |
the processor can implement copy-on-write approach for individual sub-parts of |
| 97 |
`pdata.Traces`/`pdata.Metrics`/`pdata.Logs` argument. Any approach that does not |
| 98 |
mutate the original `pdata.Traces`/`pdata.Metrics`/`pdata.Logs` is allowed. |
| 99 |
|
| 100 |
If the processor uses such technique it should declare that it does not intend |
| 101 |
to modify the original data by setting `MutatesData=false` in its capabilities |
| 102 |
to avoid marking the pipeline for Exclusive ownership and to avoid the cost of |
| 103 |
data cloning described in Exclusive Ownership section. |
| 104 |
|
| 105 |
## Ordering Processors |
| 106 |
|
| 107 |
The order processors are specified in a pipeline is important as this is the |
| 108 |
order in which each processor is applied. |
| 109 |
|
| 110 |
## Creating Custom Processors |
| 111 |
|
| 112 |
To create a custom processor for the OpenTelemetry Collector, you need to implement the processor interface, define the processor's configuration, and register it with the Collector. The process typically involves creating a factory, implementing the required processing logic, and handling configuration options. For a practical example and guidance, refer to the [`processorhelper`](https://pkg.go.dev/go.opentelemetry.io/collector/processor/processorhelper) package, which provides utilities and patterns to simplify processor development. |
| 113 |
|