in input/elasticapm/internal/modeldecoder/rumv3/decoder.go [498:658]
func mapToSpanModel(from *span, event *modelpb.APMEvent) {
out := modelpb.Span{}
out.Type = "unknown"
event.Span = &out
// map span specific data
if !from.Action.IsSet() && !from.Subtype.IsSet() {
sep := "."
before, after, ok := strings.Cut(from.Type.Val, sep)
if before != "" {
out.Type = before
}
if ok {
out.Subtype, out.Action, _ = strings.Cut(after, sep)
}
} else {
if from.Action.IsSet() {
out.Action = from.Action.Val
}
if from.Subtype.IsSet() {
out.Subtype = from.Subtype.Val
}
if from.Type.IsSet() {
out.Type = from.Type.Val
}
}
if from.Context.Destination.Address.IsSet() || from.Context.Destination.Port.IsSet() {
if from.Context.Destination.Address.IsSet() {
if event.Destination == nil {
event.Destination = &modelpb.Destination{}
}
event.Destination.Address = from.Context.Destination.Address.Val
}
if from.Context.Destination.Port.IsSet() {
if event.Destination == nil {
event.Destination = &modelpb.Destination{}
}
event.Destination.Port = uint32(from.Context.Destination.Port.Val)
}
}
if from.Context.Destination.Service.IsSet() {
service := modelpb.DestinationService{}
if from.Context.Destination.Service.Name.IsSet() {
service.Name = from.Context.Destination.Service.Name.Val
}
if from.Context.Destination.Service.Resource.IsSet() {
service.Resource = from.Context.Destination.Service.Resource.Val
}
if from.Context.Destination.Service.Type.IsSet() {
service.Type = from.Context.Destination.Service.Type.Val
}
out.DestinationService = &service
}
if from.Context.HTTP.IsSet() {
var response *modelpb.HTTPResponse
if from.Context.HTTP.Method.IsSet() {
if event.Http == nil {
event.Http = &modelpb.HTTP{}
}
event.Http.Request = &modelpb.HTTPRequest{}
event.Http.Request.Method = from.Context.HTTP.Method.Val
}
if from.Context.HTTP.StatusCode.IsSet() {
if event.Http == nil {
event.Http = &modelpb.HTTP{}
}
if response == nil {
response = &modelpb.HTTPResponse{}
}
event.Http.Response = response
event.Http.Response.StatusCode = uint32(from.Context.HTTP.StatusCode.Val)
}
if from.Context.HTTP.URL.IsSet() {
if event.Url == nil {
event.Url = &modelpb.URL{}
}
event.Url.Original = from.Context.HTTP.URL.Val
}
if from.Context.HTTP.Response.IsSet() {
if event.Http == nil {
event.Http = &modelpb.HTTP{}
}
if response == nil {
response = &modelpb.HTTPResponse{}
}
event.Http.Response = response
if from.Context.HTTP.Response.DecodedBodySize.IsSet() {
val := uint64(from.Context.HTTP.Response.DecodedBodySize.Val)
event.Http.Response.DecodedBodySize = &val
}
if from.Context.HTTP.Response.EncodedBodySize.IsSet() {
val := uint64(from.Context.HTTP.Response.EncodedBodySize.Val)
event.Http.Response.EncodedBodySize = &val
}
if from.Context.HTTP.Response.TransferSize.IsSet() {
val := uint64(from.Context.HTTP.Response.TransferSize.Val)
event.Http.Response.TransferSize = &val
}
}
}
if from.Context.Service.IsSet() {
if from.Context.Service.Name.IsSet() {
if event.Service == nil {
event.Service = &modelpb.Service{}
}
event.Service.Name = from.Context.Service.Name.Val
}
}
if len(from.Context.Tags) > 0 {
modeldecoderutil.MergeLabels(from.Context.Tags, event)
}
if from.Duration.IsSet() {
if event.Event == nil {
event.Event = &modelpb.Event{}
}
event.Event.Duration = uint64(from.Duration.Val * float64(time.Millisecond))
}
if from.ID.IsSet() {
out.Id = from.ID.Val
}
if from.Name.IsSet() {
out.Name = from.Name.Val
}
if event.Event == nil {
event.Event = &modelpb.Event{}
}
if from.Outcome.IsSet() {
event.Event.Outcome = from.Outcome.Val
} else {
if from.Context.HTTP.StatusCode.IsSet() {
statusCode := from.Context.HTTP.StatusCode.Val
if statusCode >= http.StatusBadRequest {
event.Event.Outcome = "failure"
} else {
event.Event.Outcome = "success"
}
} else {
event.Event.Outcome = "unknown"
}
}
if from.SampleRate.IsSet() && from.SampleRate.Val > 0 {
out.RepresentativeCount = 1 / from.SampleRate.Val
}
if len(from.Stacktrace) > 0 {
out.Stacktrace = modeldecoderutil.ResliceAndPopulateNil(
out.Stacktrace,
len(from.Stacktrace),
modeldecoderutil.NewType[modelpb.StacktraceFrame],
)
mapToStacktraceModel(from.Stacktrace, out.Stacktrace)
}
if from.Sync.IsSet() {
val := from.Sync.Val
out.Sync = &val
}
if from.Start.IsSet() {
// event.Timestamp is initialized to the time the payload was
// received; offset that by "start" milliseconds for RUM.
event.Timestamp += uint64(time.Duration(float64(time.Millisecond) * from.Start.Val).Nanoseconds())
}
}