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

contrib/kafka: take env variable into account to enable DSM #2353

Merged
merged 4 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all 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 contrib/Shopify/sarama/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions contrib/Shopify/sarama/option_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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 (
"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)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
21 changes: 21 additions & 0 deletions contrib/confluentinc/confluent-kafka-go/kafka.v2/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions contrib/confluentinc/confluent-kafka-go/kafka/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
21 changes: 21 additions & 0 deletions contrib/confluentinc/confluent-kafka-go/kafka/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading