Skip to content

Commit 15e2b6b

Browse files
authored
Merge branch 'main' into dependabot/go_modules/tools/dependencies-f3a1f89f55
2 parents e597653 + 77d76ae commit 15e2b6b

File tree

8 files changed

+565
-95
lines changed

8 files changed

+565
-95
lines changed

enrichments/trace/config/config.go

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ type Config struct {
2828

2929
// ResourceConfig configures the enrichment of resource attributes.
3030
type ResourceConfig struct {
31-
AgentName AttributeConfig `mapstructure:"agent_name"`
32-
AgentVersion AttributeConfig `mapstructure:"agent_version"`
31+
AgentName AttributeConfig `mapstructure:"agent_name"`
32+
AgentVersion AttributeConfig `mapstructure:"agent_version"`
33+
OverrideHostName AttributeConfig `mapstructure:"override_host_name"`
3334
}
3435

3536
// ScopeConfig configures the enrichment of scope attributes.
@@ -55,6 +56,7 @@ type ElasticTransactionConfig struct {
5556
Type AttributeConfig `mapstructure:"type"`
5657
Result AttributeConfig `mapstructure:"result"`
5758
EventOutcome AttributeConfig `mapstructure:"event_outcome"`
59+
InferredSpans AttributeConfig `mapstructure:"inferred_spans"`
5860
}
5961

6062
// ElasticSpanConfig configures the enrichment attributes for the spans
@@ -72,15 +74,24 @@ type ElasticSpanConfig struct {
7274
EventOutcome AttributeConfig `mapstructure:"event_outcome"`
7375
ServiceTarget AttributeConfig `mapstructure:"service_target"`
7476
DestinationService AttributeConfig `mapstructure:"destination_service"`
77+
InferredSpans AttributeConfig `mapstructure:"inferred_spans"`
7578
}
7679

7780
// SpanEventConfig configures enrichment attributes for the span events.
7881
type SpanEventConfig struct {
7982
// TimestampUs is a temporary attribute to enable higher
8083
// resolution timestamps in Elasticsearch. For more details see:
8184
// https://github.com/elastic/opentelemetry-dev/issues/374.
82-
TimestampUs AttributeConfig `mapstructure:"timestamp_us"`
83-
ProcessorEvent AttributeConfig `mapstructure:"processor_event"`
85+
TimestampUs AttributeConfig `mapstructure:"timestamp_us"`
86+
TransactionSampled AttributeConfig `mapstructure:"transaction_sampled"`
87+
TransactionType AttributeConfig `mapstructure:"transaction_type"`
88+
ProcessorEvent AttributeConfig `mapstructure:"processor_event"`
89+
90+
// For exceptions/errors
91+
ErrorID AttributeConfig `mapstructure:"error_id"`
92+
ErrorExceptionHandled AttributeConfig `mapstructure:"error_exception_handled"`
93+
ErrorGroupingKey AttributeConfig `mapstructure:"error_grouping_key"`
94+
ErrorGroupingName AttributeConfig `mapstructure:"error_grouping_name"`
8495
}
8596

8697
// AttributeConfig is the configuration options for each attribute.
@@ -92,8 +103,9 @@ type AttributeConfig struct {
92103
func Enabled() Config {
93104
return Config{
94105
Resource: ResourceConfig{
95-
AgentName: AttributeConfig{Enabled: true},
96-
AgentVersion: AttributeConfig{Enabled: true},
106+
AgentName: AttributeConfig{Enabled: true},
107+
AgentVersion: AttributeConfig{Enabled: true},
108+
OverrideHostName: AttributeConfig{Enabled: true},
97109
},
98110
Scope: ScopeConfig{
99111
ServiceFrameworkName: AttributeConfig{Enabled: true},
@@ -111,6 +123,7 @@ func Enabled() Config {
111123
Result: AttributeConfig{Enabled: true},
112124
EventOutcome: AttributeConfig{Enabled: true},
113125
RepresentativeCount: AttributeConfig{Enabled: true},
126+
InferredSpans: AttributeConfig{Enabled: true},
114127
},
115128
Span: ElasticSpanConfig{
116129
TimestampUs: AttributeConfig{Enabled: true},
@@ -122,10 +135,17 @@ func Enabled() Config {
122135
ServiceTarget: AttributeConfig{Enabled: true},
123136
DestinationService: AttributeConfig{Enabled: true},
124137
RepresentativeCount: AttributeConfig{Enabled: true},
138+
InferredSpans: AttributeConfig{Enabled: true},
125139
},
126140
SpanEvent: SpanEventConfig{
127-
TimestampUs: AttributeConfig{Enabled: true},
128-
ProcessorEvent: AttributeConfig{Enabled: true},
141+
TimestampUs: AttributeConfig{Enabled: true},
142+
TransactionSampled: AttributeConfig{Enabled: true},
143+
TransactionType: AttributeConfig{Enabled: true},
144+
ProcessorEvent: AttributeConfig{Enabled: true},
145+
ErrorID: AttributeConfig{Enabled: true},
146+
ErrorExceptionHandled: AttributeConfig{Enabled: true},
147+
ErrorGroupingKey: AttributeConfig{Enabled: true},
148+
ErrorGroupingName: AttributeConfig{Enabled: true},
129149
},
130150
}
131151
}

enrichments/trace/internal/elastic/attributes.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,12 @@ const (
4747
AttributeSpanDestinationServiceResource = "span.destination.service.resource"
4848
AttributeSpanDurationUs = "span.duration.us"
4949
AttributeSpanRepresentativeCount = "span.representative_count"
50+
AttributeChildIDs = "child.id"
51+
52+
// span event attributes
53+
AttributeParentID = "parent.id"
54+
AttributeErrorID = "error.id"
55+
AttributeErrorExceptionHandled = "error.exception.handled"
56+
AttributeErrorGroupingKey = "error.grouping_key"
57+
AttributeErrorGroupingName = "error.grouping_name"
5058
)

enrichments/trace/internal/elastic/resource.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
"github.com/elastic/opentelemetry-lib/enrichments/trace/config"
2424
"go.opentelemetry.io/collector/pdata/pcommon"
25-
semconv "go.opentelemetry.io/collector/semconv/v1.22.0"
25+
semconv "go.opentelemetry.io/collector/semconv/v1.25.0"
2626
)
2727

2828
// EnrichResource derives and adds Elastic specific resource attributes.
@@ -32,6 +32,9 @@ func EnrichResource(resource pcommon.Resource, cfg config.Config) {
3232
}
3333

3434
type resourceEnrichmentContext struct {
35+
hostName string
36+
k8sNodeName string
37+
3538
telemetrySDKName string
3639
telemetrySDKLanguage string
3740
telemetrySDKVersion string
@@ -42,6 +45,10 @@ type resourceEnrichmentContext struct {
4245
func (s *resourceEnrichmentContext) Enrich(resource pcommon.Resource, cfg config.ResourceConfig) {
4346
resource.Attributes().Range(func(k string, v pcommon.Value) bool {
4447
switch k {
48+
case semconv.AttributeHostName:
49+
s.hostName = v.Str()
50+
case semconv.AttributeK8SNodeName:
51+
s.k8sNodeName = v.Str()
4552
case semconv.AttributeTelemetrySDKName:
4653
s.telemetrySDKName = v.Str()
4754
case semconv.AttributeTelemetrySDKLanguage:
@@ -62,6 +69,9 @@ func (s *resourceEnrichmentContext) Enrich(resource pcommon.Resource, cfg config
6269
if cfg.AgentVersion.Enabled {
6370
s.setAgentVersion(resource)
6471
}
72+
if cfg.OverrideHostName.Enabled {
73+
s.overrideHostNameWithK8sNodeName(resource)
74+
}
6575
}
6676

6777
func (s *resourceEnrichmentContext) setAgentName(resource pcommon.Resource) {
@@ -105,3 +115,14 @@ func (s *resourceEnrichmentContext) setAgentVersion(resource pcommon.Resource) {
105115
}
106116
resource.Attributes().PutStr(AttributeAgentVersion, agentVersion)
107117
}
118+
119+
func (s *resourceEnrichmentContext) overrideHostNameWithK8sNodeName(resource pcommon.Resource) {
120+
if s.k8sNodeName == "" {
121+
return
122+
}
123+
// Host name is set same as k8s node name. In case, both host name
124+
// and k8s node name are set then host name is overridden as this is
125+
// considered an invalid configuration/smell and k8s node name is
126+
// given higher preference.
127+
resource.Attributes().PutStr(semconv.AttributeHostName, s.k8sNodeName)
128+
}

enrichments/trace/internal/elastic/resource_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,37 @@ func TestResourceEnrich(t *testing.T) {
162162
AttributeAgentVersion: "1.2.3",
163163
},
164164
},
165+
{
166+
name: "host_name_override_with_k8s_node_name",
167+
input: func() pcommon.Resource {
168+
res := pcommon.NewResource()
169+
res.Attributes().PutStr(semconv.AttributeHostName, "test-host")
170+
res.Attributes().PutStr(semconv.AttributeK8SNodeName, "k8s-node")
171+
return res
172+
}(),
173+
config: config.Enabled().Resource,
174+
enrichedAttrs: map[string]any{
175+
semconv.AttributeHostName: "k8s-node",
176+
semconv.AttributeK8SNodeName: "k8s-node",
177+
AttributeAgentName: "otlp",
178+
AttributeAgentVersion: "unknown",
179+
},
180+
},
181+
{
182+
name: "host_name_if_empty_set_from_k8s_node_name",
183+
input: func() pcommon.Resource {
184+
res := pcommon.NewResource()
185+
res.Attributes().PutStr(semconv.AttributeK8SNodeName, "k8s-node")
186+
return res
187+
}(),
188+
config: config.Enabled().Resource,
189+
enrichedAttrs: map[string]any{
190+
semconv.AttributeHostName: "k8s-node",
191+
semconv.AttributeK8SNodeName: "k8s-node",
192+
AttributeAgentName: "otlp",
193+
AttributeAgentVersion: "unknown",
194+
},
195+
},
165196
} {
166197
t.Run(tc.name, func(t *testing.T) {
167198
// Merge existing resource attrs with the attrs added

0 commit comments

Comments
 (0)