diff --git a/enrichments/trace/config/config.go b/enrichments/trace/config/config.go index 6bb50f1..ae68e0b 100644 --- a/enrichments/trace/config/config.go +++ b/enrichments/trace/config/config.go @@ -41,6 +41,7 @@ type ScopeConfig struct { // spans which are identified as elastic transaction. type ElasticTransactionConfig struct { TimestampUs AttributeConfig `mapstructure:"timestamp_us"` + Sampled AttributeConfig `mapstructure:"sampled"` ID AttributeConfig `mapstructure:"id"` Root AttributeConfig `mapstructure:"root"` Name AttributeConfig `mapstructure:"name"` @@ -84,6 +85,7 @@ func Enabled() Config { }, Transaction: ElasticTransactionConfig{ TimestampUs: AttributeConfig{Enabled: true}, + Sampled: AttributeConfig{Enabled: true}, ID: AttributeConfig{Enabled: true}, Root: AttributeConfig{Enabled: true}, Name: AttributeConfig{Enabled: true}, diff --git a/enrichments/trace/internal/elastic/attributes.go b/enrichments/trace/internal/elastic/attributes.go index 778bf48..a58a8b7 100644 --- a/enrichments/trace/internal/elastic/attributes.go +++ b/enrichments/trace/internal/elastic/attributes.go @@ -29,6 +29,7 @@ const ( // span attributes AttributeTimestampUs = "timestamp.us" AttributeProcessorEvent = "processor.event" + AttributeTransactionSampled = "transaction.sampled" AttributeTransactionID = "transaction.id" AttributeTransactionRoot = "transaction.root" AttributeTransactionName = "transaction.name" diff --git a/enrichments/trace/internal/elastic/span.go b/enrichments/trace/internal/elastic/span.go index fee81c8..9af40b2 100644 --- a/enrichments/trace/internal/elastic/span.go +++ b/enrichments/trace/internal/elastic/span.go @@ -166,6 +166,9 @@ func (s *spanEnrichmentContext) enrichTransaction( if cfg.TimestampUs.Enabled { s.setTimestampUs(span) } + if cfg.Sampled.Enabled { + span.Attributes().PutBool(AttributeTransactionSampled, true) + } if cfg.ID.Enabled { span.Attributes().PutStr(AttributeTransactionID, span.SpanID().String()) } diff --git a/enrichments/trace/internal/elastic/span_test.go b/enrichments/trace/internal/elastic/span_test.go index 68f0a6f..8fd80f4 100644 --- a/enrichments/trace/internal/elastic/span_test.go +++ b/enrichments/trace/internal/elastic/span_test.go @@ -58,6 +58,7 @@ func TestElasticTransactionEnrich(t *testing.T) { config: config.Enabled().Transaction, enrichedAttrs: map[string]any{ AttributeTimestampUs: int64(0), + AttributeTransactionSampled: true, AttributeTransactionRoot: true, AttributeTransactionID: "", AttributeTransactionName: "", @@ -85,6 +86,7 @@ func TestElasticTransactionEnrich(t *testing.T) { config: config.Enabled().Transaction, enrichedAttrs: map[string]any{ AttributeTimestampUs: int64(0), + AttributeTransactionSampled: true, AttributeTransactionRoot: true, AttributeTransactionID: "", AttributeTransactionName: "", @@ -108,6 +110,7 @@ func TestElasticTransactionEnrich(t *testing.T) { config: config.Enabled().Transaction, enrichedAttrs: map[string]any{ AttributeTimestampUs: startTs.AsTime().UnixMicro(), + AttributeTransactionSampled: true, AttributeTransactionRoot: true, AttributeTransactionID: "0100000000000000", AttributeTransactionName: "testtxn", @@ -137,6 +140,7 @@ func TestElasticTransactionEnrich(t *testing.T) { config: config.Enabled().Transaction, enrichedAttrs: map[string]any{ AttributeTimestampUs: startTs.AsTime().UnixMicro(), + AttributeTransactionSampled: true, AttributeTransactionRoot: true, AttributeTransactionID: "0100000000000000", AttributeTransactionName: "testtxn", @@ -165,6 +169,7 @@ func TestElasticTransactionEnrich(t *testing.T) { config: config.Enabled().Transaction, enrichedAttrs: map[string]any{ AttributeTimestampUs: startTs.AsTime().UnixMicro(), + AttributeTransactionSampled: true, AttributeTransactionRoot: true, AttributeTransactionID: "0100000000000000", AttributeTransactionName: "testtxn", @@ -194,6 +199,7 @@ func TestElasticTransactionEnrich(t *testing.T) { config: config.Enabled().Transaction, enrichedAttrs: map[string]any{ AttributeTimestampUs: startTs.AsTime().UnixMicro(), + AttributeTransactionSampled: true, AttributeTransactionRoot: true, AttributeTransactionID: "0100000000000000", AttributeTransactionName: "testtxn", @@ -223,6 +229,7 @@ func TestElasticTransactionEnrich(t *testing.T) { config: config.Enabled().Transaction, enrichedAttrs: map[string]any{ AttributeTimestampUs: startTs.AsTime().UnixMicro(), + AttributeTransactionSampled: true, AttributeTransactionRoot: true, AttributeTransactionID: "0100000000000000", AttributeTransactionName: "testtxn", @@ -247,6 +254,7 @@ func TestElasticTransactionEnrich(t *testing.T) { config: config.Enabled().Transaction, enrichedAttrs: map[string]any{ AttributeTimestampUs: startTs.AsTime().UnixMicro(), + AttributeTransactionSampled: true, AttributeTransactionRoot: true, AttributeTransactionID: "0100000000000000", AttributeTransactionName: "testtxn", @@ -271,6 +279,7 @@ func TestElasticTransactionEnrich(t *testing.T) { config: config.Enabled().Transaction, enrichedAttrs: map[string]any{ AttributeTimestampUs: startTs.AsTime().UnixMicro(), + AttributeTransactionSampled: true, AttributeTransactionRoot: true, AttributeTransactionID: "0100000000000000", AttributeTransactionName: "testtxn", @@ -295,6 +304,7 @@ func TestElasticTransactionEnrich(t *testing.T) { config: config.Enabled().Transaction, enrichedAttrs: map[string]any{ AttributeTimestampUs: startTs.AsTime().UnixMicro(), + AttributeTransactionSampled: true, AttributeTransactionRoot: true, AttributeTransactionID: "0100000000000000", AttributeTransactionName: "testtxn",