-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Log Correlation Example | ||
|
||
This is a `docker compose` setup showcases log correlation by creating two services: Datadog Agent and Kong Gateway. | ||
|
||
The Kong Gateway is configured to generate and send distributed traces to Datadog, and the [file-config](https://docs.konghq.com/hub/kong-inc/file-log/) | ||
plugin to generate logs that will also be sent to Datadog. The entire configuration is located in [kong.yaml](./kong.yaml). | ||
|
||
To run this example, you will need a valid Datadog API key and Docker installed. | ||
|
||
### How to run the example | ||
|
||
1. Start the services using Docker Compose with you Datadog API key: | ||
|
||
```shell | ||
DD_API_KEY=<KEY> docker compose up | ||
``` | ||
|
||
2. Grant the `kong-dbless` service permission to create the log file in the shared volume: | ||
``` | ||
docker compose exece kong-dbless chown -R kong /shared | ||
``` | ||
|
||
3. Send a request to Kong to generate traffic and a trace: | ||
```shell | ||
curl http://localhost:8000/foo | ||
{ | ||
"headers": { | ||
"Accept": "*/*", | ||
"Host": "httpbin.org", | ||
"Traceparent": "00-c9a6361300000000269a8b8c076bafcb-55eb48277a5d69e1-01", | ||
"Tracestate": "dd=p:55eb48277a5d69e1;s:1;t.tid:c9a6361300000000;t.dm:-0", | ||
"User-Agent": "curl/8.6.0", | ||
"X-Amzn-Trace-Id": "Root=1-66587c78-12932e884e34a78e68008bc4", | ||
"X-Datadog-Parent-Id": "6191121447144745441", | ||
"X-Datadog-Sampling-Priority": "1", | ||
"X-Datadog-Tags": "_dd.p.tid=c9a6361300000000,_dd.p.dm=-0", | ||
"X-Datadog-Trace-Id": "2781689153390882763", | ||
"X-Forwarded-Host": "localhost", | ||
"X-Forwarded-Path": "/foo", | ||
"X-Forwarded-Prefix": "/foo" | ||
} | ||
} | ||
``` | ||
|
||
The trace should be reported in your Datadog account: | ||
![](./assets/trace.png) | ||
|
||
Additionally, the log will be available, with the ability to pivot between trace and log views: | ||
![](./assets/log.png) | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
version: "3.2" | ||
|
||
services: | ||
# `agent` is the Datadog Agent to which traces are sent. | ||
# `agent` needs an API key set in the environment as the | ||
# `DD_API_KEY` environment variable. | ||
datadog-agent: | ||
image: 'datadog/agent' | ||
labels: | ||
com.datadoghq.ad.logs: '[{"type": "file", "source": "kong", "service": "log-correlation-example-service", "path": "/shared/log-tracing.log"}]' | ||
ports: | ||
- 8136:8136 | ||
volumes: | ||
- '/var/run/docker.sock:/var/run/docker.sock:ro' | ||
- '/proc/:/host/proc/:ro' | ||
- '/sys/fs/cgroup/:/host/sys/fs/cgroup:ro' | ||
- shared-volume:/shared:ro | ||
environment: | ||
- DD_SITE | ||
- DD_API_KEY | ||
- DD_APM_ENABLED=true | ||
- DD_LOGS_ENABLED=true | ||
- DD_LOG_LEVEL=ERROR | ||
|
||
kong-dbless: | ||
image: 'kong/kong-gateway:3.3.0.0' | ||
user: root | ||
links: | ||
- datadog-agent | ||
volumes: | ||
- ./kong.yaml:/kong/declarative/kong.yaml | ||
- ../../kong:/tmp/custom_plugins/kong | ||
- shared-volume:/shared | ||
environment: | ||
- DD_SERVICE=log-correlation-example-service | ||
- DD_AGENT_HOST=datadog-agent | ||
- KONG_DATABASE=off | ||
- KONG_LOG_LEVEL=info | ||
- KONG_DECLARATIVE_CONFIG=/kong/declarative/kong.yaml | ||
- KONG_PROXY_ACCESS_LOG=/dev/stdout | ||
- KONG_ADMIN_ACCESS_LOG=/dev/stdout | ||
- KONG_PROXY_ERROR_LOG=/dev/stderr | ||
- KONG_ADMIN_ERROR_LOG=/dev/stderr | ||
- KONG_ADMIN_LISTEN=0.0.0.0:8001 | ||
- KONG_ADMIN_GUI_URL=http://localhost:8002" | ||
- "KONG_LUA_PACKAGE_PATH=/tmp/custom_plugins/?.lua;;" | ||
- "KONG_PLUGINS=bundled,ddtrace" | ||
ports: | ||
- 8000:8000 | ||
- 8001:8001 | ||
- 8002:8002 | ||
- 8003:8003 | ||
- 8004:8004 | ||
- 8443:8443 | ||
- 8444:8444 | ||
- 8445:8445 | ||
|
||
volumes: | ||
shared-volume: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
_format_version: "3.0" | ||
_transform: true | ||
|
||
services: | ||
- name: service-a | ||
url: http://httpbin.org/headers | ||
plugins: | ||
- name: ddtrace | ||
- name: file-log | ||
config: | ||
path: /shared/log-tracing.log | ||
custom_fields_by_lua: | ||
dd.trace_id: return kong.ctx.shared.datadog_sdk_trace_id | ||
dd.span_id: return kong.ctx.shared.datadog_sdk_span_id | ||
routes: | ||
- name: my-route-a | ||
paths: | ||
- /foo |