# OpenTelemetry envelope

The *OpenTelemetry envelope* processor transforms your data to be compatible with the OpenTelemetry log schema. If your data wasn't generated by the [OpenTelemetry input plugin](https://docs.fluentbit.io/manual/4.1/data-pipeline/inputs/opentelemetry), you can use this processor before sending that data to a destination that expects an OpenTelemetry-compatible schema.

![OpenTelemetry envelope transformation](https://913035255-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fs0q292yqb4jDBrN2Li9x%2Fuploads%2Fgit-blob-d44920a144e4d1b747ffb72630bed6c2db5bc648%2Fprocessor_opentelemetry_envelope.png?alt=media)

{% hint style="info" %}
Only [YAML configuration files](https://docs.fluentbit.io/manual/4.1/administration/configuring-fluent-bit/yaml) support processors.
{% endhint %}

## Configuration parameters

The OpenTelemetry envelope processor doesn't use configuration parameters.

## Examples

The following example uses the `dummy` input plugin to generate one sample message per second, then transforms those messages by using the `opentelemetry_envelope` processor. The resulting transformed data is sent to `stdout` and the `opentelemetry` output plugin.

{% tabs %}
{% tab title="fluent-bit.yaml" %}

```yaml
service:
  flush: 1
  log_level: info

pipeline:
  inputs:
    - name: dummy
      dummy: '{"message": "Hello World"}'

      processors:
        logs:
          - name: opentelemetry_envelope

  outputs:
    - name : stdout
      match: '*'

    - name: opentelemetry
      match: '*'
      host: 127.0.0.1
      port: 4318
```

{% endtab %}

{% tab title="otel-collector.yaml" %}

```yaml
receivers:
  otlp:
    protocols:
      http:
        endpoint: 127.0.0.1:4318

exporters:
  file:
    path: out.json
  logging:
    loglevel: info

service:
  telemetry:
    logs:
      level: debug
  pipelines:
    logs:
      receivers: [otlp]
      exporters: [file, logging]
```

{% endtab %}
{% endtabs %}

The standard output of Fluent Bit prints the raw representation of the schema. However, the OpenTelemetry collector receives the data in an OpenTelemetry-compatible format.

If you inspect the `out.json` output file, you will see OpenTelemetry-compatible data, similar to the following:

```json
{
  "resourceLogs": [
    {
      "resource": {},
      "scopeLogs": [
        {
          "scope": {},
          "logRecords": [
            {
              "timeUnixNano": "1722904188085758000",
              "body": {
                "stringValue": "dummy"
              },
              "traceId": "",
              "spanId": ""
            }
          ]
        }
      ]
    }
  ]
}
```

If you're interested in additional transformations, you can also use the [content modifier](https://docs.fluentbit.io/manual/4.1/data-pipeline/processors/content-modifier) processor to modify the content of your logs. The following example shows how to add resource and scope attributes to logs:

{% tabs %}
{% tab title="fluent-bit.yaml" %}

```yaml
service:
  flush: 1
  log_level: info

pipeline:
  inputs:
    - name: dummy
      dummy: '{"message": "Hello World"}'

      processors:
        logs:
          - name: opentelemetry_envelope

          - name: content_modifier
            context: otel_resource_attributes
            action: upsert
            key: service.name
            value: my-service

  outputs:
    - name : stdout
      match: '*'

    - name: opentelemetry
      match: '*'
      host: 127.0.0.1
      port: 4318
```

{% endtab %}
{% endtabs %}

The collector JSON output will resemble the following:

```json
{
  "resourceLogs": [
    {
      "resource": {
        "attributes": [
          {
            "key": "service.name",
            "value": {
              "stringValue": "my-service"
            }
          }
        ]
      },
      "scopeLogs": [
        {
          "scope": {},
          "logRecords": [
            {
              "timeUnixNano": "1722904465173450000",
              "body": {
                "stringValue": "Hello World"
              },
              "traceId": "",
              "spanId": ""
            }
          ]
        }
      ]
    }
  ]
}
```

For more details about further processing, read the [content modifier](https://docs.fluentbit.io/manual/4.1/data-pipeline/processors/content-modifier) processor documentation.
