Skip to content

Commit

Permalink
[exporter/datadog] Add logs example (#14795)
Browse files Browse the repository at this point in the history
* [exporter/datadog] Add logging example

* fix tests

* Apply suggestions from code review

Co-authored-by: Gabriel Aszalos <[email protected]>

* PR comments

* Apply suggestions from code review

Co-authored-by: Gabriel Aszalos <[email protected]>

* PR comments - remove #

* Apply suggestions from code review

Co-authored-by: Gabriel Aszalos <[email protected]>

Co-authored-by: Gabriel Aszalos <[email protected]>
  • Loading branch information
dineshg13 and gbbr authored Oct 18, 2022
1 parent be49904 commit a0126a5
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 42 deletions.
26 changes: 26 additions & 0 deletions exporter/datadogexporter/examples/collector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,25 @@ receivers:
# static_configs:
# - targets: ['0.0.0.0:8888']

# Read more about the filelog receiver here https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/filelogreceiver.
filelog:
include_file_path: true
poll_interval: 500ms
include:
# Logs will be collected from the below file path. Please ensure it is correct or edit as needed.
- /var/log/**/*example*/*.log
# # It is essential to extract the trace_id and span_id from the logs in order to ensure that logs / traces correlation works.
# # For JSON logs, json_parser will parse the body into attributes, while trace_parser will extract the trace_id and span_id.
# operators:
# - id : parse_body
# type: json_parser
# - id: trace
# type: trace_parser
# trace_id:
# parse_from: attributes.trace_id
# span_id:
# parse_from: attributes.span_id

# Read more about processors here: https://opentelemetry.io/docs/collector/configuration/#processors
#
# Some processors are recommended in all pipelines:
Expand Down Expand Up @@ -269,6 +288,13 @@ service:
processors: [batch]
exporters: [datadog]

# Pipelines starting with `logs` or `logs/` define a logs pipeline.
logs:
# This pipeline has an OTLP receiver, filelog receiver, a batch processor and a Datadog exporter.
receivers: [otlp, filelog]
processors: [batch]
exporters: [datadog]

# # To send data to the gateway on gateway deployment mode, define these pipelines instead.
#
# metrics/gateway:
Expand Down
20 changes: 19 additions & 1 deletion exporter/datadogexporter/examples/k8s-chart/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ data:
memory:
network:
processes:
filelog:
include_file_path: true
poll_interval: 500ms
include:
# This will ensure that logs from the following path are collected.
- /var/log/**/*otel-collector*/*.log
# # Comment out this block below to get access to system metrics regarding
# # the OpenTelemetry Collector and its environment, such as spans or metrics
# # processed, running and sent, queue sizes, uptime, k8s information
Expand All @@ -52,7 +59,7 @@ data:
key: <YOUR_API_KEY_HERE>
processors:
resourcedetection:
# ensures host.name and other important resource tags
# ensures host.name and other important resource tags
# get picked up
detectors: [system, env, docker]
timeout: 5s
Expand All @@ -66,6 +73,13 @@ data:
send_batch_size: 100
timeout: 10s
service:
# This will make the collector output logs in JSON format
telemetry:
logs:
encoding: "json"
initial_fields:
# Add the service field to every log line. It can be used for filtering in Datadog.
- service: "otel-collector"
pipelines:
metrics:
receivers: [hostmetrics, otlp]
Expand All @@ -75,3 +89,7 @@ data:
receivers: [otlp]
processors: [resourcedetection, k8sattributes, batch]
exporters: [datadog]
logs:
receivers: [filelog]
processors: [batch]
exporters: [datadog]
89 changes: 51 additions & 38 deletions exporter/datadogexporter/examples/k8s-chart/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,55 @@ spec:
spec:
serviceAccountName: otel-collector-account
containers:
- name: collector
command:
- "/otelcol-contrib"
- "--config=/conf/otel-agent-config.yaml"
image: otel/opentelemetry-collector-contrib:0.59.0
resources:
limits:
cpu: 1
memory: 2Gi
requests:
cpu: 200m
memory: 400Mi
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
# The k8s.pod.ip is used to associate pods for k8sattributes
- name: OTEL_RESOURCE_ATTRIBUTES
value: "k8s.pod.ip=$(POD_IP)"
ports:
- containerPort: 4318 # default port for OpenTelemetry HTTP receiver.
hostPort: 4318
- containerPort: 4317 # default port for OpenTelemetry gRPC receiver.
hostPort: 4317
- containerPort: 8888 # Default endpoint for querying metrics.
volumeMounts:
- name: otel-agent-config-vol
mountPath: /conf
- name: collector
command:
- "/otelcol-contrib"
- "--config=/conf/otel-agent-config.yaml"
image: otel/opentelemetry-collector-contrib:0.61.0
resources:
limits:
cpu: 1
memory: 2Gi
requests:
cpu: 200m
memory: 400Mi
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
# The k8s.pod.ip is used to associate pods for k8sattributes
- name: OTEL_RESOURCE_ATTRIBUTES
value: "k8s.pod.ip=$(POD_IP)"
ports:
- containerPort: 4318 # default port for OpenTelemetry HTTP receiver.
hostPort: 4318
- containerPort: 4317 # default port for OpenTelemetry gRPC receiver.
hostPort: 4317
- containerPort: 8888 # Default endpoint for querying metrics.
volumeMounts:
- name: otel-agent-config-vol
mountPath: /conf
- name: varlogpods
mountPath: /var/log/pods
readOnly: true
- name: varlibdockercontainers
mountPath: /var/lib/docker/containers
readOnly: true
volumes:
- name: otlpgen
hostPath:
path: /otlpgen
- name: otel-agent-config-vol
configMap:
name: otel-agent-conf
items:
- key: otel-agent-config
path: otel-agent-config.yaml
- name: otlpgen
hostPath:
path: /otlpgen
- name: otel-agent-config-vol
configMap:
name: otel-agent-conf
items:
- key: otel-agent-config
path: otel-agent-config.yaml
# Mount nodes log file location.
- name: varlogpods
hostPath:
path: /var/log/pods
- name: varlibdockercontainers
hostPath:
path: /var/lib/docker/containers
2 changes: 2 additions & 0 deletions exporter/datadogexporter/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

"github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/filelogreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver"
)

Expand Down Expand Up @@ -95,6 +96,7 @@ func newTestComponents(t *testing.T) component.Factories {
[]component.ReceiverFactory{
otlpreceiver.NewFactory(),
hostmetricsreceiver.NewFactory(),
filelogreceiver.NewFactory(),
}...,
)
require.NoError(t, err)
Expand Down
9 changes: 8 additions & 1 deletion exporter/datadogexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry v0.62.0
github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor v0.62.0
github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor v0.62.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/filelogreceiver v0.62.0
github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver v0.62.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/stretchr/testify v1.8.0
Expand Down Expand Up @@ -47,7 +48,9 @@ require (
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/Showmax/go-fqdn v1.0.0 // indirect
github.com/antonmedv/expr v1.9.0 // indirect
github.com/armon/go-metrics v0.3.10 // indirect
github.com/bmatcuk/doublestar/v3 v3.0.0 // indirect
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 // indirect
Expand Down Expand Up @@ -107,7 +110,9 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mostynb/go-grpc-compression v1.1.17 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/observiq/ctimefmt v1.0.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.62.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza v0.62.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 // indirect
Expand All @@ -117,7 +122,6 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20220216144756-c35f1ee13d7c // indirect
github.com/rogpeppe/go-internal v1.8.1 // indirect
github.com/rs/cors v1.8.2 // indirect
github.com/secure-systems-lab/go-securesystemslib v0.4.0 // indirect
github.com/shirou/gopsutil/v3 v3.22.9 // indirect
Expand All @@ -143,6 +147,7 @@ require (
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect
gonum.org/v1/gonum v0.12.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220915135415-7fd63a7952de // indirect
google.golang.org/grpc v1.50.1 // indirect
Expand Down Expand Up @@ -176,6 +181,8 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/processor/reso

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver => ../../receiver/hostmetricsreceiver

replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/filelogreceiver => ../../receiver/filelogreceiver

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/opencensus => ../../pkg/translator/opencensus

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/scrapertest => ../../internal/scrapertest
Loading

0 comments on commit a0126a5

Please sign in to comment.