I would like to send trace data from a Next.js application I am developing in TypeScript to Datadog, but I can't figure it out after reading the documentation and have not been able to do that. I have specified Datadog as the exporter in collector.yaml and it shows graphs for CPU, memory, etc., but it does not show Traces data for GET and POST requests to the application.
Looking at the app log of the Docker container, it seems that traces are being made, but they are not being sent to Datadog.
How can I use OpentelemetryCollector to send application trace data to Datadog?
I am running in a local environment on a mac and don't know how to reference the logs in the Docker container, so I have commented out the filelog, is this the cause?
Here is what I have set up and the graph in question.
English may be unnatural due to the use of translation software. Sorry.
Translated with DeepL.com (free version)
・collector.yaml
receivers:
otlp:
protocols:
http:
endpoint: "localhost:4318"
grpc:
endpoint: "localhost:4317"
hostmetrics:
collection_interval: 10s
scrapers:
paging:
metrics:
system.paging.utilization:
enabled: true
cpu:
metrics:
system.cpu.utilization:
enabled: true
disk:
filesystem:
metrics:
system.filesystem.utilization:
enabled: true
load:
memory:
network:
processes:
prometheus:
config:
scrape_configs:
- job_name: 'otelcol'
scrape_interval: 10s
static_configs:
- targets: ['0.0.0.0:8888']
# filelog:
# include_file_path: true
# poll_interval: 500ms
# include:
# - /var/log/**/*example*/*.log
processors:
batch:
send_batch_max_size: 1000
send_batch_size: 100
timeout: 10s
exporters:
datadog:
api:
site: datadoghq.com
key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
service:
pipelines:
metrics:
receivers: [hostmetrics, prometheus, otlp]
processors: [batch]
exporters: [datadog]
traces:
receivers: [otlp]
processors: [batch]
exporters: [datadog]
logs:
# receivers: [otlp, filelog]
receivers: [otlp]
processors: [batch]
exporters: [datadog]
・instrumentation.ts
/*instrumentation.ts*/
import { NodeSDK } from '@opentelemetry/sdk-node';
import { ConsoleSpanExporter } from '@opentelemetry/sdk-trace-node';
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
import {
PeriodicExportingMetricReader,
ConsoleMetricExporter,
} from '@opentelemetry/sdk-metrics';
const sdk = new NodeSDK({
traceExporter: new ConsoleSpanExporter(),
metricReader: new PeriodicExportingMetricReader({
exporter: new ConsoleMetricExporter(),
}),
instrumentations: [getNodeAutoInstrumentations()],
});
sdk.start();
The issue is that the instrumentation is not actually exporting the data anywhere.
You are currently using
ConsoleSpanExporterandConsoleMetricExporterwhich exports Spans and Metrics to the console.You need to change your instrumentation to use the
OTLPexporters.If your collector is exposing ports
4317and4318to your localhost, you can remove theurlfromOTLPTraceExporterandOTLPMetricExporter.If you prefer, you can also set the following environment variable in your application Dockerfile or Docker compose file to point the
OTLPdata to the collector:Another thing that I've noticed is that if you are using the OTel Collector version
0.95.0+, you will also need thedatadog/connectorcomponent in your collector config: