func SetDerivedFieldsForError()

in receiver/elasticapmreceiver/internal/mappers/intakeV2ToDerivedFields.go [95:161]


func SetDerivedFieldsForError(event *modelpb.APMEvent, attributes pcommon.Map) {
	attributes.PutStr(elasticattr.ProcessorEvent, "error")

	if event.Error == nil {
		return
	}

	if event.Error.Id != "" {
		attributes.PutStr(elasticattr.ErrorID, event.Error.Id)
	}
	if event.Transaction != nil && event.Transaction.Id != "" {
		attributes.PutStr(elasticattr.TransactionID, event.Transaction.Id)
	}
	if event.ParentId != "" {
		attributes.PutStr(elasticattr.ParentID, event.ParentId)
	}

	if event.Error.Type != "" {
		attributes.PutStr("error.type", event.Error.Type)
	}
	if event.Error.Message != "" {
		attributes.PutStr("message", event.Error.Message)
	}
	attributes.PutStr(elasticattr.ErrorGroupingKey, event.Error.GroupingKey)
	attributes.PutInt(elasticattr.TimestampUs, int64(event.Timestamp/1_000))

	if event.Error.Culprit != "" {
		attributes.PutStr("error.culprit", event.Error.Culprit)
	}

	if event.Error.Exception != nil {
		if event.Error.Exception.Type != "" {
			attributes.PutStr("exception.type", event.Error.Exception.Type)
		}
		if event.Error.Exception.Message != "" {
			attributes.PutStr("exception.message", event.Error.Exception.Message)
		}

		if event.Error.Exception.Stacktrace != nil {
			str := ""
			for _, frame := range event.Error.Exception.Stacktrace {
				f := frame.GetFunction()
				l := frame.GetLineno()
				if f != "" {
					str += fmt.Sprintf("%s:%d %s \n", frame.GetFilename(), l, f)
				} else {
					c := frame.GetClassname()
					if c != "" && l != 0 {
						str += fmt.Sprintf("%s:%d \n", c, l)
					}
				}
			}

			attributes.PutStr("exception.stacktrace", str)
		}

		if event.Error.Exception.Module != "" {
			attributes.PutStr("error.exception.module", event.Error.Exception.Module)
		}
		if event.Error.Exception.Handled != nil {
			attributes.PutBool("error.exception.handled", *event.Error.Exception.Handled)
		}
		if event.Error.Exception.Code != "" {
			attributes.PutStr("error.exception.code", event.Error.Exception.Code)
		}
	}
}