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

Bump to opentelemetry-mapping-go v0.11.0 #21740

Merged
merged 9 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
2 changes: 2 additions & 0 deletions .copyright-overrides.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ github.com/dgraph-io/badger:
- "Copyright 2020 Dgraph Labs, Inc. and Contributors"
- "Copyright 2021 Dgraph Labs, Inc. and Contributors"
github.com/mostynb/go-grpc-compression: "Copyright 2023 Mostyn Bramley-Moore."
github.com/pjbgf/sha1cd: "Copyright 2009 The Go Authors"
mx-psi marked this conversation as resolved.
Show resolved Hide resolved
github.com/stormcat24/protodep: "Copyright Akinori Yamada"

# These have large AUTHORS/CONTRIBUTORS files but attribute copyright as a group
github.com/aptly-dev/aptly: Copyright 2013-2015 aptly authors. All rights reserved.
Expand Down
8 changes: 8 additions & 0 deletions LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@ core,github.com/go-git/go-git/v5/plumbing/format/index,Apache-2.0,"Copyright 201
core,github.com/go-git/go-git/v5/plumbing/format/objfile,Apache-2.0,"Copyright 2018 Sourced Technologies, S.L"
core,github.com/go-git/go-git/v5/plumbing/format/packfile,Apache-2.0,"Copyright 2018 Sourced Technologies, S.L"
core,github.com/go-git/go-git/v5/plumbing/format/pktline,Apache-2.0,"Copyright 2018 Sourced Technologies, S.L"
core,github.com/go-git/go-git/v5/plumbing/hash,Apache-2.0,"Copyright 2018 Sourced Technologies, S.L"
core,github.com/go-git/go-git/v5/plumbing/object,Apache-2.0,"Copyright 2018 Sourced Technologies, S.L"
core,github.com/go-git/go-git/v5/plumbing/protocol/packp,Apache-2.0,"Copyright 2018 Sourced Technologies, S.L"
core,github.com/go-git/go-git/v5/plumbing/protocol/packp/capability,Apache-2.0,"Copyright 2018 Sourced Technologies, S.L"
Expand All @@ -831,6 +832,7 @@ core,github.com/go-git/go-git/v5/utils/merkletrie/filesystem,Apache-2.0,"Copyrig
core,github.com/go-git/go-git/v5/utils/merkletrie/index,Apache-2.0,"Copyright 2018 Sourced Technologies, S.L"
core,github.com/go-git/go-git/v5/utils/merkletrie/internal/frame,Apache-2.0,"Copyright 2018 Sourced Technologies, S.L"
core,github.com/go-git/go-git/v5/utils/merkletrie/noder,Apache-2.0,"Copyright 2018 Sourced Technologies, S.L"
core,github.com/go-git/go-git/v5/utils/sync,Apache-2.0,"Copyright 2018 Sourced Technologies, S.L"
core,github.com/go-ini/ini,Apache-2.0,Copyright 2014 Unknwon
core,github.com/go-kit/log,MIT,Copyright (c) 2021 Go kit
core,github.com/go-kit/log/level,MIT,Copyright (c) 2021 Go kit
Expand Down Expand Up @@ -1341,6 +1343,9 @@ core,github.com/pierrec/lz4/v4/internal/lz4block,BSD-3-Clause,"Copyright (c) 201
core,github.com/pierrec/lz4/v4/internal/lz4errors,BSD-3-Clause,"Copyright (c) 2015, Pierre Curto"
core,github.com/pierrec/lz4/v4/internal/lz4stream,BSD-3-Clause,"Copyright (c) 2015, Pierre Curto"
core,github.com/pierrec/lz4/v4/internal/xxh32,BSD-3-Clause,"Copyright (c) 2015, Pierre Curto"
core,github.com/pjbgf/sha1cd,Apache-2.0,Copyright 2009 The Go Authors
core,github.com/pjbgf/sha1cd/internal,Apache-2.0,Copyright 2009 The Go Authors
core,github.com/pjbgf/sha1cd/ubc,Apache-2.0,Copyright 2009 The Go Authors
core,github.com/pkg/errors,BSD-2-Clause,"Copyright (c) 2015, Dave Cheney <dave@cheney.net>"
core,github.com/pmezard/go-difflib/difflib,BSD-3-Clause,"Copyright (c) 2013, Patrick Mezard"
core,github.com/power-devops/perfstat,MIT,Copyright (c) 2020 Power DevOps
Expand Down Expand Up @@ -1412,6 +1417,7 @@ core,github.com/sijms/go-ora/v2/network/security,MIT,Copyright (c) 2020 Samy Sul
core,github.com/sijms/go-ora/v2/network/security/md4,MIT,Copyright (c) 2020 Samy Sultan
core,github.com/sijms/go-ora/v2/trace,MIT,Copyright (c) 2020 Samy Sultan
core,github.com/sirupsen/logrus,MIT,Copyright (c) 2014 Simon Eskildsen
core,github.com/skeema/knownhosts,Apache-2.0,Copyright 2023 Skeema LLC and the Skeema authors | copyright 2023 Skeema LLC and the Skeema authors**
core,github.com/skydive-project/go-debouncer,Apache-2.0,"Copyright (C) 2018 Red Hat, Inc."
core,github.com/smira/go-ftp-protocol/protocol,MIT,Copyright (c) 2014 Andrey Smirnov
core,github.com/smira/go-xz,MIT,Copyright (c) 2015 Andrey Smirnov
Expand All @@ -1437,6 +1443,8 @@ core,github.com/spf13/cobra,Apache-2.0,Copyright © 2013 Steve Francia <spf@spf1
core,github.com/spf13/jwalterweatherman,MIT,Copyright (c) 2014 Steve Francia
core,github.com/spf13/pflag,BSD-3-Clause,Copyright (c) 2012 Alex Ogier. All rights reserved | Copyright (c) 2012 The Go Authors. All rights reserved
core,github.com/stoewer/go-strcase,MIT,"Copyright (c) 2017, Adrian Stoewer <adrian.stoewer@rz.ifi.lmu.de>"
core,github.com/stormcat24/protodep,Apache-2.0,Copyright Akinori Yamada
core,github.com/stormcat24/protodep/pkg/logger,Apache-2.0,Copyright Akinori Yamada
core,github.com/streadway/amqp,BSD-2-Clause,"Copyright (c) 2012-2019, Sean Treadway, SoundCloud Ltd"
core,github.com/stretchr/objx,MIT,"Copyright (c) 2014 Stretchr, Inc | Copyright (c) 2017-2018 objx contributors"
core,github.com/stretchr/testify/assert,MIT,"Copyright (c) 2012-2020 Mat Ryer, Tyler Bunnell and contributors"
Expand Down
18 changes: 15 additions & 3 deletions comp/otelcol/otlp/internal/logsagentexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/DataDog/datadog-agent/comp/logs/agent/config"
"github.com/DataDog/datadog-agent/pkg/logs/message"
"github.com/DataDog/datadog-agent/pkg/logs/sources"
"github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes"
"go.opentelemetry.io/collector/component"
exp "go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exporterhelper"
Expand Down Expand Up @@ -46,15 +47,26 @@ func (f *factory) createLogsExporter(
) (exp.Logs, error) {
logSource := sources.NewLogSource(logSourceName, &config.LogsConfig{})

// TODO: Ideally the attributes translator would be created once and reused
// across all signals. This would need unifying the logsagent and serializer
// exporters into a single exporter.
attributesTranslator, err := attributes.NewTranslator(set.TelemetrySettings)
if err != nil {
return nil, err
}

exporter, err := newExporter(set.TelemetrySettings, logSource, f.logsAgentChannel, attributesTranslator)
if err != nil {
return nil, err
}

ctx, cancel := context.WithCancel(ctx)
// cancel() runs on shutdown
pusher := createConsumeLogsFunc(set.TelemetrySettings.Logger, logSource, f.logsAgentChannel)

return exporterhelper.NewLogsExporter(
ctx,
set,
c,
pusher,
exporter.ConsumeLogs,
exporterhelper.WithShutdown(func(context.Context) error {
cancel()
return nil
Expand Down
128 changes: 67 additions & 61 deletions comp/otelcol/otlp/internal/logsagentexporter/logs_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,79 +14,85 @@ import (
"github.com/DataDog/datadog-agent/pkg/logs/message"
"github.com/DataDog/datadog-agent/pkg/logs/sources"
"github.com/DataDog/datadog-agent/pkg/util/scrubber"
"go.uber.org/zap"
"github.com/stormcat24/protodep/pkg/logger"

"github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes"
logsmapping "github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/logs"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/pdata/plog"
)

// otelTag specifies a tag to be added to all logs sent from the Datadog Agent
const otelTag = "otel_source:datadog_agent"
// otelSource specifies a source to be added to all logs sent from the Datadog Agent.
// The tag has key `otel_source` and the value specified on this constant.
const otelSource = "datadog_agent"

// createConsumeLogsFunc returns an implementation of consumer.ConsumeLogsFunc
func createConsumeLogsFunc(logger *zap.Logger, logSource *sources.LogSource, logsAgentChannel chan *message.Message) func(context.Context, plog.Logs) error {

return func(_ context.Context, ld plog.Logs) (err error) {
defer func() {
if err != nil {
newErr, scrubbingErr := scrubber.ScrubString(err.Error())
if scrubbingErr != nil {
err = scrubbingErr
} else {
err = errors.New(newErr)
}
}
}()
type exporter struct {
set component.TelemetrySettings
logsAgentChannel chan *message.Message
logSource *sources.LogSource
translator *logsmapping.Translator
}

rsl := ld.ResourceLogs()
// Iterate over resource logs
for i := 0; i < rsl.Len(); i++ {
rl := rsl.At(i)
sls := rl.ScopeLogs()
res := rl.Resource()
for j := 0; j < sls.Len(); j++ {
sl := sls.At(j)
lsl := sl.LogRecords()
// iterate over Logs
for k := 0; k < lsl.Len(); k++ {
log := lsl.At(k)
ddLog := logsmapping.Transform(log, res, logger)
func newExporter(
set component.TelemetrySettings,
logSource *sources.LogSource,
logsAgentChannel chan *message.Message,
attributesTranslator *attributes.Translator,
) (*exporter, error) {
translator, err := logsmapping.NewTranslator(set, attributesTranslator, otelSource)
if err != nil {
return nil, err
}

var tags []string
if ddTags := ddLog.GetDdtags(); ddTags == "" {
tags = []string{otelTag}
} else {
tags = append(strings.Split(ddTags, ","), otelTag)
}
// Tags are set in the message origin instead
ddLog.Ddtags = nil
service := ""
if ddLog.Service != nil {
service = *ddLog.Service
}
status := ddLog.AdditionalProperties["status"]
if status == "" {
status = message.StatusInfo
}
origin := message.NewOrigin(logSource)
origin.SetTags(tags)
origin.SetService(service)
origin.SetSource(logSourceName)
return &exporter{
set: set,
logsAgentChannel: logsAgentChannel,
logSource: logSource,
translator: translator,
}, nil
}

content, err := ddLog.MarshalJSON()
if err != nil {
logger.Error("Error parsing log: " + err.Error())
}
func (e *exporter) ConsumeLogs(ctx context.Context, ld plog.Logs) (err error) {
defer func() {
if err != nil {
newErr, scrubbingErr := scrubber.ScrubString(err.Error())
if scrubbingErr != nil {
err = scrubbingErr
} else {
err = errors.New(newErr)
}
}
}()

// ingestionTs is an internal field used for latency tracking on the status page, not the actual log timestamp.
ingestionTs := time.Now().UnixNano()
message := message.NewMessage(content, origin, status, ingestionTs)
payloads := e.translator.MapLogs(ctx, ld)
for _, ddLog := range payloads {
tags := strings.Split(ddLog.GetDdtags(), ",")
// Tags are set in the message origin instead
ddLog.Ddtags = nil
service := ""
if ddLog.Service != nil {
service = *ddLog.Service
}
status := ddLog.AdditionalProperties["status"]
if status == "" {
status = message.StatusInfo
}
origin := message.NewOrigin(e.logSource)
origin.SetTags(tags)
origin.SetService(service)
origin.SetSource(logSourceName)

logsAgentChannel <- message
}
}
content, err := ddLog.MarshalJSON()
if err != nil {
logger.Error("Error parsing log: " + err.Error())
}

return nil
// ingestionTs is an internal field used for latency tracking on the status page, not the actual log timestamp.
ingestionTs := time.Now().UnixNano()
message := message.NewMessage(content, origin, status, ingestionTs)

e.logsAgentChannel <- message
}

return nil
}
9 changes: 5 additions & 4 deletions comp/otelcol/otlp/internal/serializerexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"context"
"fmt"

"github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes"
"github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes/source"
"github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics"
"go.opentelemetry.io/collector/component"
Expand Down Expand Up @@ -80,7 +81,7 @@ type exporter struct {
cardinality collectors.TagCardinality
}

func translatorFromConfig(set component.TelemetrySettings, cfg *exporterConfig) (*metrics.Translator, error) {
func translatorFromConfig(set component.TelemetrySettings, attributesTranslator *attributes.Translator, cfg *exporterConfig) (*metrics.Translator, error) {
histogramMode := metrics.HistogramMode(cfg.Metrics.HistConfig.Mode)
switch histogramMode {
case metrics.HistogramModeCounters, metrics.HistogramModeNoBuckets, metrics.HistogramModeDistributions:
Expand Down Expand Up @@ -127,16 +128,16 @@ func translatorFromConfig(set component.TelemetrySettings, cfg *exporterConfig)
options = append(options, metrics.WithInitialCumulMonoValueMode(
metrics.InitialCumulMonoValueMode(cfg.Metrics.SumConfig.InitialCumulativeMonotonicMode)))

return metrics.NewTranslator(set, options...)
return metrics.NewTranslator(set, attributesTranslator, options...)
}

func newExporter(set component.TelemetrySettings, s serializer.MetricSerializer, cfg *exporterConfig) (*exporter, error) {
func newExporter(set component.TelemetrySettings, attributesTranslator *attributes.Translator, s serializer.MetricSerializer, cfg *exporterConfig) (*exporter, error) {
// Log any warnings from unmarshaling.
for _, warning := range cfg.warnings {
set.Logger.Warn(warning)
}

tr, err := translatorFromConfig(set, cfg)
tr, err := translatorFromConfig(set, attributesTranslator, cfg)
if err != nil {
return nil, fmt.Errorf("incorrect OTLP metrics configuration: %w", err)
}
Expand Down
24 changes: 12 additions & 12 deletions comp/otelcol/otlp/internal/serializerexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/exporter/exportertest"
"go.opentelemetry.io/collector/pdata/pmetric"

"github.com/DataDog/datadog-agent/pkg/config"
Expand Down Expand Up @@ -190,19 +192,17 @@ func Test_ConsumeMetrics_Tags(t *testing.T) {
tt.setConfig(t)
}
rec := &metricRecorder{}
exp, err := newExporter(
componenttest.NewNopTelemetrySettings(),
rec,
NewFactory(rec).CreateDefaultConfig().(*exporterConfig),
ctx := context.Background()
f := NewFactory(rec)
exp, err := f.CreateMetricsExporter(
ctx,
exportertest.NewNopCreateSettings(),
f.CreateDefaultConfig(),
)
if err != nil {
t.Errorf("newExporter() returns unexpected error: %v", err)
return
}
if err := exp.ConsumeMetrics(context.Background(), tt.genMetrics(t)); err != nil {
t.Errorf("ConsumeMetrics() returns unexpected error: %v", err)
return
}
require.NoError(t, err)
require.NoError(t, exp.Start(ctx, componenttest.NewNopHost()))
require.NoError(t, exp.ConsumeMetrics(ctx, tt.genMetrics(t)))
require.NoError(t, exp.Shutdown(ctx))

if tt.wantSketchTags.Len() > 0 {
assert.Equal(t, tt.wantSketchTags, rec.sketchSeriesList[0].Tags)
Expand Down
11 changes: 10 additions & 1 deletion comp/otelcol/otlp/internal/serializerexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package serializerexporter
import (
"context"

"github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
Expand Down Expand Up @@ -41,7 +42,15 @@ func NewFactory(s serializer.MetricSerializer) exp.Factory {
func (f *factory) createMetricExporter(ctx context.Context, params exp.CreateSettings, c component.Config) (exp.Metrics, error) {
cfg := c.(*exporterConfig)

newExp, err := newExporter(params.TelemetrySettings, f.s, cfg)
// TODO: Ideally the attributes translator would be created once and reused
// across all signals. This would need unifying the logsagent and serializer
// exporters into a single exporter.
attributesTranslator, err := attributes.NewTranslator(params.TelemetrySettings)
if err != nil {
return nil, err
}

newExp, err := newExporter(params.TelemetrySettings, attributesTranslator, f.s, cfg)
if err != nil {
return nil, err
}
Expand Down
11 changes: 11 additions & 0 deletions comp/trace/config/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
rc "github.com/DataDog/datadog-agent/pkg/config/remote/client"
"github.com/DataDog/datadog-agent/pkg/config/remote/data"
"github.com/DataDog/datadog-agent/pkg/config/utils"
"github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes"
"go.opentelemetry.io/collector/component/componenttest"

//nolint:revive // TODO(APM) Fix revive linter
configUtils "github.com/DataDog/datadog-agent/pkg/config/utils"
Expand Down Expand Up @@ -345,13 +347,22 @@ func applyDatadogConfig(c *config.AgentConfig, core corecompcfg.Component) error
if otlp.IsEnabled(coreconfig.Datadog) {
grpcPort = core.GetInt(coreconfig.OTLPTracePort)
}

// We use a noop set of telemetry settings. This silences all warnings and metrics from the attributes translator.
// The Datadog exporter overrides this with its own attributes translator using its own telemetry settings.
attributesTranslator, err := attributes.NewTranslator(componenttest.NewNopTelemetrySettings())
if err != nil {
return err
}

c.OTLPReceiver = &config.OTLP{
BindHost: c.ReceiverHost,
GRPCPort: grpcPort,
MaxRequestBytes: c.MaxRequestBytes,
SpanNameRemappings: coreconfig.Datadog.GetStringMapString("otlp_config.traces.span_name_remappings"),
SpanNameAsResourceName: core.GetBool("otlp_config.traces.span_name_as_resource_name"),
ProbabilisticSampling: core.GetFloat64("otlp_config.traces.probabilistic_sampler.sampling_percentage"),
AttributesTranslator: attributesTranslator,
}

if core.IsSet("apm_config.install_id") {
Expand Down
Loading
Loading