feat: Ship traces to datadog and add trace correlation (#6311)

* mvp works locally

* move to vars

* remove local dev datadog shipper
This commit is contained in:
Kian Jones
2025-11-20 15:26:48 -08:00
committed by Caren Thomas
parent cee3c7ed58
commit 3c841b2e33
2 changed files with 26 additions and 2 deletions

View File

@@ -71,6 +71,20 @@ class JSONFormatter(logging.Formatter):
if hasattr(record, "dd.version"): if hasattr(record, "dd.version"):
log_data["dd.version"] = getattr(record, "dd.version") log_data["dd.version"] = getattr(record, "dd.version")
# Add OpenTelemetry trace correlation (for OTEL → Datadog integration)
try:
from opentelemetry import trace
span = trace.get_current_span()
if span and span.get_span_context().is_valid:
ctx = span.get_span_context()
# Format trace_id and span_id as Datadog expects (decimal strings)
log_data["dd.trace_id"] = str(ctx.trace_id)
log_data["dd.span_id"] = str(ctx.span_id)
except Exception:
# Fail silently if OTEL is not available
pass
# Add exception info if present # Add exception info if present
if record.exc_info: if record.exc_info:
log_data["exception"] = { log_data["exception"] = {

View File

@@ -53,6 +53,16 @@ exporters:
max_interval: 30s max_interval: 30s
max_elapsed_time: 300s max_elapsed_time: 300s
datadog:
api:
site: ${env:DD_SITE}
key: ${env:DD_API_KEY}
traces:
span_name_as_resource_name: true
span_name_remappings:
http.method: http.request.method
http.status_code: http.response.status_code
extensions: extensions:
health_check: health_check:
pprof: pprof:
@@ -69,11 +79,11 @@ service:
traces: traces:
receivers: [otlp] receivers: [otlp]
processors: [memory_limiter, batch] processors: [memory_limiter, batch]
exporters: [clickhouse] exporters: [clickhouse, datadog]
logs: logs:
receivers: [filelog] receivers: [filelog]
processors: [resource, memory_limiter, batch] processors: [resource, memory_limiter, batch]
exporters: [clickhouse] exporters: [clickhouse, datadog]
metrics: metrics:
receivers: [otlp] receivers: [otlp]
processors: [memory_limiter, batch] processors: [memory_limiter, batch]