Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[exporter/datadogexporter] Add logs support #13987

Merged
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9827d6c
fix gosum
dineshg13 Sep 8, 2022
319d550
fix lint issues + gotidy
dineshg13 Sep 8, 2022
f35b11a
fix lint issues + gotidy
dineshg13 Sep 8, 2022
188386d
PR Comments
dineshg13 Sep 9, 2022
583a265
PR comments - add more tests
dineshg13 Sep 13, 2022
c81b71f
merge upstream
dineshg13 Sep 13, 2022
4c263f8
update readme
dineshg13 Sep 13, 2022
d829f7f
PR comments - add more tests
dineshg13 Sep 14, 2022
5158d95
Merge remote-tracking branch 'upstream/main' into dinesh.gurumurthy/a…
dineshg13 Sep 15, 2022
536cc65
update tests
dineshg13 Sep 15, 2022
6c9910b
fix tests + remove deprecated methods
dineshg13 Sep 15, 2022
bc2fee3
merge upstream
dineshg13 Sep 15, 2022
51a9da1
PR comments
dineshg13 Sep 16, 2022
246084b
PR comments: change the default
dineshg13 Sep 16, 2022
06146ed
merge upstream + resolve conflicts
dineshg13 Sep 19, 2022
b2320cd
merge upstream + resolve conflicts
dineshg13 Sep 22, 2022
de8ff07
PR comments
dineshg13 Sep 23, 2022
6fa1b9f
merge upstream + resolve conflicts
dineshg13 Sep 25, 2022
16e7c3f
remove duplicate test
dineshg13 Sep 25, 2022
172e02d
revert un-needed comment change
dineshg13 Sep 25, 2022
5a4429e
PR comments
dineshg13 Sep 26, 2022
f246e2f
Merge remote-tracking branch 'upstream/main' into dinesh.gurumurthy/a…
dineshg13 Sep 27, 2022
5645641
PR comments + remove send_log_record
dineshg13 Sep 27, 2022
c8b974b
modify tests
dineshg13 Sep 27, 2022
520fcb2
Merge remote-tracking branch 'upstream/main' into dinesh.gurumurthy/a…
dineshg13 Sep 27, 2022
dce3249
fix lint issues
dineshg13 Sep 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/configschema/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ require (
github.com/DataDog/datadog-agent/pkg/util/cgroups v0.40.0-rc.2 // indirect
github.com/DataDog/datadog-agent/pkg/util/log v0.40.0-rc.2 // indirect
github.com/DataDog/datadog-agent/pkg/util/scrubber v0.40.0-rc.2 // indirect
github.com/DataDog/datadog-api-client-go/v2 v2.2.0 // indirect
github.com/DataDog/datadog-go/v5 v5.1.1 // indirect
github.com/DataDog/gohai v0.0.0-20220718130825-1776f9beb9cc // indirect
github.com/DataDog/sketches-go v1.4.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions cmd/configschema/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions exporter/datadogexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

| Status | |
| ------------------------ |------------------|
| Stability | [beta] |
| Supported pipeline types | traces, metrics |
| Stability | traces [beta] |
| | metrics [beta] |
| | logs [alpha] |
| Supported pipeline types | traces, metrics, logs|
| Distributions | [contrib], [AWS] |

This exporter sends metric and trace data to [Datadog](https://datadoghq.com). For environment specific setup instructions visit the [Datadog Documentation](https://docs.datadoghq.com/tracing/setup_overview/open_standards/otel_collector_datadog_exporter/).

This exporter sends metric, traces and logs to [Datadog](https://datadoghq.com). For environment specific setup instructions visit the [Datadog Documentation](https://docs.datadoghq.com/tracing/setup_overview/open_standards/otel_collector_datadog_exporter/).

> Please review the Collector's [security
> documentation](https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/security.md),
Expand Down Expand Up @@ -53,5 +56,6 @@ Retry settings will only affect metrics.
*Please Note:* Currently [Span Events](https://github.com/open-telemetry/opentelemetry-specification/blob/11cc73939a32e3a2e6f11bdeab843c61cf8594e9/specification/trace/api.md#add-events) are extracted and added to Spans as Json on the Datadog Span Tag `events`.

[beta]:https://github.com/open-telemetry/opentelemetry-collector#beta
[alpha]:https://github.com/open-telemetry/opentelemetry-collector#alpha
[contrib]:https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
[AWS]:https://aws-otel.github.io/docs/partners/datadog
20 changes: 20 additions & 0 deletions exporter/datadogexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,19 @@ type TracesConfig struct {
flushInterval float64
}

// LogsConfig defines logs exporter specific configuration
type LogsConfig struct {
// TCPAddr.Endpoint is the host of the Datadog intake server to send logs to.
// If unset, the value is obtained from the Site.
confignet.TCPAddr `mapstructure:",squash"`

// SendLogRecordBody when enabled would send string representation of body field of log record as message to Datadog
// By default this is enabled ,when we parse the body string into attributes we may want to disable
// Set this to true, if we are unable to parse body or we want use datadog backend for parsing
// It is essential for Log Trace correlation to work, that we parse the body before reaching exporter.
mx-psi marked this conversation as resolved.
Show resolved Hide resolved
SendLogRecordBody bool `mapstructure:"send_log_record_body"`
mx-psi marked this conversation as resolved.
Show resolved Hide resolved
}

// TagsConfig defines the tag-related configuration
// It is embedded in the configuration
type TagsConfig struct {
Expand Down Expand Up @@ -339,6 +352,9 @@ type Config struct {
// Traces defines the Traces exporter specific configuration
Traces TracesConfig `mapstructure:"traces"`

// Logs defines the Logs exporter specific configuration
Logs LogsConfig `mapstructure:"logs"`

// HostMetadata defines the host metadata specific configuration
HostMetadata HostMetadataConfig `mapstructure:"host_metadata"`

Expand Down Expand Up @@ -483,5 +499,9 @@ func (c *Config) Unmarshal(configMap *confmap.Conf) error {
if !configMap.IsSet("traces::endpoint") {
c.Traces.TCPAddr.Endpoint = fmt.Sprintf("https://trace.agent.%s", c.API.Site)
}
if !configMap.IsSet("logs::endpoint") {
// this is v2 endpoint
dineshg13 marked this conversation as resolved.
Show resolved Hide resolved
c.Logs.TCPAddr.Endpoint = fmt.Sprintf("https://http-intake.logs.%s", c.API.Site)
}
return nil
}
60 changes: 59 additions & 1 deletion exporter/datadogexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/pdata/ptrace"

Expand All @@ -39,7 +40,8 @@ const (
// typeStr is the type of the exporter
typeStr = "datadog"
// The stability level of the exporter.
stability = component.StabilityLevelBeta
stability = component.StabilityLevelBeta
logsStability = component.StabilityLevelAlpha
mx-psi marked this conversation as resolved.
Show resolved Hide resolved
)

type factory struct {
Expand All @@ -66,6 +68,7 @@ func newFactoryWithRegistry(registry *featuregate.Registry) component.ExporterFa
f.createDefaultConfig,
component.WithMetricsExporter(f.createMetricsExporter, stability),
component.WithTracesExporter(f.createTracesExporter, stability),
component.WithLogsExporter(f.createLogsExporter, logsStability),
)
}

Expand Down Expand Up @@ -125,6 +128,13 @@ func (f *factory) createDefaultConfig() config.Exporter {
IgnoreResources: []string{},
},

Logs: LogsConfig{
TCPAddr: confignet.TCPAddr{
Endpoint: "https://http-intake.logs.datadoghq.com",
},
SendLogRecordBody: true,
},

HostMetadata: HostMetadataConfig{
Enabled: true,
HostnameSource: hostnameSource,
Expand Down Expand Up @@ -264,3 +274,51 @@ func (f *factory) createTracesExporter(
exporterhelper.WithShutdown(stop),
)
}

// createLogsExporter creates a trace exporter based on this config.
mx-psi marked this conversation as resolved.
Show resolved Hide resolved
func (f *factory) createLogsExporter(
ctx context.Context,
set component.ExporterCreateSettings,
c config.Exporter,
) (component.LogsExporter, error) {
cfg := checkAndCastConfig(c)

var pusher consumer.ConsumeLogsFunc
hostProvider, err := f.SourceProvider(set.TelemetrySettings, cfg.Hostname)
if err != nil {
return nil, fmt.Errorf("failed to build hostname provider: %w", err)
}
ctx, cancel := context.WithCancel(ctx)
dineshg13 marked this conversation as resolved.
Show resolved Hide resolved
// cancel() runs on shutdown
if cfg.OnlyMetadata {
// only host metadata needs to be sent, once.
pusher = func(_ context.Context, td plog.Logs) error {
f.onceMetadata.Do(func() {
attrs := pcommon.NewMap()
go metadata.Pusher(ctx, set, newMetadataConfigfromConfig(cfg), hostProvider, attrs)
mx-psi marked this conversation as resolved.
Show resolved Hide resolved
})
return nil
}
} else {
exp, err := newLogsExporter(ctx, set, cfg, &f.onceMetadata, hostProvider)
if err != nil {
cancel()
return nil, err
}
pusher = exp.consumeLogs
}

return exporterhelper.NewLogsExporter(
dineshg13 marked this conversation as resolved.
Show resolved Hide resolved
ctx,
set,
cfg,
pusher,
exporterhelper.WithTimeout(exporterhelper.TimeoutSettings{Timeout: 0 * time.Second}),
mx-psi marked this conversation as resolved.
Show resolved Hide resolved
exporterhelper.WithRetry(cfg.RetrySettings),
mx-psi marked this conversation as resolved.
Show resolved Hide resolved
exporterhelper.WithQueue(cfg.QueueSettings),
exporterhelper.WithShutdown(func(context.Context) error {
cancel()
return nil
}),
)
}
Loading