Skip to content

Commit c434532

Browse files
authored
Create common package for reusing elastic specific attributes (#141)
* Add common module for reuse * Move attributes to common * rename common to elasticattributes * Rename folder to elasticattr * rename module * Remove `replace` from go.mod * Remove module * Update resource.go
1 parent 03dfd1f commit c434532

File tree

8 files changed

+482
-476
lines changed

8 files changed

+482
-476
lines changed

elasticattr/attributes.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Licensed to Elasticsearch B.V. under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Elasticsearch B.V. licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package elasticattr
19+
20+
const (
21+
// resource s
22+
AgentName = "agent.name"
23+
AgentVersion = "agent.version"
24+
25+
// scope s
26+
ServiceFrameworkName = "service.framework.name"
27+
ServiceFrameworkVersion = "service.framework.version"
28+
29+
// span s
30+
TimestampUs = "timestamp.us"
31+
ProcessorEvent = "processor.event"
32+
TransactionSampled = "transaction.sampled"
33+
TransactionID = "transaction.id"
34+
TransactionRoot = "transaction.root"
35+
TransactionName = "transaction.name"
36+
TransactionType = "transaction.type"
37+
TransactionDurationUs = "transaction.duration.us"
38+
TransactionResult = "transaction.result"
39+
TransactionRepresentativeCount = "transaction.representative_count"
40+
SpanName = "span.name"
41+
SpanType = "span.type"
42+
SpanSubtype = "span.subtype"
43+
EventOutcome = "event.outcome"
44+
SuccessCount = "event.success_count"
45+
ServiceTargetType = "service.target.type"
46+
ServiceTargetName = "service.target.name"
47+
SpanDestinationServiceResource = "span.destination.service.resource"
48+
SpanDurationUs = "span.duration.us"
49+
SpanRepresentativeCount = "span.representative_count"
50+
ChildIDs = "child.id"
51+
52+
// span event s
53+
ParentID = "parent.id"
54+
ErrorID = "error.id"
55+
ErrorExceptionHandled = "error.exception.handled"
56+
ErrorGroupingKey = "error.grouping_key"
57+
ErrorGroupingName = "error.grouping_name"
58+
)

enrichments/trace/internal/elastic/attributes.go

Lines changed: 0 additions & 58 deletions
This file was deleted.

enrichments/trace/internal/elastic/resource.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package elastic
2020
import (
2121
"fmt"
2222

23+
"github.com/elastic/opentelemetry-lib/elasticattr"
2324
"github.com/elastic/opentelemetry-lib/enrichments/trace/config"
2425
"go.opentelemetry.io/collector/pdata/pcommon"
2526
semconv "go.opentelemetry.io/collector/semconv/v1.25.0"
@@ -98,7 +99,7 @@ func (s *resourceEnrichmentContext) setAgentName(resource pcommon.Resource) {
9899
s.telemetrySDKLanguage,
99100
)
100101
}
101-
resource.Attributes().PutStr(AttributeAgentName, agentName)
102+
resource.Attributes().PutStr(elasticattr.AgentName, agentName)
102103
}
103104

104105
func (s *resourceEnrichmentContext) setAgentVersion(resource pcommon.Resource) {
@@ -113,7 +114,7 @@ func (s *resourceEnrichmentContext) setAgentVersion(resource pcommon.Resource) {
113114
case s.telemetrySDKVersion != "":
114115
agentVersion = s.telemetrySDKVersion
115116
}
116-
resource.Attributes().PutStr(AttributeAgentVersion, agentVersion)
117+
resource.Attributes().PutStr(elasticattr.AgentVersion, agentVersion)
117118
}
118119

