-
Notifications
You must be signed in to change notification settings - Fork 0
/
stacktrace_processor_test.go
73 lines (65 loc) · 2.91 KB
/
stacktrace_processor_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package opentelemetry_stacktrace_processor // import "github.com/joostlek/opentelemetry-stacktrace-processor"
import (
"context"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/ptrace"
"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/processor/processortest"
"testing"
"time"
)
func TestBatchProcessorSpansDeliveredEnforceBatchSize(t *testing.T) {
sink := new(consumertest.TracesSink)
cfg := createDefaultConfig().(*Config)
cfg.SourceMapDirs = make([]string, 0)
cfg.SourceMapDirs = append(cfg.SourceMapDirs, "testdata")
creationSet := processortest.NewNopCreateSettings()
processor, err := newStackTraceProcessor(creationSet, sink, cfg)
require.NoError(t, err)
require.NoError(t, processor.Start(context.Background(), componenttest.NewNopHost()))
td := GenerateTraces()
assert.NoError(t, processor.ConsumeTraces(context.Background(), td))
for {
if sink.SpanCount() == 1 {
break
}
}
traces := sink.AllTraces()
event := traces[0].ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0).Events().At(0)
stackTrace, valid := event.Attributes().Get("exception.stacktrace")
assert.True(t, valid)
assert.Equal(t, "padStart@lib/lineSlicer.js:11:53\npadStart@http://localhost:4203/lineSlicers.min.js:1:228\n", stackTrace.Str())
require.NoError(t, processor.Shutdown(context.Background()))
}
var (
spanStartTimestamp = pcommon.NewTimestampFromTime(time.Date(2020, 2, 11, 20, 26, 12, 321, time.UTC))
spanEventTimestamp = pcommon.NewTimestampFromTime(time.Date(2020, 2, 11, 20, 26, 13, 123, time.UTC))
spanEndTimestamp = pcommon.NewTimestampFromTime(time.Date(2020, 2, 11, 20, 26, 13, 789, time.UTC))
)
func GenerateTraces() ptrace.Traces {
td := ptrace.NewTraces()
td.ResourceSpans().AppendEmpty().Resource().Attributes().PutStr("telemetry.sdk.language", "webjs")
ss := td.ResourceSpans().At(0).ScopeSpans().AppendEmpty().Spans()
ss.EnsureCapacity(1)
fillExceptionSpan(ss.AppendEmpty())
return td
}
func fillExceptionSpan(span ptrace.Span) {
span.SetName("@pi/error-handler")
span.SetStartTimestamp(spanStartTimestamp)
span.SetEndTimestamp(spanEndTimestamp)
span.SetDroppedAttributesCount(0)
span.SetTraceID([16]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10})
span.SetSpanID([8]byte{0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18})
evs := span.Events()
ev0 := evs.AppendEmpty()
ev0.SetTimestamp(spanEventTimestamp)
ev0.SetName("exception")
ev0.Attributes().PutStr("exception.type", "TypeError")
ev0.Attributes().PutStr("exception.message", "symbol.viewBox.baseVal is null")
ev0.Attributes().PutStr("exception.stacktrace", "padStart@http://localhost:4203/lineSlicer.min.js:1:228\npadStart@http://localhost:4203/lineSlicers.min.js:1:228\n")
span.Status().SetCode(2)
}