# Elastic APM does not support the Otel Span Events. is there an alternative?

**URL:** <https://discuss.elastic.co/t/elastic-apm-does-not-support-the-otel-span-events-is-there-an-alternative/269020>\
**Category:** APM\
**Tags:** java, server\
**Created:** [April 1, 2021, 10:50am UTC](https://discuss.elastic.co/t/elastic-apm-does-not-support-the-otel-span-events-is-there-an-alternative/269020 "2021-04-01T10:50:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ayada\_yassine](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ayada_yassine/32/86463_2.png) [@ayada\_yassine](https://discuss.elastic.co/u/ayada_yassine)\
**Post date:** [April 1, 2021, 10:50am UTC](https://discuss.elastic.co/t/elastic-apm-does-not-support-the-otel-span-events-is-there-an-alternative/269020/1 "2021-04-01T10:50:11Z")

</div>

I want to use span events to attach my logs to my span,  
Elastic Apm ignore opentelemetry exported span events.

is there an alternative ?

OpenTelemetry Span Events: [opentelemetry-specification/api.md at main · open-telemetry/opentelemetry-specification · GitHub](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#add-events)

---

<div class="post-metadata">

**Author:** ![cyrilleleclerc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cyrilleleclerc/32/60493_2.png) [@cyrilleleclerc](https://discuss.elastic.co/u/cyrilleleclerc)\
**Post date:** [April 1, 2021, 3:12pm UTC](https://discuss.elastic.co/t/elastic-apm-does-not-support-the-otel-span-events-is-there-an-alternative/269020/2 "2021-04-01T15:12:15Z")

</div>

Hello Ayada,

It's correct that we don't support span events at the moment.  
Regarding logs integration, we recommend an alternate pattern injecting the trace\_id and span\_id in the logs and then ingest the logs as a separate stream in Elastic Observability.

1. Use the capability in Otel APM Agents to inject span\_id and trace\_id in the logging framework such as Log4j2 or Logback/SLF4J in Java.
2. Export you logs as JSON. In Java with Logback, you can use the library `logback-json-classic`
3. Use a log collector like Elastic Filebeat to collect the logs and ship them in Elastic complying with the Elastic Common Schema to get the trace\_id and schema\_id recognized
4. When looking at traces in Elastic Observability, use the logs tab to view the logs associated with your trace.

**Example log message emitted by Logback with `logback-json-classic`**

```
{
   "timestamp":"1615986569752",
   "level":"INFO",
   "thread":"http-nio-8081-exec-7",
   "mdc":{
      "trace_id":"98600b7e3ed8be404fed0671cde6448d",
      "trace_flags":"01",
      "span_id":"5f928785b1a2ef30"
   },
   "logger":"com.mycompany.antifraud.AntiFraudController",
   "message":"checkOrder(totalPrice: 005, shippingCountry: US, customerIpAddress: 127.0.0.1): fraudScore: -52, rejected: false, expectedSleep: 53ms, actualSleep: 181ms, delta:241%",
   "context":"default"
}

```

**Logback configuration**

> <https://github.com/cyrille-leclerc/my-shopping-cart/blob/e3f62c2116f238915de6be9635ecb54937d5abec/anti-fraud-java/src/main/resources/logback-spring-json-file-appender.xml>

**Maven pom.xml**

```
<dependency>
    <groupId>ch.qos.logback.contrib</groupId>
    <artifactId>logback-json-classic</artifactId>
</dependency>
<dependency>
    <groupId>ch.qos.logback.contrib</groupId>
    <artifactId>logback-jackson</artifactId>
</dependency>

```

**Elastic Filebeat Configuration**

```
filebeat.inputs:
  - type: log
    enabled: true
    json.keys_under_root: true
    json.overwrite_keys: true
    paths:
      - /usr/local/var/log/my-shopping-cart/anti-fraud.log
    fields:
      service.name: frontend
    fields_under_root: true

processors:
  - add_host_metadata: ~
  - add_cloud_metadata: ~
  - add_docker_metadata: ~
  - add_kubernetes_metadata: ~
  - timestamp:
      field: "timestamp"
      layouts:
        - "UNIX_MS"
      ignore_missing: true
      test:
        - "1615986552269"
  - rename:
      fields:
        - from: "level"
          to: "log.level"
        - from: "thread"
          to: "process.thread.name"
        - from: "mdc.trace_id"
          to: "trace.id"
        - from: "mdc.span_id"
          to: "span.id"
        - from: "logger"
          to: "log.logger"
      ignore_missing: true
      fail_on_error: true
...
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 22, 2021, 11:12am UTC](https://discuss.elastic.co/t/elastic-apm-does-not-support-the-otel-span-events-is-there-an-alternative/269020/3 "2021-04-22T11:12:42Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