119120
func (s *resourceEnrichmentContext) overrideHostNameWithK8sNodeName(resource pcommon.Resource) {

enrichments/trace/internal/elastic/resource_test.go

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package elastic
2020
import (
2121
"testing"
2222

23+
"github.com/elastic/opentelemetry-lib/elasticattr"
2324
"github.com/elastic/opentelemetry-lib/enrichments/trace/config"
2425
"github.com/google/go-cmp/cmp"
2526
"github.com/stretchr/testify/assert"
@@ -44,8 +45,8 @@ func TestResourceEnrich(t *testing.T) {
4445
input: pcommon.NewResource(),
4546
config: config.Enabled().Resource,
4647
enrichedAttrs: map[string]any{
47-
AttributeAgentName: "otlp",
48-
AttributeAgentVersion: "unknown",
48+
elasticattr.AgentName: "otlp",
49+
elasticattr.AgentVersion: "unknown",
4950
},
5051
},
5152
{
@@ -57,8 +58,8 @@ func TestResourceEnrich(t *testing.T) {
5758
}(),
5859
config: config.Enabled().Resource,
5960
enrichedAttrs: map[string]any{
60-
AttributeAgentName: "customflavor",
61-
AttributeAgentVersion: "unknown",
61+
elasticattr.AgentName: "customflavor",
62+
elasticattr.AgentVersion: "unknown",
6263
},
6364
},
6465
{
@@ -71,8 +72,8 @@ func TestResourceEnrich(t *testing.T) {
7172
}(),
7273
config: config.Enabled().Resource,
7374
enrichedAttrs: map[string]any{
74-
AttributeAgentName: "customflavor/unknown/elastic",
75-
AttributeAgentVersion: "unknown",
75+
elasticattr.AgentName: "customflavor/unknown/elastic",
76+
elasticattr.AgentVersion: "unknown",
7677
},
7778
},
7879
{
@@ -86,8 +87,8 @@ func TestResourceEnrich(t *testing.T) {
8687
}(),
8788
config: config.Enabled().Resource,
8889
enrichedAttrs: map[string]any{
89-
AttributeAgentName: "customflavor/cpp/elastic",
90-
AttributeAgentVersion: "unknown",
90+
elasticattr.AgentName: "customflavor/cpp/elastic",
91+
elasticattr.AgentVersion: "unknown",
9192
},
9293
},
9394
{
@@ -99,8 +100,8 @@ func TestResourceEnrich(t *testing.T) {
99100
}(),
100101
config: config.Enabled().Resource,
101102
enrichedAttrs: map[string]any{
102-
AttributeAgentName: "otlp/cpp",
103-
AttributeAgentVersion: "unknown",
103+
elasticattr.AgentName: "otlp/cpp",
104+
elasticattr.AgentVersion: "unknown",
104105
},
105106
},
106107
{
@@ -113,8 +114,8 @@ func TestResourceEnrich(t *testing.T) {
113114
}(),
114115
config: config.Enabled().Resource,
115116
enrichedAttrs: map[string]any{
116-
AttributeAgentName: "customflavor/cpp",
117-
AttributeAgentVersion: "unknown",
117+
elasticattr.AgentName: "customflavor/cpp",
118+
elasticattr.AgentVersion: "unknown",
118119
},
119120
},
120121
{
@@ -127,8 +128,8 @@ func TestResourceEnrich(t *testing.T) {
127128
}(),
128129
config: config.Enabled().Resource,
129130
enrichedAttrs: map[string]any{
130-
AttributeAgentName: "customflavor",
131-
AttributeAgentVersion: "9.999.9",
131+
elasticattr.AgentName: "customflavor",
132+
elasticattr.AgentVersion: "9.999.9",
132133
},
133134
},
134135
{
@@ -142,8 +143,8 @@ func TestResourceEnrich(t *testing.T) {
142143
}(),
143144
config: config.Enabled().Resource,
144145
enrichedAttrs: map[string]any{
145-
AttributeAgentName: "customflavor/unknown/elastic",
146-
AttributeAgentVersion: "unknown",
146+
elasticattr.AgentName: "customflavor/unknown/elastic",
147+
elasticattr.AgentVersion: "unknown",
147148
},
148149
},
149150
{
@@ -158,8 +159,8 @@ func TestResourceEnrich(t *testing.T) {
158159
}(),
159160
config: config.Enabled().Resource,
160161
enrichedAttrs: map[string]any{
161-
AttributeAgentName: "customflavor/unknown/elastic",
162-
AttributeAgentVersion: "1.2.3",
162+
elasticattr.AgentName: "customflavor/unknown/elastic",
163+
elasticattr.AgentVersion: "1.2.3",
163164
},
164165
},
165166
{
@@ -174,8 +175,8 @@ func TestResourceEnrich(t *testing.T) {
174175
enrichedAttrs: map[string]any{
175176
semconv.AttributeHostName: "k8s-node",
176177
semconv.AttributeK8SNodeName: "k8s-node",
177-
AttributeAgentName: "otlp",
178-
AttributeAgentVersion: "unknown",
178+
elasticattr.AgentName: "otlp",
179+
elasticattr.AgentVersion: "unknown",
179180
},
180181
},
181182
{
@@ -189,8 +190,8 @@ func TestResourceEnrich(t *testing.T) {
189190
enrichedAttrs: map[string]any{
190191
semconv.AttributeHostName: "k8s-node",
191192
semconv.AttributeK8SNodeName: "k8s-node",
192-
AttributeAgentName: "otlp",
193-
AttributeAgentVersion: "unknown",
193+
elasticattr.AgentName: "otlp",
194+
elasticattr.AgentVersion: "unknown",
194195
},
195196
},
196197
} {

enrichments/trace/internal/elastic/scope.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package elastic
1919

2020
import (
21+
"github.com/elastic/opentelemetry-lib/elasticattr"
2122
"github.com/elastic/opentelemetry-lib/enrichments/trace/config"
2223
"go.opentelemetry.io/collector/pdata/pcommon"
2324
)
@@ -27,8 +28,8 @@ func EnrichScope(scope pcommon.InstrumentationScope, cfg config.Config) {
2728
attrs := scope.Attributes()
2829
if cfg.Scope.ServiceFrameworkName.Enabled {
2930
if name := scope.Name(); name != "" {
30-
attrs.PutStr(AttributeServiceFrameworkName, name)
31-
attrs.PutStr(AttributeServiceFrameworkVersion, scope.Version())
31+
attrs.PutStr(elasticattr.ServiceFrameworkName, name)
32+
attrs.PutStr(elasticattr.ServiceFrameworkVersion, scope.Version())
3233
}
3334
}
3435
}

enrichments/trace/internal/elastic/scope_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package elastic
2020
import (
2121
"testing"
2222

23+
"github.com/elastic/opentelemetry-lib/elasticattr"
2324
"github.com/elastic/opentelemetry-lib/enrichments/trace/config"
2425
"github.com/google/go-cmp/cmp"
2526
"github.com/stretchr/testify/assert"
@@ -47,8 +48,8 @@ func TestScopeEnrich(t *testing.T) {
4748
}(),
4849
config: config.Enabled().Scope,
4950
enrichedAttrs: map[string]any{
50-
AttributeServiceFrameworkName: "test",
51-
AttributeServiceFrameworkVersion: "",
51+
elasticattr.ServiceFrameworkName: "test",
52+
elasticattr.ServiceFrameworkVersion: "",
5253
},
5354
},
5455
{
@@ -61,8 +62,8 @@ func TestScopeEnrich(t *testing.T) {
6162
}(),
6263
config: config.Enabled().Scope,
6364
enrichedAttrs: map[string]any{
64-
AttributeServiceFrameworkName: "test",
65-
AttributeServiceFrameworkVersion: "v1.0.0",
65+
elasticattr.ServiceFrameworkName: "test",
66+
elasticattr.ServiceFrameworkVersion: "v1.0.0",
6667
},
6768
},
6869
} {

0 commit comments

Comments
 (0)