# 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/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://4080960765-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYLAade0z5f61r7oMWpvX%2Fuploads%2Fgit-blob-d44920a144e4d1b747ffb72630bed6c2db5bc648%2Fprocessor_opentelemetry_envelope.png?alt=media)

{% hint style="info" %}
Only [YAML configuration files](https://docs.fluentbit.io/manual/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/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/data-pipeline/processors/content-modifier) processor documentation.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.fluentbit.io/manual/data-pipeline/processors/opentelemetry-envelope.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
