Send OpenTelemetry data to Grafana Cloud
In Grafana, configure OpenTelemetry Collector as an integration, then deploy OTEL Collector with the Grafana username, password, and endpoint, and configure the OpenTelemetry plugin to send data to OTEL Collector.
Prerequisites
Kong Konnect
This is a Konnect tutorial and requires a Konnect personal access token.
-
Create a new personal access token by opening the Konnect PAT page and selecting Generate Token.
-
Export your token to an environment variable:
export KONNECT_TOKEN='YOUR_KONNECT_PAT'Copied! -
Run the quickstart script to automatically provision a Control Plane and Data Plane, and configure your environment:
curl -Ls https://get.konghq.com/quickstart | bash -s -- -k $KONNECT_TOKEN -e KONG_TRACING_INSTRUMENTATIONS=all -e KONG_TRACING_SAMPLING_RATE=1.0 --deck-outputCopied!This sets up a Konnect Control Plane named
quickstart, provisions a local Data Plane, and prints out the following environment variable exports:export DECK_KONNECT_TOKEN=$KONNECT_TOKEN export DECK_KONNECT_CONTROL_PLANE_NAME=quickstart export KONNECT_CONTROL_PLANE_URL=https://us.api.konghq.com export KONNECT_PROXY_URL='http://localhost:8000'Copied!Copy and paste these into your terminal to configure your session.
Kong Gateway running
This tutorial requires Kong Gateway Enterprise. If you don’t have Kong Gateway set up yet, you can use the quickstart script with an enterprise license to get an instance of Kong Gateway running almost instantly.
-
Export your license to an environment variable:
export KONG_LICENSE_DATA='LICENSE-CONTENTS-GO-HERE'Copied! -
Run the quickstart script:
curl -Ls https://get.konghq.com/quickstart | bash -s -- -e KONG_LICENSE_DATA \ -e KONG_TRACING_INSTRUMENTATIONS=all \ -e KONG_TRACING_SAMPLING_RATE=1.0Copied!Once Kong Gateway is ready, you will see the following message:
Kong Gateway Ready
decK v1.43+
decK is a CLI tool for managing Kong Gateway declaratively with state files. To complete this tutorial, install decK version 1.43 or later.
This guide uses deck gateway apply, which directly applies entity configuration to your Gateway instance.
We recommend upgrading your decK installation to take advantage of this tool.
You can check your current decK version with deck version.
Required entities
For this tutorial, you’ll need Kong Gateway entities, like Gateway Services and Routes, pre-configured. These entities are essential for Kong Gateway to function but installing them isn’t the focus of this guide. Follow these steps to pre-configure them:
-
Run the following command:
echo ' _format_version: "3.0" services: - name: example-service url: http://httpbin.konghq.com/anything routes: - name: example-route paths: - "/anything" service: name: example-service ' | deck gateway apply -Copied!
To learn more about entities, you can read our entities documentation.
Grafana Cloud
This tutorial requires a Grafana Cloud account. You can create an account with a free trial at https://grafana.com/products/cloud/.
Configure the OpenTelemetry Collector integration in Grafana
We need to add a connection to OpenTelemetry in Grafana to generate the configuration we need.
- Log in to Grafana and launch your Grafana Cloud stack.
- In the sidebar, click Connections > Add new connection.
- Click OpenTelemetry Collector.
- In the Access Policy token name field, enter a name for the token, “kong-otel” for example.
-
Click Create token.
From the configuration generated by Grafana, export the values under
extensions.basicauth/grafana_cloud.client_authto your environment:export GRAFANA_USERNAME='username value' export GRAFANA_PASSWORD='password value'Copied!Then export the URL under
exporters.otlphttp/grafana_cloud.endpoint:export GRAFANA_ENDPOINT='endpoint value'Copied! -
In a terminal, create a configuration file for OpenTelemetry Collector:
nano otel-config.yamlCopied!Add the following content to the file and save it:
extensions: basicauth/grafana_cloud: client_auth: username: ${env:GRAFANA_USERNAME} password: ${env:GRAFANA_PASSWORD} health_check: pprof: endpoint: 0.0.0.0:1777 zpages: endpoint: 0.0.0.0:55679 receivers: otlp: protocols: grpc: endpoint: 0.0.0.0:4317 http: endpoint: 0.0.0.0:4318 prometheus: config: scrape_configs: - job_name: 'otel-collector' scrape_interval: 10s static_configs: - targets: ['0.0.0.0:8888'] jaeger: protocols: grpc: endpoint: 0.0.0.0:14250 thrift_binary: endpoint: 0.0.0.0:6832 thrift_compact: endpoint: 0.0.0.0:6831 thrift_http: endpoint: 0.0.0.0:14268 zipkin: endpoint: 0.0.0.0:9411 processors: batch: exporters: otlphttp/grafana_cloud: endpoint: ${env:GRAFANA_ENDPOINT} auth: authenticator: basicauth/grafana_cloud debug: verbosity: detailed service: pipelines: traces: receivers: [otlp, jaeger, zipkin] processors: [batch] exporters: [debug,otlphttp/grafana_cloud] metrics: receivers: [otlp, prometheus] processors: [batch] exporters: [debug,otlphttp/grafana_cloud] logs: receivers: [otlp] processors: [batch] exporters: [debug,otlphttp/grafana_cloud] extensions: [health_check, pprof, zpages, basicauth/grafana_cloud]Copied!This configuration is the default OpenTelemetry Collector configuration, with the addition of the Grafana exporter.
- In Grafana Cloud, in the Service name field, enter a name. In this example, we’ll use “kong-dev”.
- In your terminal, export the following environment variables:
export OTEL_SERVICE_NAME='kong-dev' export OTEL_RESOURCE_ATTRIBUTES='deployment.environment=production' export OTEL_EXPORTER_OTLP_ENDPOINT='http://localhost:4318' export OTEL_EXPORTER_OTLP_PROTOCOL='http/protobuf'Copied!
Deploy OpenTelemetry Collector
Now that we have the OpenTelemetry Collector configuration, we can deploy it. Use the opentelemetry-collector-contrib image and apply the configuration and environment variables that we defined in the previous step:
docker run \
-p 4318:4318 \
-e OTEL_SERVICE_NAME \
-e OTEL_RESOURCE_ATTRIBUTES \
-e OTEL_EXPORTER_OTLP_ENDPOINT \
-e OTEL_EXPORTER_OTLP_PROTOCOL \
-e GRAFANA_USERNAME \
-e GRAFANA_PASSWORD \
-e GRAFANA_ENDPOINT \
-v $(pwd)/otel-config.yaml:/etc/otelcol-contrib/config.yaml \
otel/opentelemetry-collector-contrib:0.141.0
You should already see some data in the terminal, however, this data will not be sent to Grafana since it doesn’t use the kong-dev service name.
In a new terminal, export the OTEL Collector host:
export DECK_OTEL_HOST=host.docker.internal
Enable the OpenTelemetry plugin
Let’s configure the OpenTelemetry plugin to send Kong Gateway metrics, traces, and logs to Grafana using the OpenTelemetry Collector.
Enable the OTEL plugin with the OTEL Collector endpoints settings configured:
echo '
_format_version: "3.0"
plugins:
- name: opentelemetry
config:
traces_endpoint: http://${{ env "DECK_OTEL_HOST" }}:4318/v1/traces
access_logs_endpoint: http://${{ env "DECK_OTEL_HOST" }}:4318/v1/logs
logs_endpoint: http://${{ env "DECK_OTEL_HOST" }}:4318/v1/logs
metrics:
endpoint: http://${{ env "DECK_OTEL_HOST" }}:4318/v1/metrics
resource_attributes:
service.name: kong-dev
' | deck gateway apply -
The
config.resource_attributes.service.namevalue should be the same as the service name defined in Grafana Cloud.
Validate the connection between OpenTelemetry Collector and Grafana
Send a POST request to generate traffic that we can use to validate that OpenTelemetry Collector is receiving the telemetry data:
curl -X POST "$KONNECT_PROXY_URL/anything" \
--no-progress-meter --fail-with-body \
-H "Accept: application/json"\
-H "Content-Type: application/json"
curl -X POST "http://localhost:8000/anything" \
--no-progress-meter --fail-with-body \
-H "Accept: application/json"\
-H "Content-Type: application/json"
You should see data in your OpenTelemetry Collector terminal.
Now, go back to the OTEL collector configuration in Grafana Cloud and click Test connection. You should see the following message:
Traces are being ingested properly
Validate that Grafana is receiving Kong Gateway data
- In the sidebar, click Drilldown.
- Click the signal you want to see:
- Metrics
- Logs
- Traces
If you don’t see your data, check that:
- You’re viewing the correct data source. In the Data source dropdown list, select:
-
grafanacloud-<stack-name>-promfor metrics -
grafanacloud-<stack-name>-logsfor logs -
grafanacloud-<stack-name>-tracesfor traces
-
- You’re viewing the correct time range.
If everything is working as expected, you should see graphs with your data. You can now start building dashboards.
Cleanup
Clean up Konnect environment
If you created a new control plane and want to conserve your free trial credits or avoid unnecessary charges, delete the new control plane used in this tutorial.
Destroy the Kong Gateway container
curl -Ls https://get.konghq.com/quickstart | bash -s -- -d