# Gravitee.io  - Tracing support with OpenTelemetry

**URL:** <https://community.dynatrace.com/t/gravitee-io-tracing-support-with-opentelemetry/47915>\
**Category:** Dynatrace Tips\
**Tags:** opentelemetry, distributed-tracing\
**Created:** [September 23, 2024, 3:24pm UTC](https://community.dynatrace.com/t/gravitee-io-tracing-support-with-opentelemetry/47915 "2024-09-23T15:24:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [September 23, 2024, 3:24pm UTC](https://community.dynatrace.com/t/gravitee-io-tracing-support-with-opentelemetry/47915/1 "2024-09-23T15:24:35Z")

</div>

The [Gravitee.io](http://Gravitee.io) API gateway is not a directly supported technology by OneAgent. Without support, you are unable to see any processing within the API gateway, and traces stop at the API gateway.&nbsp; Luckily, there is OpenTelemetry support for Gravitee 4.x helping to overcome this.

# Steps to get this working **for Gravitee 4.6 or higher:**

## **Prerequisites**

If you run OneAgent on the Gravitee Gateway host, either turn off deep monitoring for the Gateway process or turn off the following OneAgent features for the Gravitee Gateway process groups, otherwise, you will have duplicate spans and/or tracing is broken.

- Java Netty
- Java OpenTelemetry

## Option 1 -&nbsp; **send traces directly to Dynatrace** (SaaS or Managed)

1. Create an Api Token in your Dynatrace environment with scope trace ingest scope.
2. Configure tracing in Gravitee based on&nbsp;[OpenTelemetry | API Management | Gravitee Documentation](https://documentation.gravitee.io/apim/analyze-and-monitor-apis/opentelemetry#enable-opentelemetry-for-your-gateway),&nbsp;typically in gravitee.yml, where  
\<DT\_ENVIRONMENT\> is URL for the Dynatrace environment like [https://abc12345.live.dynatrace.com](https://abc12345.live.dynatrace.com)&nbsp;for SaaS or [https://host/e/](https://host/e/)\<environmentid&nbsp;for Managed

```markup
services:
  opentelemetry:
    enabled: true
    verbose: false    
    exporter:
      endpoint: <DT_ENVIRONMENT>/api/v2/otlp
      protocol: http/protobuf
      compression: gzip
      headers:
        - Authorization: api-token <API_TOKEN>​

```

Adjust other parameters, if necessary, such as SSL (typically needed in Managed environments only) or proxy.

## Option 2 - Send traces&nbsp; **using locally running fullstack OneAgent**

If you want to send **traces using locally running full-stack OneAgent** , you can simplify the configuration a little bit, and spans are also included in the OneAgent full-stack license compared to Option 1.

1. Ensure EEC is enabled on the OneAgent hosts or globally in Dynatrace, see&nbsp;[About Extensions — Dynatrace Docs](https://docs.dynatrace.com/docs/shortlink/extension-concepts)
2. Configure Gravitee Gateway in gravitee.yml (or accordingly if other options are used).

```markup
services:
  opentelemetry:
    enabled: true
    verbose: false    
    exporter:
      endpoint: http://localhost:14499/otlp
      protocol: http/protobuf
      compression: none

```

## Option 3 - Send traces if Gravitee runs in Kubernetes using Dynatrace Operator Telemetry ingest

This requires Dynatrace Operator 1.6 or newer on the cluster running Gravitee gateway.

1. Enable and configure the Telemetry ingest with Dynatrace Operator by following&nbsp; [Telemetry ingest support](https://docs.dynatrace.com/docs/shortlink/guides-telemetry-ingest).
2. Configure Gravitee Gateway in gravitee.yml (or accordingly if other options are used), adjust the hostname accordingly to your dynakube configuration:

```markup
services:
  opentelemetry:
    enabled: true
    verbose: false    
    exporter:
      endpoint: http://dynakube-telemetry-ingest.dynatrace.svc:4317
      protocol: grpc

```

## Additional considerations

If you want a relation between the Unified service and process group instance, you need to add the resource attributes **dt.entity.process\_group\_instance** and **dt.entity.host** (added automatically if you send traces using locally installed OneAgent (option two). Although adding resource attributes can be accomplished by adding extraAttributes parameter in Gravitee, it does not work for keys with an underscore character, so an easier solution is to use OpenTelemetry Collector or Dynatrace collector to add the values. See an example below using the locally installed OneAgent as final ingest endpoint:

```markup
receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317

processors:
  resource:
    attributes:
      - key: dt.entity.host
        value: <HOST>
        action: upsert
      - key: dt.entity.process_group_instance
        value: <PROCESS_GROUP_INSTANCE>
        action: upsert

exporters:
  otlphttp:
    endpoint: http://localhost:14499/otlp

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [resource]
      exporters: [otlphttp]
    metrics:
      receivers: [otlp]
      processors: [resource]
      exporters: [otlphttp]
    logs:
      receivers: [otlp]
      processors: [resource]
      exporters: [otlphttp]

```

# Steps to get this working **for Gravitee 4.5 or lower:**

- **If your version is 4.3 or lower** , please add [opentelemetry-api-1.39.0.jar](https://repo1.maven.org/maven2/io/opentelemetry/opentelemetry-api/1.39.0/opentelemetry-api-1.39.0.jar) and&nbsp;[opentelemetry-context-1.39.0.jar](https://repo1.maven.org/maven2/io/opentelemetry/opentelemetry-context/1.39.0/opentelemetry-context-1.39.0.jar) libraries to lib/ext/ directory. You can download them from maven (links above).
- **If your version is 4.3 or lowser** , please add&nbsp;[gravitee-tracer-opentelemetry-1.0.1.zip](https://download.gravitee.io/graviteeio-apim/plugins/tracers/gravitee-tracer-opentelemetry/gravitee-tracer-opentelemetry-1.0.1.zip)&nbsp;(or newer) to plugins directory unless you are already using a distribution with the plugin.
- Create an Api Token in your Dynatrace environment with scope trace ingest scope.
- Deploy OpenTelemetry collector to the host where the Gravitee API gateway is running or where it fits your case. You can also reuse existing collectors. I recommend using Dynatrace distribution directly, see&nbsp;[Deploy the Dynatrace OTel Collector — Dynatrace Docs](https://docs.dynatrace.com/docs/shortlink/otel-collector-deploy)&nbsp;for deployment
- Configure your OpenTelemetry collector, sample config is below and it includes OpenTelemetry resource attributes to map the ingested traces to existing entities in Dynatrace. In the same change:  
\<HOST\> for your HOST entity ID&nbsp; where your API gateway is running,  
\<PROCESS\_GROUP\_INSTANCE\> for your process group instance of the API gateway process on the host  
\<ENVIRONMENT\> for your Dynatrace environment URL e.g. [https://abc12345.live.dynatrace.com](https://abc12345.live.dynatrace.com)  
\<APITOKEN\> for your API token created in the previous step

```markup
receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317

processors:
  resource:
    attributes:
      - key: dt.entity.host
        value: <HOST>
        action: upsert
      - key: dt.entity.process_group_instance
        value: <PROCESS_GROUP_INSTANCE>
        action: upsert

exporters:
  otlphttp:
    endpoint: <ENVIRONMENT>/api/v2/otlp
    headers:
      Authorization: "Api-Token <APITOKEN>"

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [resource]
      exporters: [otlphttp]
    metrics:
      receivers: [otlp]
      processors: [resource]
      exporters: [otlphttp]
    logs:
      receivers: [otlp]
      processors: [resource]
      exporters: [otlphttp]
​

```

- Start or restart the OpenTelemetry collector.

- Configure Gravitee API gateway in gravitee.yml to include OpenTelemetry tracer. In case the OpenTelemetry collector is not running on the same host, change the URL accordingly.

```markup
tracing:                 
    enabled: true 
    type: otel                                                   
    otel:                                                                         
      url: grpc://localhost:4317​

```

- Restart the API gateway process, you should see the enablement of the otel tracing in the API gateway logs:

```markup
13:58:09.943 [graviteeio-node] [] INFO i.g.node.tracing.TracingService - Tracing support is enabled with tracer: name[otel]​

```

- Traces now should be ingested and a new Unified service should be created on the API Gateway process:

- You should now see full traces including the API Gateway processing.&nbsp; In the image below - the red part is from OneAgent, the blue part is from the OpenTelemetry tracing plugin, and the green part is from another service monitored by OneAgent.

Just a few notes:

- OneAgent deployment is not required but I recommend doing it for licensing and better request monitoring
- Although the OpenTelemetry plugin for Gravitee includes OTLP http output, it supports only the JSON payload which is on the other side not supported by Dynatrace. Dynatrace supports protobuf only for OTLP. That’s why OpenTelemetry collector is required.

---

<div class="post-metadata">

**Author:** ![agonzalez](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/agonzalez/32/8558_2.png) [@agonzalez](https://community.dynatrace.com/u/agonzalez)\
**Post date:** [October 11, 2024, 9:01am UTC](https://community.dynatrace.com/t/gravitee-io-tracing-support-with-opentelemetry/47915/2 "2024-10-11T09:01:47Z")

</div>

Hello Julius, thanks for this tutorial! Especially for the note on OTLP HTTP output. The OneAgent is deployed on the gateway. We thought we would be able to capture the OpenTelemetry traces directly, but it was not possible without the OTel Collector.

---

<div class="post-metadata">

**Author:** ![AntonioSousa](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/antoniosousa/32/50_2.png) [@AntonioSousa](https://community.dynatrace.com/u/AntonioSousa)\
**Post date:** [October 11, 2024, 9:29am UTC](https://community.dynatrace.com/t/gravitee-io-tracing-support-with-opentelemetry/47915/3 "2024-10-11T09:29:59Z")

</div>

[@Julius\_Loman](https://community.dynatrace.com/user/3364),

Thanks for the detailed configuration. While not a [Gravitee.io](http://Gravitee.io) user, it’s great to know how certain services are implementing OpenTelemetry and how they integrate with Dynatrace.

---

<div class="post-metadata">

**Author:** ![agonzalez](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/agonzalez/32/8558_2.png) [@agonzalez](https://community.dynatrace.com/u/agonzalez)\
**Post date:** [October 11, 2024, 10:12am UTC](https://community.dynatrace.com/t/gravitee-io-tracing-support-with-opentelemetry/47915/4 "2024-10-11T10:12:31Z")

</div>

It seems that my traces aren’t complete, I think Gravitee remove headers, did it happened to you ?

Can you confirm the header that I need to be forwarded by Gravitee, I supposed the following:

- x-dynatrace

- traceparent

- tracestate

Is there anything else I should be carefull about ?

---

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [October 11, 2024, 2:35pm UTC](https://community.dynatrace.com/t/gravitee-io-tracing-support-with-opentelemetry/47915/5 "2024-10-11T14:35:20Z")

</div>

[@agonzalez](https://community.dynatrace.com/user/58691)&nbsp;it did not happen in my case. Maybe this is specific to your [gravitee.io](http://gravitee.io) setup (a policy removing specific headers?) or something else is removing headers. I recommend setting up request attributes on the services to capture the values. You need just w3c headers (traceparent, tracestate) for this to work.

Basically, the tricky part was just the OTLP HTTP setup which produces JSON only and this is not mentioned in the docs.

One important caveat is the enrichment of traces with Dynatrace resource attributes, so your trace ingest is covered by a full-stack oneagent license - but that’s already in my setup above.

---

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [October 17, 2024, 6:44am UTC](https://community.dynatrace.com/t/gravitee-io-tracing-support-with-opentelemetry/47915/6 "2024-10-17T06:44:53Z")

</div>

If you have OneAgent on the gravitee host, normally OneAgent will collect the OTEL traces and the collector is not required. Unfortunately, Gravitee configuration for OpenTelemetry plugin requires a valid configuration and output, otherwise, it will produce a lot of errors about the plugin being unable to export traces.

So a valid destination in Gravitee is needed. It’s not possible to include and enable the plugin without it.
