Skip to content

Commit a1affa2

Browse files
authored
[exporter/elasticsearchexporter] synchronize mapping with expected Elasticsearch fields (#44234)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Add missing fields to struct so that they are populated in the respective elasticsearch index. <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes <!--Describe what testing was performed and which tests were added.--> #### Testing <!--Describe the documentation added.--> #### Documentation <!--Please delete paragraphs that you did not use before submitting.--> --------- Signed-off-by: Florian Lehner <[email protected]>
1 parent 00eeae4 commit a1affa2

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: 'enhancement'
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. receiver/filelog)
7+
component: exporter/elasticsearch
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: add missing fields to struct so that they are populated in the respective elasticsearch index
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [44234]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

exporter/elasticsearchexporter/internal/serializer/otelserializer/profile_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ func TestSerializeProfile(t *testing.T) {
139139
"host.id": "localhost",
140140
"process.executable.name": "libc.so.6",
141141
"process.thread.name": "",
142+
"profiling.project.id": json.Number("2"),
142143
},
143144
{
144145
"script": map[string]any{

exporter/elasticsearchexporter/internal/serializer/otelserializer/serializeprofiles/model.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ type StackTraceEvent struct {
5656
ServiceName string `json:"service.name,omitempty"`
5757
Frequency int64 `json:"Stacktrace.sampling_frequency"`
5858
Count uint16 `json:"Stacktrace.count"`
59+
ProjectID uint32 `json:"profiling.project.id,omitempty"`
60+
HostName string `json:"host.name,omitempty"`
5961
}
6062

6163
// StackTrace represents a stacktrace serializable into the stacktraces index.

exporter/elasticsearchexporter/internal/serializer/otelserializer/serializeprofiles/transform.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ func stackTraceEvent(dic pprofile.ProfilesDictionary, traceID string, sample ppr
226226
K8sNamespaceName: hostMetadata[string(semconv.K8SNamespaceNameKey)],
227227
Count: 1, // Elasticsearch v9.2+ doesn't read the count value any more.
228228
Frequency: frequency,
229+
HostName: hostMetadata[string(semconv.HostNameKey)],
230+
ProjectID: 2, // Use a project ID other than 1 to not conflict with ECH default value.
231+
ServiceName: hostMetadata[string(semconv.ServiceNameKey)],
229232
}
230233

231234
// Store event-specific attributes.

exporter/elasticsearchexporter/internal/serializer/otelserializer/serializeprofiles/transform_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/stretchr/testify/require"
1616
"go.opentelemetry.io/collector/pdata/pprofile"
1717
"go.opentelemetry.io/ebpf-profiler/libpf"
18-
semconv "go.opentelemetry.io/otel/semconv/v1.22.0"
18+
semconv "go.opentelemetry.io/otel/semconv/v1.36.0"
1919
)
2020

2121
var (
@@ -199,6 +199,7 @@ func TestTransform(t *testing.T) {
199199
},
200200
buildResourceProfiles: func() pprofile.ResourceProfiles {
201201
rp := pprofile.NewResourceProfiles()
202+
rp.Resource().Attributes().PutStr(string(semconv.ServiceNameKey), "my_service.name")
202203

203204
sp := rp.ScopeProfiles().AppendEmpty()
204205
p := sp.Profiles().AppendEmpty()
@@ -273,8 +274,10 @@ func TestTransform(t *testing.T) {
273274
EcsVersion: EcsVersion{V: EcsVersionString},
274275
TimeStamp: 42000000000,
275276
StackTraceID: wantedTraceID,
277+
ServiceName: "my_service.name",
276278
Frequency: 20,
277279
Count: 1,
280+
ProjectID: 2,
278281
},
279282
HostMetadata: HostResourceData{},
280283
},
@@ -424,6 +427,7 @@ func TestStackPayloads(t *testing.T) {
424427
StackTraceID: wantedTraceID,
425428
Frequency: 20,
426429
Count: 1,
430+
ProjectID: 2,
427431
},
428432
HostMetadata: HostResourceData{},
429433
},
@@ -538,6 +542,7 @@ func TestStackPayloads(t *testing.T) {
538542
StackTraceID: wantedTraceID,
539543
Frequency: 20,
540544
Count: 1,
545+
ProjectID: 2,
541546
},
542547
},
543548
{
@@ -547,6 +552,7 @@ func TestStackPayloads(t *testing.T) {
547552
StackTraceID: wantedTraceID,
548553
Frequency: 20,
549554
Count: 1,
555+
ProjectID: 2,
550556
},
551557
},
552558
},
@@ -665,6 +671,7 @@ func TestStackPayloads(t *testing.T) {
665671
StackTraceID: wantedTraceID,
666672
Frequency: 20,
667673
Count: 1,
674+
ProjectID: 2,
668675
},
669676
},
670677
},
@@ -721,6 +728,7 @@ func TestStackTraceEvent(t *testing.T) {
721728
StackTraceID: stacktraceIDBase64,
722729
Frequency: 20,
723730
Count: 1,
731+
ProjectID: 2,
724732
},
725733
},
726734
{
@@ -748,6 +756,7 @@ func TestStackTraceEvent(t *testing.T) {
748756
StackTraceID: stacktraceIDBase64,
749757
Frequency: 20,
750758
Count: 1,
759+
ProjectID: 2,
751760
},
752761
},
753762
{
@@ -773,6 +782,7 @@ func TestStackTraceEvent(t *testing.T) {
773782
StackTraceID: stacktraceIDBase64,
774783
Frequency: 20,
775784
Count: 1,
785+
ProjectID: 2,
776786
},
777787
},
778788
{
@@ -800,6 +810,7 @@ func TestStackTraceEvent(t *testing.T) {
800810
string(semconv.ContainerNameKey): "my_container",
801811
string(semconv.ContainerIDKey): "my_container_id",
802812
string(semconv.K8SNamespaceNameKey): "my_k8s_namespace_name",
813+
string(semconv.HostNameKey): "my_host_name",
803814
})
804815
sp := rp.ScopeProfiles().AppendEmpty()
805816
p := sp.Profiles().AppendEmpty()
@@ -818,9 +829,11 @@ func TestStackTraceEvent(t *testing.T) {
818829
ContainerID: "my_container_id",
819830
ThreadName: "my_thread",
820831
ServiceName: "my_service",
832+
HostName: "my_host_name",
821833
StackTraceID: stacktraceIDBase64,
822834
Frequency: 20,
823835
Count: 1,
836+
ProjectID: 2,
824837
},
825838
},
826839
} {

0 commit comments

Comments
 (0)