Skip to content

Commit 823b737

Browse files
Update transaction enrichment to clear the span ID and span Name. Remove span ID and Name enrichment(#254)
* Update transaction enrichment to set clear the span id and span name This allows the span id and name to be only represented by the elastic attributes (`transaction.id` , `transaction.name`) only * Remove span.id and span.name enrichment since it is not required, the elasticsearch exporter will add these fields based on the span top-level ID and Name fields
1 parent b2001c4 commit 823b737

File tree

4 files changed

+34
-84
lines changed

4 files changed

+34
-84
lines changed

enrichments/config/config.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,21 @@ type ElasticTransactionConfig struct {
4949
// TimestampUs is a temporary attribute to enable higher
5050
// resolution timestamps in Elasticsearch. For more details see:
5151
// https://github.com/elastic/opentelemetry-dev/issues/374.
52-
TimestampUs AttributeConfig `mapstructure:"timestamp_us"`
53-
Sampled AttributeConfig `mapstructure:"sampled"`
54-
ID AttributeConfig `mapstructure:"id"`
55-
Root AttributeConfig `mapstructure:"root"`
56-
Name AttributeConfig `mapstructure:"name"`
52+
TimestampUs AttributeConfig `mapstructure:"timestamp_us"`
53+
Sampled AttributeConfig `mapstructure:"sampled"`
54+
ID AttributeConfig `mapstructure:"id"`
55+
// ClearSpanID sets the span ID to an empty value so that the
56+
// ID is only represented by the `transaction.id` attribute.
57+
// Applicable only when ID is enabled.
58+
// Disabled by default.
59+
ClearSpanID AttributeConfig `mapstructure:"clear_span_id"`
60+
Root AttributeConfig `mapstructure:"root"`
61+
Name AttributeConfig `mapstructure:"name"`
62+
// ClearSpanName sets the span name to an empty value so that the
63+
// name is only represented by the `transaction.name` attribute.
64+
// Applicable only when Name is enabled.
65+
// Disabled by default.
66+
ClearSpanName AttributeConfig `mapstructure:"clear_span_name"`
5767
ProcessorEvent AttributeConfig `mapstructure:"processor_event"`
5868
RepresentativeCount AttributeConfig `mapstructure:"representative_count"`
5969
DurationUs AttributeConfig `mapstructure:"duration_us"`
@@ -73,8 +83,6 @@ type ElasticSpanConfig struct {
7383
// resolution timestamps in Elasticsearch. For more details see:
7484
// https://github.com/elastic/opentelemetry-dev/issues/374.
7585
TimestampUs AttributeConfig `mapstructure:"timestamp_us"`
76-
ID AttributeConfig `mapstructure:"id"`
77-
Name AttributeConfig `mapstructure:"name"`
7886
ProcessorEvent AttributeConfig `mapstructure:"processor_event"`
7987
RepresentativeCount AttributeConfig `mapstructure:"representative_count"`
8088
Action AttributeConfig `mapstructure:"action"`
@@ -154,8 +162,6 @@ func Enabled() Config {
154162
},
155163
Span: ElasticSpanConfig{
156164
TimestampUs: AttributeConfig{Enabled: true},
157-
ID: AttributeConfig{Enabled: true},
158-
Name: AttributeConfig{Enabled: true},
159165
ProcessorEvent: AttributeConfig{Enabled: true},
160166
Action: AttributeConfig{Enabled: true},
161167
TypeSubtype: AttributeConfig{Enabled: true},

enrichments/config/config_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,22 @@ func TestEnabled(t *testing.T) {
3636
func assertAllEnabled(t *testing.T, cfg reflect.Value) {
3737
t.Helper()
3838

39+
// Fields that are intentionally disabled by default
40+
disabledByDefault := map[string]bool{
41+
"ClearSpanID": true,
42+
"ClearSpanName": true,
43+
}
44+
3945
for i := 0; i < cfg.NumField(); i++ {
46+
fieldName := cfg.Type().Field(i).Name
4047
rAttrCfg := cfg.Field(i).Interface()
4148
attrCfg, ok := rAttrCfg.(AttributeConfig)
4249
require.True(t, ok, "must be a type of AttributeConfig")
43-
require.True(t, attrCfg.Enabled, "must be enabled")
50+
51+
if disabledByDefault[fieldName] {
52+
require.False(t, attrCfg.Enabled, "%s must be disabled by default", fieldName)
53+
} else {
54+
require.True(t, attrCfg.Enabled, "%s must be enabled", fieldName)
55+
}
4456
}
4557
}

enrichments/internal/elastic/span.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,18 @@ func (s *spanEnrichmentContext) enrichTransaction(
264264
// https://github.com/elastic/apm-data/blob/v1.19.5/input/elasticapm/internal/modeldecoder/v2/decoder.go#L1377-L1379
265265
// https://github.com/elastic/apm-data/blob/v1.19.5/input/otlp/traces.go#L185-L194
266266
attribute.PutStr(span.Attributes(), elasticattr.SpanID, transactionID)
267+
if cfg.ClearSpanID.Enabled {
268+
span.SetSpanID(pcommon.SpanID{})
269+
}
267270
}
268271
if cfg.Root.Enabled {
269272
attribute.PutBool(span.Attributes(), elasticattr.TransactionRoot, isTraceRoot(span))
270273
}
271274
if cfg.Name.Enabled {
272275
attribute.PutStr(span.Attributes(), elasticattr.TransactionName, span.Name())
276+
if cfg.ClearSpanName.Enabled {
277+
span.SetName("")
278+
}
273279
}
274280
if cfg.ProcessorEvent.Enabled {
275281
attribute.PutStr(span.Attributes(), elasticattr.ProcessorEvent, "transaction")
@@ -315,12 +321,6 @@ func (s *spanEnrichmentContext) enrichSpan(
315321
if cfg.TimestampUs.Enabled {
316322
attribute.PutInt(span.Attributes(), elasticattr.TimestampUs, getTimestampUs(span.StartTimestamp()))
317323
}
318-
if cfg.ID.Enabled {
319-
attribute.PutStr(span.Attributes(), elasticattr.SpanID, span.SpanID().String())
320-
}
321-
if cfg.Name.Enabled {
322-
attribute.PutStr(span.Attributes(), elasticattr.SpanName, span.Name())
323-
}
324324
if cfg.RepresentativeCount.Enabled {
325325
repCount := getRepresentativeCount(span.TraceState().AsRaw())
326326
attribute.PutDouble(span.Attributes(), elasticattr.SpanRepresentativeCount, repCount)

0 commit comments

Comments
 (0)