Skip to content

Commit ac063cc

Browse files
committed
pass scope resource and logs to encode span event too
1 parent 90af5cb commit ac063cc

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

exporter/elasticsearchexporter/exporter.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -360,19 +360,18 @@ func (e *elasticsearchExporter) pushTraceData(
360360
scopeSpans := il.ScopeSpans()
361361
for j := 0; j < scopeSpans.Len(); j++ {
362362
scopeSpan := scopeSpans.At(j)
363-
scope := scopeSpan.Scope()
364363
spans := scopeSpan.Spans()
365364
for k := 0; k < spans.Len(); k++ {
366365
span := spans.At(k)
367-
if err := e.pushTraceRecord(ctx, resource, il.SchemaUrl(), span, scope, scopeSpan.SchemaUrl(), session); err != nil {
366+
if err := e.pushTraceRecord(ctx, il, scopeSpan, span, session); err != nil {
368367
if cerr := ctx.Err(); cerr != nil {
369368
return cerr
370369
}
371370
errs = append(errs, err)
372371
}
373372
for ii := 0; ii < span.Events().Len(); ii++ {
374373
spanEvent := span.Events().At(ii)
375-
if err := e.pushSpanEvent(ctx, resource, il.SchemaUrl(), span, spanEvent, scope, scopeSpan.SchemaUrl(), session); err != nil {
374+
if err := e.pushSpanEvent(ctx, resource, il.SchemaUrl(), span, spanEvent, scopeSpan.Scope(), scopeSpan.SchemaUrl(), session); err != nil {
376375
errs = append(errs, err)
377376
}
378377
}
@@ -391,16 +390,21 @@ func (e *elasticsearchExporter) pushTraceData(
391390

392391
func (e *elasticsearchExporter) pushTraceRecord(
393392
ctx context.Context,
394-
resource pcommon.Resource,
395-
resourceSchemaURL string,
393+
resourceSpans ptrace.ResourceSpans,
394+
scopeSpans ptrace.ScopeSpans,
396395
span ptrace.Span,
397-
scope pcommon.InstrumentationScope,
398-
scopeSchemaURL string,
399396
bulkIndexerSession bulkIndexerSession,
400397
) error {
401398
fIndex := e.index
402399
if e.dynamicIndex {
403-
fIndex = routeSpan(span.Attributes(), scope.Attributes(), resource.Attributes(), fIndex, e.otel, span.Name())
400+
fIndex = routeSpan(
401+
span.Attributes(),
402+
scopeSpans.Scope().Attributes(),
403+
resourceSpans.Resource().Attributes(),
404+
fIndex,
405+
e.otel,
406+
span.Name(),
407+
)
404408
}
405409

406410
if e.logstashFormat.Enabled {
@@ -411,7 +415,7 @@ func (e *elasticsearchExporter) pushTraceRecord(
411415
fIndex = formattedIndex
412416
}
413417

414-
document, err := e.model.encodeSpan(resource, resourceSchemaURL, span, scope, scopeSchemaURL)
418+
document, err := e.model.encodeSpan(resourceSpans, scopeSpans, span)
415419
if err != nil {
416420
return fmt.Errorf("failed to encode trace record: %w", err)
417421
}

exporter/elasticsearchexporter/model.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ var ErrInvalidTypeForBodyMapMode = errors.New("invalid log record body type for
7979

8080
type mappingModel interface {
8181
encodeLog(pcommon.Resource, string, plog.LogRecord, plog.ScopeLogs) ([]byte, error)
82-
encodeSpan(pcommon.Resource, string, ptrace.Span, pcommon.InstrumentationScope, string) ([]byte, error)
82+
encodeSpan(ptrace.ResourceSpans, ptrace.ScopeSpans, ptrace.Span) ([]byte, error)
8383
encodeSpanEvent(resource pcommon.Resource, resourceSchemaURL string, span ptrace.Span, spanEvent ptrace.SpanEvent, scope pcommon.InstrumentationScope, scopeSchemaURL string) *objmodel.Document
8484
upsertMetricDataPointValue(map[uint32]objmodel.Document, pcommon.Resource, string, pcommon.InstrumentationScope, string, pmetric.Metric, dataPoint) error
8585
encodeDocument(objmodel.Document) ([]byte, error)
@@ -638,13 +638,13 @@ func (m *encodeModel) encodeAttributesOTelMode(document *objmodel.Document, attr
638638
document.AddAttributes("attributes", attrsCopy)
639639
}
640640

641-
func (m *encodeModel) encodeSpan(resource pcommon.Resource, resourceSchemaURL string, span ptrace.Span, scope pcommon.InstrumentationScope, scopeSchemaURL string) ([]byte, error) {
641+
func (m *encodeModel) encodeSpan(resourceSpans ptrace.ResourceSpans, scopeSpans ptrace.ScopeSpans, span ptrace.Span) ([]byte, error) {
642642
var document objmodel.Document
643643
switch m.mode {
644644
case mapping.ModeOTel:
645-
document = m.encodeSpanOTelMode(resource, resourceSchemaURL, span, scope, scopeSchemaURL)
645+
document = m.encodeSpanOTelMode(resourceSpans.Resource(), resourceSpans.SchemaUrl(), span, scopeSpans.Scope(), scopeSpans.SchemaUrl())
646646
default:
647-
document = m.encodeSpanDefaultMode(resource, span, scope)
647+
document = m.encodeSpanDefaultMode(resourceSpans.Resource(), span, scopeSpans.Scope())
648648
}
649649
// For OTel mode, prefix conflicts are not a problem as otel-data has subobjects: false
650650
document.Dedup(m.mode != mapping.ModeOTel)

exporter/elasticsearchexporter/model_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ var (
5757
func TestEncodeSpan(t *testing.T) {
5858
model := &encodeModel{dedot: false}
5959
td := mockResourceSpans()
60-
spanByte, err := model.encodeSpan(td.ResourceSpans().At(0).Resource(), "", td.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0), td.ResourceSpans().At(0).ScopeSpans().At(0).Scope(), "")
60+
spanByte, err := model.encodeSpan(
61+
td.ResourceSpans().At(0),
62+
td.ResourceSpans().At(0).ScopeSpans().At(0),
63+
td.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0),
64+
)
6165
assert.NoError(t, err)
6266
assert.Equal(t, expectedSpanBody, string(spanByte))
6367
}

0 commit comments

Comments
 (0)