@@ -48,7 +48,7 @@ type modelWriter struct {
4848// writeTransaction encodes tx as JSON to the buffer, and then resets tx.
4949func (w * modelWriter ) writeTransaction (tx * Transaction , td * TransactionData ) {
5050 var modelTx model.Transaction
51- w . buildModelTransaction (& modelTx , tx , td )
51+ BuildModelTransaction (& modelTx , tx , td )
5252 w .json .RawString (`{"transaction":` )
5353 modelTx .MarshalFastJSON (& w .json )
5454 w .json .RawByte ('}' )
@@ -103,39 +103,6 @@ func (w *modelWriter) writeMetrics(m *Metrics) {
103103 m .reset ()
104104}
105105
106- func (w * modelWriter ) buildModelTransaction (out * model.Transaction , tx * Transaction , td * TransactionData ) {
107- out .ID = model .SpanID (tx .traceContext .Span )
108- out .TraceID = model .TraceID (tx .traceContext .Trace )
109- sampled := tx .traceContext .Options .Recorded ()
110- if ! sampled {
111- out .Sampled = & notSampled
112- }
113- if tx .traceContext .State .haveSampleRate {
114- out .SampleRate = & tx .traceContext .State .sampleRate
115- }
116-
117- out .ParentID = model .SpanID (tx .parentID )
118- out .Name = truncateString (td .Name )
119- out .Type = truncateString (td .Type )
120- out .Result = truncateString (td .Result )
121- out .Outcome = normalizeOutcome (td .Outcome )
122- out .Timestamp = model .Time (td .timestamp .UTC ())
123- out .Duration = td .Duration .Seconds () * 1000
124- out .SpanCount .Started = td .spansCreated
125- out .SpanCount .Dropped = td .spansDropped
126- out .OTel = td .Context .otel
127- for _ , sl := range td .links {
128- out .Links = append (out .Links , model.SpanLink {TraceID : model .TraceID (sl .Trace ), SpanID : model .SpanID (sl .Span )})
129- }
130- if dss := buildDroppedSpansStats (td .droppedSpansStats ); len (dss ) > 0 {
131- out .DroppedSpansStats = dss
132- }
133-
134- if sampled {
135- out .Context = td .Context .build ()
136- }
137- }
138-
139106func (w * modelWriter ) buildModelSpan (out * model.Span , span * Span , sd * SpanData ) {
140107 w .modelStacktrace = w .modelStacktrace [:0 ]
141108 out .ID = model .SpanID (span .traceContext .Span )
@@ -258,6 +225,40 @@ func (w *modelWriter) buildModelError(out *model.Error, e *ErrorData) {
258225 out .Culprit = truncateString (out .Culprit )
259226}
260227
228+ // BuildModelTransaction converts apm transaction to model transaction
229+ func BuildModelTransaction (out * model.Transaction , tx * Transaction , td * TransactionData ) {
230+ out .ID = model .SpanID (tx .traceContext .Span )
231+ out .TraceID = model .TraceID (tx .traceContext .Trace )
232+ sampled := tx .traceContext .Options .Recorded ()
233+ if ! sampled {
234+ out .Sampled = & notSampled
235+ }
236+ if tx .traceContext .State .haveSampleRate {
237+ out .SampleRate = & tx .traceContext .State .sampleRate
238+ }
239+
240+ out .ParentID = model .SpanID (tx .parentID )
241+ out .Name = truncateString (td .Name )
242+ out .Type = truncateString (td .Type )
243+ out .Result = truncateString (td .Result )
244+ out .Outcome = normalizeOutcome (td .Outcome )
245+ out .Timestamp = model .Time (td .timestamp .UTC ())
246+ out .Duration = td .Duration .Seconds () * 1000
247+ out .SpanCount .Started = td .spansCreated
248+ out .SpanCount .Dropped = td .spansDropped
249+ out .OTel = td .Context .otel
250+ for _ , sl := range td .links {
251+ out .Links = append (out .Links , model.SpanLink {TraceID : model .TraceID (sl .Trace ), SpanID : model .SpanID (sl .Span )})
252+ }
253+ if dss := buildDroppedSpansStats (td .droppedSpansStats ); len (dss ) > 0 {
254+ out .DroppedSpansStats = dss
255+ }
256+
257+ if sampled {
258+ out .Context = td .Context .build ()
259+ }
260+ }
261+
261262func stacktraceCulprit (frames []model.StacktraceFrame ) string {
262263 for _ , frame := range frames {
263264 if ! frame .LibraryFrame {
0 commit comments