Skip to content

Commit 9cf8ee6

Browse files
bvigarRobin-Law
andauthored
[receiver/datadogreceiver] Adding logs support to the datadog receiver (open-telemetry#43841)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Adding a feature to the datadog receiver to support logs, in addition to the currently supported traces and metrics. This change adds support for the `api/v2/logs` endpoint. Note: There's purposefully no datadog semantics or conforming in this changeset because I plan to make those changes next in the [ddsemanticsprocessor](https://github.com/Sawmills/opentelemetry-collector-contrib/tree/e70d1b2ba66405e10dfc02afc170f8e2462b4a36/processor/datadogsemanticsprocessor). I didn't think they belonged here. <!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes <!--Describe what testing was performed and which tests were added.--> #### Testing - Built a custom collector locally with these changes and verified with the debug exporter that otel logs are being exported properly - Added tests for the log translation layer - Added e2e tests for the receiver for single and multiple logs <!--Describe the documentation added.--> #### Documentation Updated the `receiver/datadogreceiver/README.md` to now show support for logs. <!--Please delete paragraphs that you did not use before submitting.--> --------- Co-authored-by: Robin Law <[email protected]>
1 parent 5558a3f commit 9cf8ee6

19 files changed

+834
-6
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. receiver/filelog)
7+
component: receiver/datadog
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: "Adding log telemetry functionality to the existing datadog receiver component."
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [43841]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

receiver/datadogreceiver/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<!-- status autogenerated section -->
44
| Status | |
55
| ------------- |-----------|
6-
| Stability | [alpha]: traces, metrics |
6+
| Stability | [alpha]: traces, metrics, logs |
77
| Distributions | [contrib] |
88
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Areceiver%2Fdatadog%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Areceiver%2Fdatadog) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Areceiver%2Fdatadog%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Areceiver%2Fdatadog) |
99
| Code coverage | [![codecov](https://codecov.io/github/open-telemetry/opentelemetry-collector-contrib/graph/main/badge.svg?component=receiver_datadog)](https://app.codecov.io/gh/open-telemetry/opentelemetry-collector-contrib/tree/main/?components%5B0%5D=receiver_datadog&displayType=list) |
@@ -16,7 +16,7 @@
1616
## Overview
1717

1818
The Datadog receiver enables translation between Datadog and OpenTelemetry-compatible backends.
19-
It currently has support for Datadog's APM traces and Datadog metrics.
19+
It currently has support for Datadog's APM traces, metrics, and logs.
2020

2121
## Configuration
2222

@@ -120,6 +120,12 @@ Format example can be found [here](./internal/translator/traces_translator_test.
120120
| /api/v1/distribution_points | Development | |
121121
| /intake | Development | Support for proxying calls |
122122

123+
**Logs**
124+
125+
| Datadog API Endpoint | Status | Notes |
126+
|----------------------|-------------|------------------------------|
127+
| /api/v2/logs | Development | Support for msgpack and json |
128+
123129
### Temporality considerations
124130

125131
Some backends use a different [timestamp temporality](https://opentelemetry.io/docs/specs/otel/metrics/data-model/#temporality) than Datadog uses. Both delta and cumulative temporalities are allowed in the spec.

receiver/datadogreceiver/factory.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ func NewFactory() receiver.Factory {
2323
metadata.Type,
2424
createDefaultConfig,
2525
receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability),
26-
receiver.WithTraces(createTracesReceiver, metadata.TracesStability))
26+
receiver.WithTraces(createTracesReceiver, metadata.TracesStability),
27+
receiver.WithLogs(createLogsReceiver, metadata.LogsStability),
28+
)
2729
}
2830

2931
func createDefaultConfig() component.Config {
@@ -74,4 +76,19 @@ func createMetricsReceiver(ctx context.Context, params receiver.Settings, cfg co
7476
return r, nil
7577
}
7678

79+
func createLogsReceiver(ctx context.Context, params receiver.Settings, cfg component.Config, consumer consumer.Logs) (receiver.Logs, error) {
80+
var err error
81+
rcfg := cfg.(*Config)
82+
r := receivers.GetOrAdd(cfg, func() (dd component.Component) {
83+
dd, err = newDataDogReceiver(ctx, rcfg, params)
84+
return dd
85+
})
86+
if err != nil {
87+
return nil, err
88+
}
89+
90+
r.Unwrap().(*datadogReceiver).nextLogsConsumer = consumer
91+
return r, nil
92+
}
93+
7794
var receivers = sharedcomponent.NewSharedComponents()

receiver/datadogreceiver/generated_component_test.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/datadogreceiver/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ require (
1515
github.com/open-telemetry/opentelemetry-collector-contrib/internal/exp/metrics v0.139.0
1616
github.com/open-telemetry/opentelemetry-collector-contrib/internal/sharedcomponent v0.139.0
1717
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/datadog v0.139.0
18+
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden v0.139.0
19+
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest v0.139.0
1820
github.com/stretchr/testify v1.11.1
1921
github.com/tinylib/msgp v1.5.0
2022
github.com/vmihailenco/msgpack/v5 v5.4.1

receiver/datadogreceiver/go.sum

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/datadogreceiver/internal/metadata/generated_logs.go

Lines changed: 92 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/datadogreceiver/internal/metadata/generated_logs_test.go

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

receiver/datadogreceiver/internal/metadata/generated_status.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package translator // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/datadogreceiver/internal/translator"
5+
import (
6+
"go.opentelemetry.io/collector/pdata/plog"
7+
)
8+
9+
// I think the struct we should be unmarshaling into (below) should work, but doesn't include the status field for some reason...
10+
// https://github.com/DataDog/datadog-api-client-go/blob/151a146e7ae57e5e8ed620a9ae6f958ed7db1ca7/api/datadogV2/model_http_log_item.go#L14-L34
11+
type DatadogLogPayload struct {
12+
Message string `json:"message"`
13+
Status string `json:"status"`
14+
Timestamp int64 `json:"timestamp"`
15+
Hostname string `json:"hostname"`
16+
Service string `json:"service"`
17+
Source string `json:"ddsource"`
18+
Tags string `json:"ddtags"`
19+
}
20+
21+
func ToPlog(incomingLogs []*DatadogLogPayload) plog.Logs {
22+
plogPayload := plog.NewLogs()
23+
if len(incomingLogs) == 0 {
24+
return plogPayload
25+
}
26+
27+
resourceLogs := plogPayload.ResourceLogs().AppendEmpty()
28+
scopeLogs := resourceLogs.ScopeLogs().AppendEmpty()
29+
scopeLogs.LogRecords().EnsureCapacity(len(incomingLogs))
30+
for _, incomingLog := range incomingLogs {
31+
logRecord := scopeLogs.LogRecords().AppendEmpty()
32+
logRecord.Body().SetStr(incomingLog.Message)
33+
logRecord.Attributes().PutStr("status", incomingLog.Status)
34+
logRecord.Attributes().PutInt("timestamp", incomingLog.Timestamp)
35+
logRecord.Attributes().PutStr("hostname", incomingLog.Hostname)
36+
logRecord.Attributes().PutStr("service", incomingLog.Service)
37+
logRecord.Attributes().PutStr("ddsource", incomingLog.Source)
38+
logRecord.Attributes().PutStr("ddtags", incomingLog.Tags)
39+
}
40+
41+
return plogPayload
42+
}

0 commit comments

Comments
 (0)