@@ -6,15 +6,13 @@ package elasticsearchexporter // import "github.com/open-telemetry/opentelemetry
6
6
import (
7
7
"bytes"
8
8
"encoding/binary"
9
- "encoding/json"
10
9
"errors"
11
10
"fmt"
12
11
"hash"
13
12
"hash/fnv"
14
13
"math"
15
14
"slices"
16
15
"strings"
17
- "time"
18
16
19
17
jsoniter "github.com/json-iterator/go"
20
18
"go.opentelemetry.io/collector/pdata/pcommon"
@@ -26,7 +24,6 @@ import (
26
24
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/elasticsearchexporter/internal/exphistogram"
27
25
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/elasticsearchexporter/internal/mapping"
28
26
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/elasticsearchexporter/internal/objmodel"
29
- "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/traceutil"
30
27
)
31
28
32
29
// resourceAttrsConversionMap contains conversions for resource-level attributes
@@ -106,12 +103,6 @@ type dataPoint interface {
106
103
HasMappingHint (mappingHint ) bool
107
104
}
108
105
109
- const (
110
- traceIDField = "traceID"
111
- spanIDField = "spanID"
112
- attributeField = "attribute"
113
- )
114
-
115
106
func (m * encodeModel ) encodeLog (resource pcommon.Resource , resourceSchemaURL string , record plog.LogRecord , scopeLogs plog.ScopeLogs ) ([]byte , error ) {
116
107
var document objmodel.Document
117
108
switch m .mode {
@@ -122,7 +113,7 @@ func (m *encodeModel) encodeLog(resource pcommon.Resource, resourceSchemaURL str
122
113
case mapping .ModeBodyMap :
123
114
return m .encodeLogBodyMapMode (record )
124
115
default :
125
- document = mapping.DefaultEncoder {Mode : m .mode }.EncodeLog (resource , record , scopeLogs )
116
+ document = mapping.DefaultEncoder {Mode : m .mode }.EncodeLog (resource , scopeLogs , record )
126
117
}
127
118
// For OTel mode, prefix conflicts are not a problem as otel-data has subobjects: false
128
119
document .Dedup (m .mode != mapping .ModeOTel )
@@ -644,7 +635,7 @@ func (m *encodeModel) encodeSpan(resourceSpans ptrace.ResourceSpans, scopeSpans
644
635
case mapping .ModeOTel :
645
636
document = m .encodeSpanOTelMode (resourceSpans .Resource (), resourceSpans .SchemaUrl (), span , scopeSpans .Scope (), scopeSpans .SchemaUrl ())
646
637
default :
647
- document = m . encodeSpanDefaultMode ( resourceSpans . Resource (), span , scopeSpans . Scope () )
638
+ document = mapping. DefaultEncoder { Mode : m . mode }. EncodeSpan ( resourceSpans , scopeSpans , span )
648
639
}
649
640
// For OTel mode, prefix conflicts are not a problem as otel-data has subobjects: false
650
641
document .Dedup (m .mode != mapping .ModeOTel )
@@ -694,26 +685,6 @@ func (m *encodeModel) encodeSpanOTelMode(resource pcommon.Resource, resourceSche
694
685
return document
695
686
}
696
687
697
- func (m * encodeModel ) encodeSpanDefaultMode (resource pcommon.Resource , span ptrace.Span , scope pcommon.InstrumentationScope ) objmodel.Document {
698
- var document objmodel.Document
699
- document .AddTimestamp ("@timestamp" , span .StartTimestamp ()) // We use @timestamp in order to ensure that we can index if the default data stream logs template is used.
700
- document .AddTimestamp ("EndTimestamp" , span .EndTimestamp ())
701
- document .AddTraceID ("TraceId" , span .TraceID ())
702
- document .AddSpanID ("SpanId" , span .SpanID ())
703
- document .AddSpanID ("ParentSpanId" , span .ParentSpanID ())
704
- document .AddString ("Name" , span .Name ())
705
- document .AddString ("Kind" , traceutil .SpanKindStr (span .Kind ()))
706
- document .AddInt ("TraceStatus" , int64 (span .Status ().Code ()))
707
- document .AddString ("TraceStatusDescription" , span .Status ().Message ())
708
- document .AddString ("Link" , spanLinksToString (span .Links ()))
709
- m .encodeAttributes (& document , span .Attributes ())
710
- document .AddAttributes ("Resource" , resource .Attributes ())
711
- m .encodeEvents (& document , span .Events ())
712
- document .AddInt ("Duration" , durationAsMicroseconds (span .StartTimestamp ().AsTime (), span .EndTimestamp ().AsTime ())) // unit is microseconds
713
- document .AddAttributes ("Scope" , scopeToAttributes (scope ))
714
- return document
715
- }
716
-
717
688
func (m * encodeModel ) encodeSpanEvent (resource pcommon.Resource , resourceSchemaURL string , span ptrace.Span , spanEvent ptrace.SpanEvent , scope pcommon.InstrumentationScope , scopeSchemaURL string ) * objmodel.Document {
718
689
if m .mode != mapping .ModeOTel {
719
690
// Currently span events are stored separately only in OTel mapping mode.
@@ -736,52 +707,6 @@ func (m *encodeModel) encodeSpanEvent(resource pcommon.Resource, resourceSchemaU
736
707
return & document
737
708
}
738
709
739
- func (m * encodeModel ) encodeAttributes (document * objmodel.Document , attributes pcommon.Map ) {
740
- key := "Attributes"
741
- if m .mode == mapping .ModeRaw {
742
- key = ""
743
- }
744
- document .AddAttributes (key , attributes )
745
- }
746
-
747
- func (m * encodeModel ) encodeEvents (document * objmodel.Document , events ptrace.SpanEventSlice ) {
748
- key := "Events"
749
- if m .mode == mapping .ModeRaw {
750
- key = ""
751
- }
752
- document .AddEvents (key , events )
753
- }
754
-
755
- func spanLinksToString (spanLinkSlice ptrace.SpanLinkSlice ) string {
756
- linkArray := make ([]map [string ]any , 0 , spanLinkSlice .Len ())
757
- for i := 0 ; i < spanLinkSlice .Len (); i ++ {
758
- spanLink := spanLinkSlice .At (i )
759
- link := map [string ]any {}
760
- link [spanIDField ] = traceutil .SpanIDToHexOrEmptyString (spanLink .SpanID ())
761
- link [traceIDField ] = traceutil .TraceIDToHexOrEmptyString (spanLink .TraceID ())
762
- link [attributeField ] = spanLink .Attributes ().AsRaw ()
763
- linkArray = append (linkArray , link )
764
- }
765
- linkArrayBytes , _ := json .Marshal (& linkArray )
766
- return string (linkArrayBytes )
767
- }
768
-
769
- // durationAsMicroseconds calculate span duration through end - start nanoseconds and converts time.Time to microseconds,
770
- // which is the format the Duration field is stored in the Span.
771
- func durationAsMicroseconds (start , end time.Time ) int64 {
772
- return (end .UnixNano () - start .UnixNano ()) / 1000
773
- }
774
-
775
- func scopeToAttributes (scope pcommon.InstrumentationScope ) pcommon.Map {
776
- attrs := pcommon .NewMap ()
777
- attrs .PutStr ("name" , scope .Name ())
778
- attrs .PutStr ("version" , scope .Version ())
779
- for k , v := range scope .Attributes ().AsRaw () {
780
- attrs .PutStr (k , v .(string ))
781
- }
782
- return attrs
783
- }
784
-
785
710
func encodeAttributesECSMode (document * objmodel.Document , attrs pcommon.Map , conversionMap map [string ]string , preserveMap map [string ]bool ) {
786
711
if len (conversionMap ) == 0 {
787
712
// No conversions to be done; add all attributes at top level of
0 commit comments