From 8963c5a1da0dbf879adc54ab78de4be28b637fa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vandon?= Date: Tue, 14 Nov 2023 15:54:47 +0100 Subject: [PATCH 1/3] take env variable into account to enable DSM --- contrib/Shopify/sarama/option.go | 4 +++ contrib/Shopify/sarama/option_test.go | 33 +++++++++++++++++++ .../confluent-kafka-go/kafka.v2/option.go | 3 ++ .../kafka.v2/option_test.go | 21 ++++++++++++ .../confluent-kafka-go/kafka/option.go | 3 ++ .../confluent-kafka-go/kafka/option_test.go | 21 ++++++++++++ 6 files changed, 85 insertions(+) create mode 100644 contrib/Shopify/sarama/option_test.go diff --git a/contrib/Shopify/sarama/option.go b/contrib/Shopify/sarama/option.go index f2443b6a82..5613dcdeca 100644 --- a/contrib/Shopify/sarama/option.go +++ b/contrib/Shopify/sarama/option.go @@ -34,6 +34,8 @@ func defaults(cfg *config) { cfg.consumerSpanName = namingschema.NewKafkaInboundOp().GetName() cfg.producerSpanName = namingschema.NewKafkaOutboundOp().GetName() + cfg.dataStreamsEnabled = internal.BoolEnv("DD_DATA_STREAMS_ENABLED", false) + // cfg.analyticsRate = globalconfig.AnalyticsRate() if internal.BoolEnv("DD_TRACE_SARAMA_ANALYTICS_ENABLED", false) { cfg.analyticsRate = 1.0 @@ -54,6 +56,8 @@ func WithServiceName(name string) Option { } // WithDataStreams enables the Data Streams monitoring product features: https://www.datadoghq.com/product/data-streams-monitoring/ +// +// Deprecated: Use the environment variable DD_DATA_STREAMS_ENABLED instead func WithDataStreams() Option { return func(cfg *config) { cfg.dataStreamsEnabled = true diff --git a/contrib/Shopify/sarama/option_test.go b/contrib/Shopify/sarama/option_test.go new file mode 100644 index 0000000000..8b5a39977a --- /dev/null +++ b/contrib/Shopify/sarama/option_test.go @@ -0,0 +1,33 @@ +package sarama + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +func TestDataStreamsActivation(t *testing.T) { + t.Run("default", func(t *testing.T) { + cfg := new(config) + defaults(cfg) + assert.False(t, cfg.dataStreamsEnabled) + }) + t.Run("withOption", func(t *testing.T) { + cfg := new(config) + defaults(cfg) + WithDataStreams()(cfg) + assert.True(t, cfg.dataStreamsEnabled) + }) + t.Run("withEnv", func(t *testing.T) { + t.Setenv("DD_DATA_STREAMS_ENABLED", "true") + cfg := new(config) + defaults(cfg) + assert.True(t, cfg.dataStreamsEnabled) + }) + t.Run("optionOverridesEnv", func(t *testing.T) { + t.Setenv("DD_DATA_STREAMS_ENABLED", "false") + cfg := new(config) + defaults(cfg) + WithDataStreams()(cfg) + assert.True(t, cfg.dataStreamsEnabled) + }) +} diff --git a/contrib/confluentinc/confluent-kafka-go/kafka.v2/option.go b/contrib/confluentinc/confluent-kafka-go/kafka.v2/option.go index d946a426ed..c5891ff820 100644 --- a/contrib/confluentinc/confluent-kafka-go/kafka.v2/option.go +++ b/contrib/confluentinc/confluent-kafka-go/kafka.v2/option.go @@ -41,6 +41,7 @@ func newConfig(opts ...Option) *config { // analyticsRate: globalconfig.AnalyticsRate(), analyticsRate: math.NaN(), } + cfg.dataStreamsEnabled = internal.BoolEnv("DD_DATA_STREAMS_ENABLED", false) if internal.BoolEnv("DD_TRACE_KAFKA_ANALYTICS_ENABLED", false) { cfg.analyticsRate = 1.0 } @@ -129,6 +130,8 @@ func WithConfig(cg *kafka.ConfigMap) Option { } // WithDataStreams enables the Data Streams monitoring product features: https://www.datadoghq.com/product/data-streams-monitoring/ +// +// Deprecated: Use the environment variable DD_DATA_STREAMS_ENABLED instead func WithDataStreams() Option { return func(cfg *config) { cfg.dataStreamsEnabled = true diff --git a/contrib/confluentinc/confluent-kafka-go/kafka.v2/option_test.go b/contrib/confluentinc/confluent-kafka-go/kafka.v2/option_test.go index c97e149801..d990870fc5 100644 --- a/contrib/confluentinc/confluent-kafka-go/kafka.v2/option_test.go +++ b/contrib/confluentinc/confluent-kafka-go/kafka.v2/option_test.go @@ -14,6 +14,27 @@ import ( "github.com/stretchr/testify/assert" ) +func TestDataStreamsActivation(t *testing.T) { + t.Run("default", func(t *testing.T) { + cfg := newConfig() + assert.False(t, cfg.dataStreamsEnabled) + }) + t.Run("withOption", func(t *testing.T) { + cfg := newConfig(WithDataStreams()) + assert.True(t, cfg.dataStreamsEnabled) + }) + t.Run("withEnv", func(t *testing.T) { + t.Setenv("DD_DATA_STREAMS_ENABLED", "true") + cfg := newConfig() + assert.True(t, cfg.dataStreamsEnabled) + }) + t.Run("optionOverridesEnv", func(t *testing.T) { + t.Setenv("DD_DATA_STREAMS_ENABLED", "false") + cfg := newConfig(WithDataStreams()) + assert.True(t, cfg.dataStreamsEnabled) + }) +} + func TestAnalyticsSettings(t *testing.T) { t.Run("defaults", func(t *testing.T) { cfg := newConfig() diff --git a/contrib/confluentinc/confluent-kafka-go/kafka/option.go b/contrib/confluentinc/confluent-kafka-go/kafka/option.go index 514f54fff0..2b37f0972c 100644 --- a/contrib/confluentinc/confluent-kafka-go/kafka/option.go +++ b/contrib/confluentinc/confluent-kafka-go/kafka/option.go @@ -41,6 +41,7 @@ func newConfig(opts ...Option) *config { // analyticsRate: globalconfig.AnalyticsRate(), analyticsRate: math.NaN(), } + cfg.dataStreamsEnabled = internal.BoolEnv("DD_DATA_STREAMS_ENABLED", false) if internal.BoolEnv("DD_TRACE_KAFKA_ANALYTICS_ENABLED", false) { cfg.analyticsRate = 1.0 } @@ -129,6 +130,8 @@ func WithConfig(cg *kafka.ConfigMap) Option { } // WithDataStreams enables the Data Streams monitoring product features: https://www.datadoghq.com/product/data-streams-monitoring/ +// +// Deprecated: Use the environment variable DD_DATA_STREAMS_ENABLED instead func WithDataStreams() Option { return func(cfg *config) { cfg.dataStreamsEnabled = true diff --git a/contrib/confluentinc/confluent-kafka-go/kafka/option_test.go b/contrib/confluentinc/confluent-kafka-go/kafka/option_test.go index c97e149801..d990870fc5 100644 --- a/contrib/confluentinc/confluent-kafka-go/kafka/option_test.go +++ b/contrib/confluentinc/confluent-kafka-go/kafka/option_test.go @@ -14,6 +14,27 @@ import ( "github.com/stretchr/testify/assert" ) +func TestDataStreamsActivation(t *testing.T) { + t.Run("default", func(t *testing.T) { + cfg := newConfig() + assert.False(t, cfg.dataStreamsEnabled) + }) + t.Run("withOption", func(t *testing.T) { + cfg := newConfig(WithDataStreams()) + assert.True(t, cfg.dataStreamsEnabled) + }) + t.Run("withEnv", func(t *testing.T) { + t.Setenv("DD_DATA_STREAMS_ENABLED", "true") + cfg := newConfig() + assert.True(t, cfg.dataStreamsEnabled) + }) + t.Run("optionOverridesEnv", func(t *testing.T) { + t.Setenv("DD_DATA_STREAMS_ENABLED", "false") + cfg := newConfig(WithDataStreams()) + assert.True(t, cfg.dataStreamsEnabled) + }) +} + func TestAnalyticsSettings(t *testing.T) { t.Run("defaults", func(t *testing.T) { cfg := newConfig() From 40da99a26c449eb532a0742f3e395280dfc2d95d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vandon?= Date: Tue, 14 Nov 2023 16:08:54 +0100 Subject: [PATCH 2/3] add copyright --- contrib/Shopify/sarama/option_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/contrib/Shopify/sarama/option_test.go b/contrib/Shopify/sarama/option_test.go index 8b5a39977a..d2bba4fed8 100644 --- a/contrib/Shopify/sarama/option_test.go +++ b/contrib/Shopify/sarama/option_test.go @@ -1,3 +1,8 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016 Datadog, Inc. + package sarama import ( From 9cd3d19033ba1c4a2a7a93024d15b2da04ccfe7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vandon?= Date: Wed, 15 Nov 2023 10:52:20 +0100 Subject: [PATCH 3/3] un-deprecate configuration via options --- contrib/Shopify/sarama/option.go | 2 -- contrib/confluentinc/confluent-kafka-go/kafka.v2/option.go | 2 -- contrib/confluentinc/confluent-kafka-go/kafka/option.go | 2 -- 3 files changed, 6 deletions(-) diff --git a/contrib/Shopify/sarama/option.go b/contrib/Shopify/sarama/option.go index 5613dcdeca..1c574d9680 100644 --- a/contrib/Shopify/sarama/option.go +++ b/contrib/Shopify/sarama/option.go @@ -56,8 +56,6 @@ func WithServiceName(name string) Option { } // WithDataStreams enables the Data Streams monitoring product features: https://www.datadoghq.com/product/data-streams-monitoring/ -// -// Deprecated: Use the environment variable DD_DATA_STREAMS_ENABLED instead func WithDataStreams() Option { return func(cfg *config) { cfg.dataStreamsEnabled = true diff --git a/contrib/confluentinc/confluent-kafka-go/kafka.v2/option.go b/contrib/confluentinc/confluent-kafka-go/kafka.v2/option.go index c5891ff820..767686957a 100644 --- a/contrib/confluentinc/confluent-kafka-go/kafka.v2/option.go +++ b/contrib/confluentinc/confluent-kafka-go/kafka.v2/option.go @@ -130,8 +130,6 @@ func WithConfig(cg *kafka.ConfigMap) Option { } // WithDataStreams enables the Data Streams monitoring product features: https://www.datadoghq.com/product/data-streams-monitoring/ -// -// Deprecated: Use the environment variable DD_DATA_STREAMS_ENABLED instead func WithDataStreams() Option { return func(cfg *config) { cfg.dataStreamsEnabled = true diff --git a/contrib/confluentinc/confluent-kafka-go/kafka/option.go b/contrib/confluentinc/confluent-kafka-go/kafka/option.go index 2b37f0972c..aeb1526ed7 100644 --- a/contrib/confluentinc/confluent-kafka-go/kafka/option.go +++ b/contrib/confluentinc/confluent-kafka-go/kafka/option.go @@ -130,8 +130,6 @@ func WithConfig(cg *kafka.ConfigMap) Option { } // WithDataStreams enables the Data Streams monitoring product features: https://www.datadoghq.com/product/data-streams-monitoring/ -// -// Deprecated: Use the environment variable DD_DATA_STREAMS_ENABLED instead func WithDataStreams() Option { return func(cfg *config) { cfg.dataStreamsEnabled = true